i want to append some extra thing to all product name in view cart how can i do it via observer
please tell which observer should i use or call for that
Magento product name at Cart has been coming from function getProductName
() at class
Mage_Checkout_Block_Cart_Item_Renderer_Configurable
and
Mage_Checkout_Block_Cart_Item_Renderer
You need to change on this function.So rewrite those two blocks and do change
on function getProductName
.
public function getProductName()
{
if ($this->hasProductName()) {
return $this->getData('product_name');
}
return $this->getProduct()->getName(). 'myAppend';
}
mour,you can do this by event sales_quote_item_set_product
<events>
<sales_quote_item_set_product> <!-- identifier of the event we want to catch -->
<observers>
<sales_quote_item_set_product_handler> <!-- identifier of the event handler -->
<type>model</type> <!-- class method call type; valid are model, object and singleton -->
<class>magento58323/observer</class> <!-- observers class alias -->
<method>setmynameOption</method> <!-- observer's method to be called -->
<args></args> <!-- additional arguments passed to observer -->
</sales_quote_item_set_product_handler>
</observers>
</sales_quote_item_set_product>
</events>
And
function change name
<?php
class Stackexchange_58323_Model_Observer
{
public function setmynameOption(Varien_Event_Observer $observer)
{
$Event = $observer->getEvent();
//Mage::dispatchEvent('sales_quote_item_set_product', array('product' => $product,'quote_item' => $this));
$product=$Event->getProduct();
$quote_item=$Event->getQuoteItem();
$quote_item->setName($product->getName().'myappend');
return
}
}
I wanted to do the same thing..... after trying all the day finally I ended up doing adding an extra column at the table "sales_flat_quote_item" named custom_product_name and saved the modified name.
just like $item->setCustomProductName($modified_name) and save it $item->save();
inside the deault.phtml (your_theme/checkout/cart/item/default) invoke the modified name $item->getCustomProductName()..
of course, careful with the other product names... so check the product type using if statement