Magento Checkout Cart – Adding Optional Product

cartcustom-optionsproduct

I have created a warranty as a product in magento which has 2 custom check box options. This product (warranty) does not have any specific page so I would like to display both the custom options of a warranty products as checkbox when selected one of the custom option the product (warranty) also should get added to the cart.

I want to display this addon product (warranty) only when the cart amount is larger then $2000. Is there any way to achieve this functionality? I have attached a screenshot below to illustrate the custom option.

Warranty option sample

Best Answer

You can create observer for events checkout_cart_product_add_after and checkout_cart_product_update_after and in your observer you can check cart total and add or remove product from cart dynamically.
You can try below codes :
getting totals

$totals = Mage::getSingleton(‘checkout/session’)->getQuote()->getTotals();//Total object     
$subtotal = round($totals["subtotal"]->getValue());//Subtotal value 
$grandtotal = round($totals["grand_total"]->getValue()); //Grandtotal value

adding product to cart

$cart = Mage::getModel('checkout/cart');
$cart->init();
$cart->addProduct($my_product, array('qty' => $qty_value));
$cart->save(); 
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

Similarly you can write for removing product from cart if while updating cart order total goes down the required amount.
Also in you can do necessary changes in item.phtml to remove remove link, qty update box and other stuff that you don't need.