Adding Free bundle product to cart when subtotal is equal or greater than N amount

Hello Guys & Gals,

I like to share some code for adding free product to cart when subtotal is greater or equal to N amount (Amount is define in Backend)

You have to add two fields in system->configuration->sales section, Check the code below to add fields:

Copy file from core :: YourProject/app/code/core/Mage/sales/etc/system.xml
Paste to Local:: YourProject/app/code/Local/Mage/sales/etc/system.xml
Open file:: Search for “</groups> </sales>” Add below code snippents before the search terms.

<offers translate="label">
<label>Offer Bundle Product Id</label>
<bundle_product_id translate="label comment">
<label>Product Id Used in Offer</label>
<cart_subtotal translate="label comment">
<label>Cart Subtotal Used in bundle product Offer </label>

Clear cache from backend. And open System->configuration->sales:

There you can find 2 fields under “Offer Bundle Product Id” Add product id to “Bundle Product Id Used in Offer” field and subtotal amount to “Cart Subtotal Used in bundle product Offer “

After adding the above lines in system.xml open admin panel
Add below function in CartController.php

In function indexAction::search term ” foreach ($cart->getQuote()->getMessages() as $message) ” add below lines before search term

$this->addFreeProductToCart(); // This function is define below indexAction function to add free product to cart

Function defination of addFreeProductToCart

public function addFreeProductToCart()
$freeGiftProductId = Mage::getStoreConfig('sales/offers/bundle_product_id');
$freeGiftSubtotal = Mage::getStoreConfig('sales/offers/cart_subtotal'); //not including tax
static $lowStockWarningAmount = 5;
$freeGiftCartItemId = null;
$subtotal = 0;
if(($freeGiftProductId > 0) && ($freeGiftSubtotal >0)) {

foreach ($cart->getQuote()->getAllItems() as $item) {
if ($item->getProduct()->getId() == $freeGiftProductId) {
if ($item->getQty() > 1) {
$freeGiftCartItemId = $item->getItemId();
$subtotal = $cart->getQuote()->getSubtotal();

if ($subtotal >= $freeGiftSubtotal) {
$bundled_product = Mage::getModel('catalog/product')
if($bundled_product->isSaleable()) {

$bundled_items = array();
$bundled_options = array();
if($bundled_product->getTypeId() == 'bundle'){

$selectionCollection = $bundled_product->getTypeInstance(true)->getSelectionsCollection(
$bundled_product->getTypeInstance(true)->getOptionsIds($bundled_product), $bundled_product



foreach($selectionCollection as $option)
$bundled_options['bundle_option'][1][$option->option_id] = $option->selection_id;

$bundled_items[] = $option->product_id;
} else {
$bundled_options['bundle_option'][$option->option_id] = $option->selection_id;

$bundled_options['qty'] = 1;
$cart->getCheckoutSession()->addSuccess('Your free gift has been added to your cart .');
} else {
$cart->getCheckoutSession()->addError('The requested quantity for "'.$bundled_product->getName().'" is not available.');
} else {
//remove product if it is already there because the subtotal is less than the threshold
if ($freeGiftCartItemId != null) {
$cart->getCheckoutSession()->addSuccess('Your free gift has been removed from your cart due to insufficient subtotal.');


I am very glad to share my knowledge. If you have any question you can add comment to this post.

Mayank Zalavadia 🙂