Jump to content
Sign in to follow this  
aiyou

Help: Applying Discounts to Attribute Price

Recommended Posts

Hello All.

 

I'm trying to implement a different approach to Quantity Price Breaks, where as the discount is a percent off of the list price, rather than a fixed amount. The reason for this is that I also want to use Actual Attribute Pricing (http://addons.oscommerce.com/info/1716), and I need the discount percent to be applied to the attribute price, in addition to the base product price.

 

My starting point is QPBPP v 1.3.5. I modified the computePrice function in PriceFormatter as follows:

  function computePrice($qty, $nof_other_items_in_cart_same_cat = 0)
 {
   $qty = $this->adjustQty($qty);

   // Add the number of other items in the cart from the same category to see if a price break is reached
   $qty += $nof_other_items_in_cart_same_cat;

   // Compute base price, taking into account the possibility of a special
   $price = (true == $this->hasSpecialPrice) ? $this->specialPrice : $this->thePrice;

   if (is_array($this->price_breaks) && count($this->price_breaks) > 0) {
     foreach($this->price_breaks as $price_break) {
       if ($qty >= $price_break['products_qty']) {
         $price = $price_break['products_price'];
	  //aiyou
	  $factor = ($price_break['products_price']) / 100;
       }
     }
   } // end if (is_array($this->price_breaks) && count($this->price_breaks) > 0)

$price = ($this->thePrice * (1-$factor));

   return $price;
 }

 

So, this adjusts the product base price by the discount percent (or, at least it seems to in my limited testing so far).

 

However, I've stepped through the shoppingcart.php and priceformatter.php file trying to find where the attribute price gets added to the base price, but nothing seems to work. The attribute price (whether +, - or actual) ends up getting added to the (now discounted) product price at 100% value.

 

I've tried various modifications to the attributes references within the calculate and attributes_price functions within shoppingcart.php to no avail.

 

Can anyone point me in the right direction?

 

Thanks in advance.

Rob

Share this post


Link to post
Share on other sites
Hello All.

 

I'm trying to implement a different approach to Quantity Price Breaks, where as the discount is a percent off of the list price, rather than a fixed amount. The reason for this is that I also want to use Actual Attribute Pricing (http://addons.oscommerce.com/info/1716), and I need the discount percent to be applied to the attribute price, in addition to the base product price.

 

My starting point is QPBPP v 1.3.5. I modified the computePrice function in PriceFormatter as follows:

  function computePrice($qty, $nof_other_items_in_cart_same_cat = 0)
 {
   $qty = $this->adjustQty($qty);

   // Add the number of other items in the cart from the same category to see if a price break is reached
   $qty += $nof_other_items_in_cart_same_cat;

   // Compute base price, taking into account the possibility of a special
   $price = (true == $this->hasSpecialPrice) ? $this->specialPrice : $this->thePrice;

   if (is_array($this->price_breaks) && count($this->price_breaks) > 0) {
     foreach($this->price_breaks as $price_break) {
       if ($qty >= $price_break['products_qty']) {
         $price = $price_break['products_price'];
	  //aiyou
	  $factor = ($price_break['products_price']) / 100;
       }
     }
   } // end if (is_array($this->price_breaks) && count($this->price_breaks) > 0)

$price = ($this->thePrice * (1-$factor));

   return $price;
 }

 

So, this adjusts the product base price by the discount percent (or, at least it seems to in my limited testing so far).

 

However, I've stepped through the shoppingcart.php and priceformatter.php file trying to find where the attribute price gets added to the base price, but nothing seems to work. The attribute price (whether +, - or actual) ends up getting added to the (now discounted) product price at 100% value.

 

I've tried various modifications to the attributes references within the calculate and attributes_price functions within shoppingcart.php to no avail.

 

Can anyone point me in the right direction?

 

Thanks in advance.

Rob

Hi Rob,

 

Is this going to be applied to all products having same percentage discount if so try this http://addons.oscommerce.com/info/3367 can make qty 1 to get the discount

 

Steve

Share this post


Link to post
Share on other sites

Thanks Steve.

 

I had not seen Discount Per Products Quantity contribution previously. Having just looked at the general contribution overview, it's not quite what I was after, but may be worth pursuing if I can't get my desired approach to pan out.

 

To make things simple, many products might share a similar price break scheme, but that is not a requirement. I liked the concept of the original QPBPP, but with the use of attribute pricing, not all product/attribute combinations were seeing the same percentage of savings (as a $10 item, with a $1 off 5 or more would be 10% savings, but if the same $10 product had a $10 attribute selected, the same $1 discount would be applied, resulting in a 5% savings). The use of actual attribute pricing further complicated matters, but was a necessity to address customer confusion in pricing. So, now a need to apply a quantity percent discount.

 

I did find that my use of $factor within the PriceFormatter was not being carried back to shopping_cart. For a php programmer, probably a "well, yeah" observation, but this has been some of my most in depth php coding short of merging contribs. By redeclaring it as this->$theFactor and then referencing it from within shopping_cart as $pf->theFactor, the value was available for use. I have some rounding issues that I need to address, and some more testing to ensure that the discount factor is applied correctly to items in the cart (and balances to the cart subtotal).

 

And, after seeing some other threads regarding discounts and their impact on payment authorizations (PayPal, Authorize.net, etc), I now know I need to double-check that aspect as well.

 

If any are interested, I'll post the in-progress modifications for review and feedback.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×