When I add a product to cart then its related products will be added automatically with it and it's working. But, I want to make the price zero on the cart page for related products only, as they will be free. I have added event as below :
<events>
<sales_quote_add_item>
<observers>
<priceupdate_observer>
<type>singleton</type>
<class>Inchoo_CustomLinkedProducts_Model_Observer</class>
<method>modifyPrice</method>
</priceupdate_observer>
</observers>
</sales_quote_add_item>
</events>
Method in the observer is as below:
public function modifyPrice(Varien_Event_Observer $obs)
{
$free_product = $obs->getQuoteItem()->getProduct();
// Get all custom products
$custom_products = $free_product->getCustomProductCollection();
// get all custom product id and save in array
$custom_product_ids = array();
foreach($custom_products as $product){
$custom_product_ids[] = $product->getId(); // double check to make sure this product_id
}
//$collection = Mage::getModel('sales/quote_item')->getCollection();
// $items = Mage::getModel(‘checkout/cart’)->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
foreach($items as $item )
{
if(in_array($item->getProductId(), $custom_product_ids))
{
$price = $this->_getPriceByItem($item);
$item->setCustomPrice($price);
$item->setOriginalCustomPrice($price);
}
}
}
it is not working and i don't get related/custom product ids in the session , only 1 id gets printed.