i want to change product name to custom name when added to cart:

i wrote below code to change price ,but unable to change product name why so ,what to do for that



public function modifyPrice(Varien_Event_Observer $obs ){

    $item = $obs->getEvent()->getQuoteItem();

    $specialPrice = $price+10;

    // Make sure we don't have a negative
    if ($specialPrice > 0) {

  • you want to change particular product name only or for all Jan 10 '15 at 6:04
  • Please try with $item->getProduct()->setName('helllloo');.
    – michael
    Jan 11 '15 at 11:35

The problem is, that inside the cart checkout/cart/render/simple.phtml the default to get the name is:

<?php echo $this->escapeHtml($this->getProductName()) ?>

And this gets the name from the product, rather then from the item.

public function getProductName()
    if ($this->hasProductName()) {
        return $this->getData('product_name');
    return $this->getProduct()->getName();

So you need to change this to $_item->getName() then you get the set name.


Why change the name of the product on cart add? Just add a secondary product attribute and then display that in the cart item render rather than the product name.

  • 1
    And review step and order item renderer and invoice item renderer and credit memo item renderer and email templates and PDFs... I think changing the item name is actually simpler ;) Sep 8 '15 at 5:06
  • Wonderfully thought out Fabian :)
    – philwinkle
    Sep 8 '15 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.