Web Design Forum: Magento help - Buy X get Y free promotion - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Magento help - Buy X get Y free promotion Rate Topic: -----

#1 User is offline   wkdfx 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 89
  • Joined: 09-June 08
  • Reputation: 0
  • Gender:Male
  • Location:Manchester, UK
  • Experience:Advanced
  • Area of Expertise:SEO

Posted 15 April 2010 - 02:00 PM

Hi Guys,

I'm implementing a promotion on a site - Buy 2 get 1 free on everything.

Magento has a similar promotion by default which only applies on an individual product and not on all products in the cart!

So, here's the default code:

case 'buy_x_get_y':
                    $x = $rule->getDiscountStep();
                    $y = $rule->getDiscountAmount();
                    if (!$x || $y>=$x) {
                        break;
                    }
                    $buy = 0; $free = 0;
                    while ($buy+$free<$qty) {
                        $buy += $x;
                        if ($buy+$free>=$qty) {
                            break;
                        }
                        $free += min($y, $qty-$buy-$free);
                        if ($buy+$free>=$qty) {
                            break;
                        }
                    }
                    $discountAmount    = $free*$itemPrice;
                    $baseDiscountAmount= $free*$baseItemPrice;
                    break;


someone came up with this solution but only works on the first three products:

case 'buy_x_get_y':
                          $cartRules = $address->getCartFixedRules();
                             $x = $rule->getDiscountStep(); //2
                              $y = $rule->getDiscountAmount(); //1

                      if ($quote->getItemsSummaryQty()>=($x+$y)){

                       if (!isset($cartRules[$rule->getId()])) {
                                    $cartRules[$rule->getId()] = $item->getPrice();
                                }elseif($cartRules[$rule->getId()]>$item->getPrice()){
                        $cartRules[$rule->getId()] = $item->getPrice();
                        }

                        
                                if ($cartRules[$rule->getId()] > 0) {
                                    $quoteAmount = $quote->getStore()->convertPrice($cartRules[$rule->getId()]);
                                    $discountAmount = min($item->getRowTotal(), $quoteAmount);
                                    $baseDiscountAmount = min($item->getBaseRowTotal(), $cartRules[$rule->getId()]);
                                    $cartRules[$rule->getId()] -= $baseDiscountAmount;
                                }

                    $address->setCartFixedRules($cartRules);
                    }

                      break;


I would appreciate your thoughts on this!

WkdFX
0

#2 User is offline   wkdfx 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 89
  • Joined: 09-June 08
  • Reputation: 0
  • Gender:Male
  • Location:Manchester, UK
  • Experience:Advanced
  • Area of Expertise:SEO

Posted 19 April 2010 - 11:06 AM

Any Ideas...
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users