Results 1 to 1 of 1

Threaded View

  1. #1
    Join Date
    Dec 2012
    Posts
    2
    Plugin Contributions
    0

    Default User input product dimensions, update price based on inputs now Working!

    Hello!

    This will be my first and probably the only contribution I will do on this forum, since my job doesn't allow me to distribute code\solutions provided by us, and since this is just a Patch, I will share it with you:

    Zahid Hussain shared the code that worked:
    "you want to edit this file: includes/classes/shopping_cart.php"

    Find the following code (should be around line 1243):
    PHP Code:
            $products_array[] = array('id' => $products_id
                                      
    'category' => $products->fields['master_categories_id'], 
                                      
    'name' => $products->fields['products_name'], 
                                      
    'model' => $products->fields['products_model'], 
                                      
    'image' => $products->fields['products_image'], 
                                      
    'price' => ($products->fields['product_is_free'] =='1' $products_price), 
            
    //                                    'quantity' => $this->contents[$products_id]['qty'], 
                                      
    'quantity' => $new_qty
                                      
    'weight' => $products->fields['products_weight'] + $this->attributes_weight($products_id), 
                                      
    // fix here 
                                      
    'final_price' => ($products_price $this->attributes_price($products_id)), 
                                      
    'onetime_charges' => ($this->attributes_price_onetime_charges($products_id$new_qty)), 
                                      
    'tax_class_id' => $products->fields['products_tax_class_id'], 
                                      
    'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''), 
                                      
    'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''), 
                                      
    'products_priced_by_attribute' => $products->fields['products_priced_by_attribute'], 
                                      
    'product_is_free' => $products->fields['product_is_free'], 
                                      
    'products_discount_type' => $products->fields['products_discount_type'], 
                                      
    'products_discount_type_from' => $products->fields['products_discount_type_from']); 
          } 
        } 
        
    $this->notify('NOTIFIER_CART_GET_PRODUCTS_END'); 
        return 
    $products_array
      } 
    And REPLACE with this:
    PHP Code:
            //begin Attribute Calculator 1.0 
            //Zen Cart contribution by JT Website Design http://www.jtwebsitedesign.com     
            
    $description_sql 'SELECT products_name FROM ' TABLE_PRODUCTS_DESCRIPTION ' where products_id = "' . (int) $products_id '"'

            
    $pdescription $db->Execute($description_sql); 
            
    $products_name $pdescription->fields['products_name']; 

            switch(
    $products->fields['products_name']) 
                { 
                  case 
    'Product A'
                  
    $priceFactor 1.00
                  break; 
                  case 
    'Product B'
                  
    $priceFactor 0.50
                  break; 
                  case 
    'Product C'
                  
    $priceFactor 1.25
                  break; 
                  default: 
                
    $priceFactor 0;         
                } 
            if(
    $priceFactor != 0
                { 
                
    $Length_ID_Query "select products_options_id from " TABLE_PRODUCTS_OPTIONS " where products_options_name = 'Length'"
                
    $Length_ID $db->Execute($Length_ID_Query); 
                
    $LengthID = (int)$Length_ID->fields['products_options_id']; 
         
                
    $Width_ID_Query "select products_options_id from " TABLE_PRODUCTS_OPTIONS " where products_options_name = 'Width'"
                
    $Width_ID $db->Execute($Width_ID_Query); 
                
    $WidthID = (int)$Width_ID->fields['products_options_id']; 
                 
                if (
    $this->contents[$products_id]['attributes_values'][$WidthID] && $this->contents[$products_id]['attributes_values'][$LengthID]) 
                
    $areaFactor $this->contents[$products_id]['attributes_values'][$WidthID]*$this->contents[$products_id]['attributes_values'][$LengthID]; 
                 
                else 
                
    $areaFactor 0
                
    $extraCharge $areaFactor $priceFactor
                } 
            else 
                
    $extraCharge 0
            
    //end Attribute Calculator 1.0 

            
    $products_array[] = array('id' => $products_id
                                      
    'category' => $products->fields['master_categories_id'], 
                                      
    'name' => $products->fields['products_name'], 
                                      
    'model' => $products->fields['products_model'], 
                                      
    'image' => $products->fields['products_image'], 
                                      
    'price' => ($products->fields['product_is_free'] =='1' $products_price+$extraCharge), 
            
    //                                    'quantity' => $this->contents[$products_id]['qty'], 
                                      
    'quantity' => $new_qty
                                      
    'weight' => $products->fields['products_weight'] + $this->attributes_weight($products_id), 
                                      
    // fix here 
                                      
    'final_price' => ($products_price $this->attributes_price($products_id) + $extraCharge), 
                                      
    'onetime_charges' => ($this->attributes_price_onetime_charges($products_id$new_qty)), 
                                      
    'tax_class_id' => $products->fields['products_tax_class_id'], 
                                      
    'attributes' => (isset($this->contents[$products_id]['attributes']) ? $this->contents[$products_id]['attributes'] : ''), 
                                      
    'attributes_values' => (isset($this->contents[$products_id]['attributes_values']) ? $this->contents[$products_id]['attributes_values'] : ''), 
                                      
    'products_priced_by_attribute' => $products->fields['products_priced_by_attribute'], 
                                      
    'product_is_free' => $products->fields['product_is_free'], 
                                      
    'products_discount_type' => $products->fields['products_discount_type'], 
                                      
    'products_discount_type_from' => $products->fields['products_discount_type_from']); 
          } 
        } 
        
    $this->notify('NOTIFIER_CART_GET_PRODUCTS_END'); 
        return 
    $products_array
      } 
    The thing is that that code was delivering the base price + the price by Area;

    All I had to do was to replace

    PHP Code:
    $extraCharge $areaFactor $priceFactor 
    by

    PHP Code:
     $extraCharge $areaFactor $priceFactor-$products_price
    Not that so far this is the only free sollution working on an open-source e-commerce platform, thanks a lot to the creator and have fun coding.
    Last edited by ChobPT; 3 Dec 2012 at 01:42 AM.

 

 

Similar Threads

  1. Price based on custom dimensions
    By shamkeem in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 3 Aug 2011, 04:58 AM
  2. User input product dimensions, update price based on inputs
    By TheStebes in forum Setting Up Categories, Products, Attributes
    Replies: 17
    Last Post: 7 Dec 2010, 03:58 PM
  3. price based on dimensions
    By jinx in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 24 Jan 2008, 08:35 PM
  4. Need User text input based on Attribute selected
    By heinz in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 7 Aug 2007, 09:35 PM
  5. Price based on dimensions (per square meter)
    By frankkubiak in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 28 Sep 2006, 04:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg