Magento Buy X Get Lowest Priced Item Free

An extension for Magento on Magento Connect (here) allows users to run a promotion similar to Buy X Get Y Free, but of different products (instead of a number of the same products). The caveat to this extension however is that it breaks a Magento 1.4.x installation completely, due to key changes in the coupon validation routines in the upgrade.

Anyway, I attach to this post the fixed file. Unzip this file, overwrite app/code/local/Sttl/Buygetfree/Model/Validator.php with the one inside the zip, and go create some promotions!

Have fun.

P.S: This ([download id=”1″ format=”7″]) is a full version of all the module’s files if you find it easier to do it that way. Place this file in app/code/local and extract. Then create a file called Sttl_Buygetfree.xml in app/etc/modules and put this inside of it:


21 replies on “Magento Buy X Get Lowest Priced Item Free”

  1. Hi!

    Thanks for the modification. Unfortunately I can’t get this working on my installation.

    Please see my options as follows:
    Status: Active
    All websites, all customer groups
    No coupon
    1000 uses per customer (just wanted to have some other value than 0 in it)

    Rule: all must be true; articleqty equals or greater than 4
    and on the actions-tab I’ve choosen all options as shown in the pictures at megentocommerce. 🙁
    any hint what I’m doing wrong?

  2. Hi,
    Have you tried it with a coupon code and activating it on the cart page? It might also be worth reading my other post on this subject here which lists the values for every setting in the promotions window in order to get this working correctly. It’s worth at least getting that far and then modifying the settings once you’ve got it working.

  3. Hi,

    If my promotion is ‘buy 3 get the cheapest free’, can this module be set up to allow for when the customer buys 6, 9 or 12 items and gets the 2, 3, or 4 cheapest items for free?

    If you can help with this configuration, I’d be happy to reimburse you for your time.


    Craig Bartholomew

  4. Howdy,

    In theory, it should already do that. If you read my other post on this article, it describes the configuration for the cart rule in detail. This should work in multiples, so if you have “buy 3 get cheapest free” promotion, it should discount a number of the cheapest matching items depending on how many multiples of the rule there are. So 1 multiple (3 products) will discount the cheapest product that matches, 2 multiples will discount the 2 cheapest products of the 6 products that match, 3 multiples will discount 3 of the cheapest products of the 12 products that match. i.e; 1 for each multiple.


  5. Hi Dan,

    Thanks for the fast reply. I had already set up the rule as per your instructions, except that my qualifying products are based on attribute set id, rather than category id. However, it does not work. Regardless of the quantity in the cart, the discount only applies to one product.

    I’m changing some of the logic to get the module to work as I would like. However, your input would be most welcome. If I get there before you, I’ll happily post my changes.



  6. Hi Craig,
    In your promotion rule under the “Conditions” tab, set “If total quantity equals or great than 3 for a sub-selection of items in card matching all of these conditions:”, “Attribute set is [attribute set selection]”. Then under “Actions”, set “If all of these conditions are true:”, “Attribute set is [attribute set selection]”. This should substitute the rule from using category to attribute set instead for matching products.
    I’ve not tested this, but in theory it should work as you expect it to.
    Hope this helps.

  7. Hi, I’ve installed your module but the promotion is never applied in the shopping cart.
    I need to apply this promotion, buy 3 and get the lowest free on all website
    Can you please help

  8. Hi, This is a great fix, thank you!

    I used it and it works almost great, I set up the rule as per your instructions in the other post. it works fine for one free product but it does not work as expected when quantity in the cart should give more than one products for free, in this case, the
    discount only applies to one product.

  9. I can’t seem to get this working on Magento The action “Buy X get lowest item free” isn’t showing in the dropdown. I used the “full version of all the module’s files”-installation.

    Anyone have this up-and-running in Magento

  10. Yes I have it working on 1.5.01 but it only works on the 1st set of items, I haven’t been able to get it to work on multiple sets. e.g buy 4 get 1 free works great but if someone buys 8 they should get 2 free but they dont they still only get 1 free. I’ve even tried setting the rule so that if they buy 8 they get 2 free but it seems to only give 1 lowest free no matter what.

    THe way I got it working was installing it with Magento Connect then copying the validation file from the full pack provided here.

  11. Ok, got this working now in Magento Thanks Greg. I don’t have the same problem as you do though. If a customer buys 8, he gets 2 for free. If he buys 1, he gets 1 for free. Be sure to check your “Discount Qty Step (Buy X)”, the conditions and action conditions.

    What I noticed is that it only applies to single products in the category. So if you buy DIFFERENT products in the same category, the rule is not working somehow…

  12. Never mind. I overlooked the Apply in the Action tab. I still can’t choose “Buy X get lowest item free (Discount amount is lowest item price)”. I can only choose the standard “Buy X get Y free (discount amount is Y)”. That figures why it was acting that way. Bummer…

    So conclusion is that I still can’t get this working in Magento 🙂

  13. I’m afraid this does not work for multiples of items without modifying the code. In the validator class, there is no multiplier for the number of multiples of the total quantity for the items involve in the cart.

  14. Any chance of getting the link to the amended Validator.php back up?

    It can’t find the file at the moment.


  15. Hey! Dan,
    I am working to set this up in my store, I tried your extension but I think the logic you are using in Validator.php file is incorrect.

    case ‘buy_x_get_lowest_free’:
    $x = $rule->getDiscountStep();
    $y = $rule->getDiscountAmount();

    $session = Mage::getSingleton(‘checkout/session’);

    $output = array();

    foreach ($session->getQuote()->getAllItems() as $item)
    $check = $item->getQty();

    $prc = $item->getBaseCalculationPrice();

    if($prc > 0)
    for($i=0; $igetBaseCalculationPrice();


    if($x <= count($output))
    $quoteAmount = min($output);
    $discountAmount = $quoteAmount;
    $baseDiscountAmount= $quoteAmount;


    I am very close to the solution. Hopefully I will be able to post the solution after getting it done.

Comments are closed.