1

Trying to implement the buy 1 get 1 free but making it incremental. If a customer adds 2 products, customer gets 2 of the same product free. If a customer adds 3 products, customer gets 3 of the same product free and So on. Is this possible with shopping cart rules? if not, is there a reference site with code, that I can use to make it work.

 protected static function _getFreeQuoteItem(Mage_Sales_Model_Quote $quote, $sku, $storeId, $qty)
{
    if ($qty < 1) {
        return false;
    } else {
         $qty=$Qty1;
    }

    /** @var Mage_Catalog_Model_Product $product */
    $product = Mage::getModel('catalog/product')->loadByAttribute('sku', $sku);

    if ($product == false) {
        return false;
    }

    Mage::getModel('cataloginventory/stock_item')->assignProduct($product);

    if ($product->isSalable() == false) {
        return false;
    }

    $quoteItem = Mage::getModel('sales/quote_item')->setProduct($product);
    $quoteItem->setQuote($quote)
            ->setQty($qty)
            ->setCustomPrice(0.0)
            ->setOriginalCustomPrice($product->getPrice())
            ->setIsFreeProduct(true)
            ->setWeeeTaxApplied('a:0:{}') // Set WeeTaxApplied Value by default so there are no "warnings" later on during invoice creation
            ->setStoreId($storeId);
    $quoteItem->addOption(new Varien_Object(array(
        'product' => $product,
        'code' => 'info_buyRequest',
        'value' => serialize(array('qty' => $qty, 'is_free_product' => true))
    )));
    // With the freeproduct_uniqid option, items of the same free product won't get combined.
    $quoteItem->addOption(new Varien_Object(array(
        'product' => $product,
        'code' => 'freeproduct_uniqid'.$sku,
        'value' => uniqid(null, true)
    )));

    return $quoteItem;
}

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.