I want to prevent configurable products from ending up in the cart. I want to add their simple product equivalent to the cart.
Despite this being a fairly normal request, I haven't found anything that is doing this.
I currently have an observer set up to work on checkout_cart_add_product_complete
checkout_cart_add_product_complete
I'm able to manipulate the cart from here (add, remove items), but I can't remove a configurable product (nor its options).
Does anyone know how this is possible?
Observer.php
class Mymodule_Addtocartredirect_Model_Customizablereplace {
public function replaceItems($observer) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$storeId = Mage::app()->getStore()->getStoreId();
foreach ($quote->getAllItems() as $item) {
$result = array();
Mage::log("We have a product! " . $item->getSku(),null,"test.log");
if($item->getOptionByCode('simple_product')) {
$childProduct = $item->getOptionByCode('simple_product')->getProduct()->getId();
Mage::log("We have ".$childProduct,null,"test.log");
}
if ($option = $item->getOptionByCode('simple_product')) {
$cartHelper = Mage::helper('checkout/cart')->getCart();
$quantity = $item->getQty();
$childProduct = $option->getProduct();
Mage::log("Child Product: ".$childProduct->getSku()." (".$childProduct->getId().")",null,"test.log");
$cartHelper->removeItem($item->getId());
$cartHelper->addItem($childProduct->getId(),$quantity);
}
}
$quote->collectTotals()->save();
}
}
Best Answer
Few days back,I did the same,by creating a custom module Create a module and in the CartController.php file, create the following:
Create a new save function
Done!!