Magento extension: Buy X selection of products, Get another Y selection for free

When to use:
Magento has a native “buy x get y” sales rule in promotions. Magento’s x and y refer to a same product. For example, if a product offer is “buy 3 get 2”, you have to buy 5 of this product then only pay for 3 of them.

Quite often the store owners want to give an offer which let customers choose from a wide range of products, (the programme add them up, get a total quantity of subselect), and offer another selection of products for free. It is useful if the store have two ranges of products, among which prices are almost the same. Let’s make it clear to you: in this module, “buy x get y” means “Buy X selection of products, Get another Y selection for free”.

I wrote some quick and dirty codes to do “Buy X selection of products, Get another Y selection for free” quite a while ago, but this release refactors the codes into a standard standalone Magento extension.

How to install:
Copy the whole “app” folder, merge to magento/app. That’s it.

If you are logged in Magento backend when doing installation, that’s fine. But you have to log out and log in again to access Buy X Get Y configuration section in System Configuration.

How to use:
Log in Magento backend, go to Promotions -> Shopping Cart Price Rules, create a new rule whose name must start with “[bxgy]”;

In “Rule Information” tab, apart from the Rule Name, set up everything else as if it is normal Magento sales rule;

Screenshot: Rule Information
Screenshot: Rule Information

In “Conditions” tab, create a product total quantity subselect. The product subselect should match the selection of X product in the offer, and condition is “equals or greater than”, and quantity should match the quantity of X product used as qualifier;
* Do not create more than one subselect. Result is unpredictable otherwise.
* The condition must be “equals or greater than” and the quantity must be the threshold quantity of the offer. Although the calculation of the free quota of Y product is not dependent on the quantity (it is dependent on the settings in “Actions” tab), the offer validation is still Magento original logic. This module changes the discount amount after the offer validation. In other words, you must think about when to trigger Magento native “buy x get y”, and do the same conditions for this module.

Screenshot: Conditions
Screenshot: Conditions

In “Actions” tab, set Apply to “Buy X get Y (discount amount is Y)” (although this is not normal buy_x_get_y action, the program still check this simple_action), set Discount amount to offer free quota, set Maximum Qty Discount is Applied to to 0, set Discount Qty Step (Buy X) to offer quantity qualifier. For example, if the offer is “buy any 3 of X products, and get any 2 of Y products free”, then set Discount amount to 3, set Maximum Qty Discount is Applied to to 0, set Discount Qty Step (Buy X) to 2. Then, in “Apply the rule only to cart items matching the following conditions (leave blank for all items)”, create a combination of conditions which match the selection of Y product in the offer. Multi combination is OK;

Screenshot: Actions
Screenshot: Actions

In “Label” tab, enter the offer labels as normal. It is not required, but if you leave it blank, the “ugly” Rule Name “[bxgy]***” will be used is discount description;

Now save the rule, and go to System -> Configuration -> Buy X Get Y -> Buy X selection of products, Get another Y selection for free, set up the offer reminder message in cart. It is not required. And if it is not set up, the offer is still taking effect as long as the sales rule is enabled.

How is it created:
This module is created by koukou1985’s module creator ( Thanks to koukou1985.

How good is it:
This module does not override any Mage classes. It is safe to use with other extensions as long as namespace and module name do not conflict.

Q: Why this module does not work?
A: I won’t cover all reasons that make my module not working. I only point out caveats of my module, and expect you to have common knowledge of Magento, such as “refresh the cache to see the newly installed features”. All caveats are in above sections. So, if you are stuck, go back to the top and read again.

Download BuyXGetY.tar.gz

Update: a new version of bxgy module is available at

2011/02/21 Update again: please checkout a newer release. Always leave comments on the newest release post. The comment on this post is closed.


  1. Thanks for this. It’s very helpful. I can get it to give me the discount on the free product, but I can’t get it to give me the reminder when I don’t have the Y product in the cart. I’m on 1.4.1

    Also, it would be great if the extension could automatically add the Y to the cart when the X condition was met. If the Y was a configurable product, it could redirect to the configurable product page and let the user choose the color/size/etc. and add to cart the Y.

  2. Thank you for suggestions.

    This bxgy is featuring defining x selection and y selection using magento’s native interface. When y selection is across a range of products, it is not possible to add y automatically. The purchase logic is customers shopping as usual, and when the conditions are met, bxgy applies automatically.

    It is inspired (of course, required firstly) by the company I am serving. From the figure I observed, only 50% customers from a segmented market take the free gift. Even Y was a configurable instead of a selection, automatic adding or redirecting is annoying. That’s why I only “reminder” them to take the gift not “force” them.

    I also leave the choice of whether or not reminder customer to you. You need to enable the reminder in system configuration.

    Please note a newer version is available at

    Sorry my blog is lack of facility to put information together. It would be good if you could find the newest version in the first place.

  3. I LOVE YOU…
    just kidding… But seryous, i’m for days searching how to make THIS man… And i finally found the answer. At first, really thanks by the module, god bless you man…. Really, you don’t know how i’m happy!!!!

  4. Hey man, i’m using your module, and it’s preety good! I Was wondering if i could make an promotions like that, but the custumer which have the cart price greater them 49.90 win y products, could i do it with this module?

  5. You can add min order 49.90 as 2nd condition. My module will ignore it, but magento native validation will validate it before my module have chance to change the discount result. However, it conflicts with reminder in shopping cart. Either disable reminder or change reminder logic (if you can).

  6. Thank you so much for this moduel, it helped me a lot.
    The only feature I can’t get to work is de reminder. It just won’t show, even when it is set to ‘Yes’ in the configuration.
    I am using version 14.1.1

  7. On this extension i think “Buy any X get any Y free”.

    where we can select ANY “Y” products?

    My requirement is

    i need a shopping cart price rule as follows.

    The rule has to perform a conditon that Buy 50 products then 20 products Free.
    A shopping cart price rule contains set of products.

    When a customer Buys ANY 50 products from the set of products as we mentioned in the rule then the customer gets a popup which contains 20 products(products from the rule) select for Free.

    Like this there were other rules also.(Buy 20 get 10 products Free,etc..)
    There is a conflict case which a product may exists in many rules.

    Any help would be appreciated.

  8. I have uploaded all the code to my server and also added shopping cart price rule. But after going to System -> Configuration -> Buy X Get Y, it says Access Denied!

    Need help.


  9. i think i covered this in FAQ section of readme.txt. Access Denied is not a bxgy module specific issue. Any newly installed Magento modules have this issue. All you need to do is log out and log in again (and consult magento documentation).

  10. hi,

    where can i find the reminder message? its not working for me even the cart satisfies my rule.

    Does the customer can able to select “Y products”?(i mean free products)

    i need like this.


  11. reminder message is shown at /checkout/cart/index

    you remind me to improve bxgy. when i did bxgy, the company was using the setting “redirect to shopping cart after adding a product”. so the reminder message shown there is all right. however, if you are not using this setting, you will be frustrated. i’ll find some time to improve bxgy fit for generic settings.

    customers can select y products. for good usability, you can make a category page with all y products on it and lead customers to that page in the reminder message.

  12. For some reason this is discounting by the cost of the first item in the cart not the cheapest (unless that is the cheapest)…. have I done something wrong?

  13. Hi – thanks for this extension! It works great – for the first matching product(s). How do I get it to work for multiple products? For example, if I have a BOGO free promo, and I have 4 qualifying products in my cart – I want the first 2 products to be paid for, and the next 2 products free. Currently it seems that it will only give you 1 free item regardless of the amount of products in your cart. Is there something I am doing wrong?

    Thank you again!!!

  14. to: Erin, Assume you just want “buy x get y”, and x and y are from an identical selection, you DO NOT need my bxgy extension – Magento native promotional rules can do that.

    My bxgy let you define x and y from x selection and y selection respectively.

  15. I don’t get it, i’d like to do this:
    buy 20 products of sku 1224 get sku 1270 for free.

    I have made a Shopping Cart Price Rule:


    If ALL of these conditions are TRUE :
    * Total Items Quantity equals or greater than 20
    * If an item is FOUND in the cart with ALL of these conditions true:
    o SKU is 1224 Apply

    And action:
    Amount = 1

    If ALL of these conditions are TRUE :
    * SKU is 1270 Apply

    How to do this?

  16. You are almost there. Just check Conditions – do not use total quantity (it refers to totoal quantity of the cart). You must use subselection.

    If ALL of these conditions are TRUE :

    * If total quantity equals or greater than 20 for a subselection of items in cart matching ALL of these conditions:

    Click on my screenshot you might get more ideas

  17. In Actions, you left Discount Qty Step (Buy X) empty. You must enter 20 in your case to satisfy Magento’s native rule validation, because my extension relies on Magento’s native validation but changes its original discounting logic.

  18. Thanx allot, i’m really glad i ran into your post :D

    Would have been great if the product automaticly will be added to the card but this is okee too!

  19. I’m glad you get it working.

    As for automatic adding products to cart, this feature has been asked for by someone else earlier, but it conflicts with what I want to achieve with bxgy module. What I want to achieve is – Site owners can define an arbitrary collection of products for Conditions, and another arbitrary collection of products for Actions. Then within these collection, customers can choose whatever they want.

    But, it’s open source, you can modify my code to achieve what you want.

  20. Hi again,

    I got the module working the way I want. However – I am having the same problem as longerlife. IF I have two products in the cart – product X for $100 and product Y for $50, my discount amount is $100 since it is the first in the cart. Is there a tweak for having it always pick the lowest price?

    Thank you!!!!!


  21. You might make things over complicated. If you only want people buy a product for $100 and give away another product for free, you do not need my bxgy module. You can use Magento standard percentage or fixed amount price discount.

    Understanding the concept of X and Y is vital before you do anything. When Magento says buy x get y, it refers to a single product, of which x or y is the quantity. In my bxgy module, buy x get y means two ranges of products, of which x or y is the quantity respectively. But you are talking about x y totally differently.

    Item sequence in cart, or which product is higher/lower price makes no difference to my module, if set up correctly. (Just mention that. you do not need my module anyway)

  22. Hi,

    sorry if my terminology is wrong. I have two completely separate products, if you buy one you get the cheaper one free. I have tried this with the Magento built-in function and it does NOT work if the products are different. It seems your module does what I need – however I need it to pick the cheapest product as the free product.

    Does this make sense?

    Thanks for taking the time to respond.


  23. Hi, Erin

    If I do it, I’ll create a shopping cart price rule, in Conditions define your $100 product (I don’t call it X product because it’s misleading), in Actions define your $50 product, apply “percent of product price discount” as 100 (which means 100% free).

    Your discounting model is simple. Forget my bxgy, also forget Magento’s buy x get y.

    Thank you for thinking of me.


  24. Great extension. However, I also have a problem with reminder message showing up. I use the redirect to the shopping cart after adding the product and it’s still not there. The discount works fine though.

  25. I have checked whether reminder message is showing at shopping cart. I did not find anything wrong. The environment is Magento beta2, but I believe 1.4.x.x is fine for this module.

    People said it not working? Maybe I need to write better instruction for them.

    Bxgy version 1.0.0 will be released soon after I refactor all my modules. 18 modules so far.

  26. Thank you for great extension but it does not seem to work on my site.
    I’d like to do this:
    buy 3products of sku 1234, get 1 sku 4321 for free.
    I have made following Shopping Cart Price Rule:
    If ALL of these conditions are TRUE :
    * If total quantity equals or greater than 3 for a subselection of items in card matching ALL of these conditions;
    * SKU is 1234
    And action:
    Discount Amount = 1
    Maximun Qty Discount is Applied To = 0
    Discount Qty Step(Buy X) = 3
    If ALL of these conditions are TRUE :
    * SKU is 4321
    Did I miss something?
    I neither see reminder message nor the rule applying in my cart.
    BTW, I am using

  27. Thank you, it is working beautiful.
    However, the reminder message is still missing even after I enabled System/Configuration/Buy X Get Y/Enable offer reminder message to “YES”.
    Is there something else do I need to do in order to get this work?
    I refreshed all caches but still not working
    BTW, I am using original magento blue theme, now, for the test.

  28. Hi!
    I’ve just found out that your module is not compatible with Sweet Tooth extension!
    Actually the reminder is displayed and relevant, but the promotion takes no effect. But it does work when I disable Sweet Tooth module.

    If you have any idea why, please let me know! I’ll try to investigate on my side and tell you if I find something as well.

  29. Actually Sweet Tooth overrides Mage_SalesRule_Model_Validator class (I don’t know what on earth they did that for).
    I temporally resolved this issue by just commenting that overriding node in their config.xml and both modules seem to work together fine so far. Just crossing my finger I won’t get any tricky bug in the long run.

  30. A unique (at least I did not see it elsewhere) feature of Magento is class overriding by extensions. It is powerful and easy way to customise Magento into a logic you want. But as I pointed out in another post, the final manipulated Magento config can only find one overridden class, so if two extensions are overriding a same class, they are not likely to work together. Or in your case, even bxgy does not override a class (but it still depends on Magento native class) but another extension overrides the class into something totally unexpected by bxgy, they are not likely to work together, either.

    Another way to inject the logic to Magento is using event-observer. In my opinion, it is safer and more “eco”. However, it is not a unique feature of Magento, so Magento does not promote it as much as overriding. And it is slightly difficult to code – usually costs me twice time if I insist no-overriding.

    I can’t rule how others do coding, but I have my own protocol: try event-observer first, use overriding as last resort.

    Anyway, I’m glad you sort it out.

  31. Hi Christopher,
    Can you tell me where and how exactly you changed your coding?
    I am no programmer and just started to use Magento, and I would like to use this extension and sweet tooth at the same time.
    I am using Magento and I still have problem displaying reminder although the extension is working fine.

  32. Hello everybody.

    First of all. Thank you for the Extension.

    I would like for us to provide a feature-request. The reminder Messages is set in the Admin-Configuration. I use the extension for rules like this: Buy X A’s => Get Y B’s for Free. (One rule for one article)
    In this case it is very usefull, if the reminder-message can be set in each validation-rule.
    => PERHAPS we TRY to extend the extension with automatically add of the Y B’s to cart, if I got some free minutest.

    I had a configuration-problem with the Reminder-Message too.
    I found out theat the path in the archive is not completed (for us).
    Path in Archive: app/design/frontend/default/layout/qian/bxgy.xml
    I miss the templatename after /app/design/frontend/default/[TEMPLATE-NAME]/layout/qian/bxgy.xml

    I configured the template in our case to /app/design/frontend/default/xdot/layout/qian/bxgy.xml.

    Hopefully this can help with the Reminder-Problem.

    Best Regards


  33. Thank you very much, Carsten.

    I was told bxgy not showing reminder many time. I did check once and it was all right on my test server. So I assume it was theme setting causing the problem. I did not know that totally due to my carelessness, I packaged bxgy.xml into wrong folder. Bxgy 0.1.1 and bxgy 0.1.0 are affected.

    Bxgy 0.1.2 is a quick release to fix it. I am awfully sorry for wasting people time trying to figure out why reminder message cannot show up.

    Have said that, theme setting is still a possible area causing the problem. That’s why I changed structure of bxgy in late version (not ready yet).

Comments are closed.