Magento – Offering a free gift with purchase of a particular product type like (Buy X products Get Y Free)

catalog-price-rulescatalog-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

The best way to achieve what you want is to create a custom module for this. You can follow below approach for this.

1) Create a product attribute for example: free_gift_sku with type as dropdown and enter sku of all the free gift products. Associate this attribute with each products

2) Now while creating the product, select the free_gift_sku value as the SKU of the product which is required to be added as free gift for that product.

3) Observe an event checkout_cart_product_add_after and get the details of the product added to the cart through quote_item. You will get all the details of the product which also includes SKU of the free gift product.

4) Now programmatically add the free gift product to the basket. You can define the logic of adding the product as per your requirement.

Please Note: The code for observer and adding product to basket programatically is different for Magento1.x and Magento2.x. Digging into the code/Googling it will help you out.

To save you some time, please check this thread to add product to cart programmatically in Magento2

Magento2 - How to add a product into cart programatically when checkout_cart_product_add_after is fired

Hope it helps