Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted

I'm trying to use the "Add Weight To Product Attributes v0.1" and "Actual Attribute Price V1.0" contributions together. Has anyone else tried this? They both edit the same lines of code on shopping_cart.php and I'm having trouble mixing the two together.

 

Here's what I'm trying to achieve: I have products that come in different sizes, with a different weight and price for each size. For example, the site sells dog food that comes 5lb, 10lb, and 15lb bags. I want the weights to be set up as attributes, so I don't have to list each size as a separate item with the catalog. When the optional size is selected, the additional weight needs to be calculated in the shipping. "Add Weight To Product Attributes v0.1" works perfect for this, however, I also want the "actual" price to appear in the dropdown menu, not + or -.

 

"Add Weight To Product Attributes v0.1" requires this edit to shopping_cart.php around line 230:

// attributes price
// [email protected]
// add-weight-to-product-attributes mod:
// added weight to db query
       if (isset($this->contents[$products_id]['attributes'])) {
         reset($this->contents[$products_id]['attributes']);
         while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
           $attribute_price_query = tep_db_query("select options_values_price, price_prefix, options_values_weight from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
           $attribute_price = tep_db_fetch_array($attribute_price_query);
           if ($attribute_price['price_prefix'] == '+') {
             $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           } else {
             $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           }
           if(!empty($attribute_price['options_values_weight'])) {
          	 // [email protected]
          	 // add-weight-to-product-attributes mod:
          	 $this->weight += ($qty * $attribute_price['options_values_weight']);
           } // END if(!empty($attribute_price['options_values_weight'])) {
         }
       }
     }
   }

And "Actual Attribute Price V1.0" requires this edit around line 230:

 

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// BOF - AAP V1.2.1 - updated to account for no price prefix to equal actual price
// attributes price

       if (!isset($this->contents[$products_id]['attributes']))
 {
         $this->total += tep_add_tax($products_price, $products_tax) * $qty;
 }
         $this->weight += ($qty * $products_weight);
       }


       if (isset($this->contents[$products_id]['attributes'])) {
         reset($this->contents[$products_id]['attributes']);
         while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
           $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
           $attribute_price = tep_db_fetch_array($attribute_price_query);
           $price_prefix = $attribute_price['price_prefix'];
           $option_price = $attribute_price['options_values_price'];
             $products_query = tep_db_query("select products_price from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
             $products_stuff = tep_db_fetch_array($products_query);
             $products_price = $products_stuff['products_price'];
           if ($price_prefix == '+') {
           $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           }
             if ($price_prefix == '-') {
             $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           }


           if ($price_prefix == '')
           {  
             if ($attribute_price['options_values_price'] == '0')
               $this->total += tep_add_tax($products_price, $products_tax) * $qty;
           }

           if ($attribute_price['options_values_price'] > '0') {
             if ($price_prefix == '') {
        	 if (ceil($option_price) != ceil($products_price))
          {
           $this->total += tep_add_tax($attribute_price['options_values_price'], $products_tax) * $qty;
          }
          else
          {
             $this->total += tep_add_tax($products_price, $products_tax) * $qty;
           $this->total += tep_add_tax(tep_adjust_price($option_price, $products_price), $product_tax) * $qty;
        	 }

             }
           }
         }
       }
     }
   }

// subtotal function for attributes price
   function attributes_price($products_id) {
     $attributes_price = 0;

     if (isset($this->contents[$products_id]['attributes'])) {
       reset($this->contents[$products_id]['attributes']);
       while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
         $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
         $attribute_price = tep_db_fetch_array($attribute_price_query);
         $price_prefix = $attribute_price['price_prefix'];
         $option_price = $attribute_price['options_values_price'];
         $products_query = tep_db_query("select products_price from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
         $products_stuff = tep_db_fetch_array($products_query);
         $products_price = $products_stuff['products_price'];
         //Check for special price
         $products_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$products_id . "'");
         $products_stuff = tep_db_fetch_array($products_query);
         if($products_stuff['specials_new_products_price'] != ''){
           $products_price = $products_stuff['specials_new_products_price'];
         }
         if ($price_prefix == '+') {
           $attributes_price += $option_price;
         }
         if ($price_prefix == '-') {
           $attributes_price -= $option_price;
         }
         if (($price_prefix == '') and  ($option_price > 0))
           $attributes_price += tep_adjust_price($option_price,$products_price);
         else
           $attributes_price+= $option_price;
       }
     }
     return $attributes_price;
   }
// EOF - AAP V1.2.1
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

 

Here's my failed attempt to combine the two (you'll notice the code for the "add weight" contribution added in the middle):

/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////
// BOF - AAP V1.2.1 - updated to account for no price prefix to equal actual price
// attributes price

       if (!isset($this->contents[$products_id]['attributes']))
 {
         $this->total += tep_add_tax($products_price, $products_tax) * $qty;
 }
         $this->weight += ($qty * $products_weight);
       }


       if (isset($this->contents[$products_id]['attributes'])) {
         reset($this->contents[$products_id]['attributes']);
         while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
           $attribute_price_query = tep_db_query("select options_values_price, price_prefix, options_values_weight from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$prid . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
           $attribute_price = tep_db_fetch_array($attribute_price_query);
           $price_prefix = $attribute_price['price_prefix'];
           $option_price = $attribute_price['options_values_price'];
             $products_query = tep_db_query("select products_price from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
             $products_stuff = tep_db_fetch_array($products_query);
             $products_price = $products_stuff['products_price'];
           if ($price_prefix == '+') {
           $this->total += $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           }
             if ($price_prefix == '-') {
             $this->total -= $qty * tep_add_tax($attribute_price['options_values_price'], $products_tax);
           }


           if ($price_prefix == '')
           {  
             if ($attribute_price['options_values_price'] == '0')
               $this->total += tep_add_tax($products_price, $products_tax) * $qty;
           }

           if ($attribute_price['options_values_price'] > '0') {
             if ($price_prefix == '') {
        	 if (ceil($option_price) != ceil($products_price))
          {
           $this->total += tep_add_tax($attribute_price['options_values_price'], $products_tax) * $qty;
          }
          else
          {
             $this->total += tep_add_tax($products_price, $products_tax) * $qty;
           $this->total += tep_add_tax(tep_adjust_price($option_price, $products_price), $product_tax) * $qty;
        	 }
        	 if(!empty($attribute_price['options_values_weight'])) {
          	 // [email protected]
          	 // add-weight-to-product-attributes mod:
          	 $this->weight += ($qty * $attribute_price['options_values_weight']);
           } // END if(!empty($attribute_price['options_values_weight'])) {

             }
           }
         }
       }
     }
   }

// subtotal function for attributes price
   function attributes_price($products_id) {
     $attributes_price = 0;

     if (isset($this->contents[$products_id]['attributes'])) {
       reset($this->contents[$products_id]['attributes']);
       while (list($option, $value) = each($this->contents[$products_id]['attributes'])) {
         $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . (int)$products_id . "' and options_id = '" . (int)$option . "' and options_values_id = '" . (int)$value . "'");
         $attribute_price = tep_db_fetch_array($attribute_price_query);
         $price_prefix = $attribute_price['price_prefix'];
         $option_price = $attribute_price['options_values_price'];
         $products_query = tep_db_query("select products_price from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
         $products_stuff = tep_db_fetch_array($products_query);
         $products_price = $products_stuff['products_price'];
         //Check for special price
         $products_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . (int)$products_id . "'");
         $products_stuff = tep_db_fetch_array($products_query);
         if($products_stuff['specials_new_products_price'] != ''){
           $products_price = $products_stuff['specials_new_products_price'];
         }
         if ($price_prefix == '+') {
           $attributes_price += $option_price;
         }
         if ($price_prefix == '-') {
           $attributes_price -= $option_price;
         }
         if (($price_prefix == '') and  ($option_price > 0))
           $attributes_price += tep_adjust_price($option_price,$products_price);
         else
           $attributes_price+= $option_price;
       }
     }
     return $attributes_price;
   }
// EOF - AAP V1.2.1
/////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////

 

Any suggestions? Thanks!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...