Magento – Offering a free gift with purchase of a particular product type

catalog-rulesfree-giftpromotions

We need to the ability to provide customers who purchase a particular product type (attribute type) a free type of gift with that product.

The products offered as a free gift are associate products of a configurable product. They need to be linked so that when this free gift is selected, it deducts from this SKU's quantity in inventory.

There are about 100 of these types of products that will be offered as a free gift – so ideally presenting the options in a dropdown menu would be preferred.

We've checked out about 10 'free gift extensions' now for Magento (and can't find any more) and none of them can do what we want or are wrote appallingly. They mostly auto add products at cart based on a rule like total amount. They're all limited in functionality and offer mininal to no flexibility.

I'm unable to add this as a configurable option due to the setup.

I can create them as a custom option but then they do not link up with the actual product SKU's and deduct from quantity in inventory.

Can anyone advise of an extension that can do this or the best way to implement this ability? It's looking more and more likely that we'll have to write our own extension to do this but find it hard to believe there would not be something out there that does this already.

Best Answer

As you've mentioned there are 10+ extensions that do this. No extension is going to fulfill your every business rule out of the box - make it yourself!

  • Create one 'free' product
  • Set their visibility to be 'Not Visibile Individually'
  • Set the 100+ custom options on the product
  • Create a System > Configuration input field and tab set to manage the ID of the free product (alternatively create a product attribute or attribute set that identifies the product as a free product type). I will use the former as a suggested approach.

Then, create a new block and template to display the custom options from this product:

<?php

class YourCompany_YourModule_Block_Freeproduct extends Mage_Core_Block_Abstract
{

    protected $_freeProduct;

    public function getFreeProduct()
    {
        if(!isset($this->_freeProduct)){
            $id = Mage::getStoreConfig('system/freeproduct/free_product_id');
            $this->_freeProduct = Mage::getModel('catalog/product')->load($id);
        }

        return $this->_freeProduct;
    }

    public function getFreeProductOptions()
    {
        if($product = $this->getFreeProduct()){
            if(!$product->hasOptions()){
                return;
            }

            return $product->getOptions();
        }
    }

}

And make use of getFreeProductOptions in your template/phtml file:

<?php if($options = $this->getFreeProductOptions()): ?>

    <select name="free_product">
        <?php foreach($options as $option): ?>
            <option value="<?php echo $option->getId();?>"><?php echo $option->getTitle(); ?></option>
        <?php endforeach; ?>
    </select>

<?php endif; ?>

You will want to call this block that renders the template from inside a getChildHtml and locate that inside of the <form> element on your theme's catalog/product/view.phtml file. This way, the free_product value comes along for the ride with an add to cart button click.

All you have to do then is create an observer of the cart add postdispatch event and examine the request object. From there you'll have the chosen option id to add to the cart. Voila!

Best of luck!