0

EDIT: SOLVED

I had to override this method from Mage_Checkout_Block_Cart_Item_Renderer to use $this->getItem()->getName() instead of $this->getProduct()->getName().

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

How can I change name of the product that I am creating here in Observer.php checkout_cart_product_add_after event so that I see it in cart view.

I tried setName() and setData to change the name, but it didn't work.

I want to change name of $exampleItem, changing price works, but changing name doesn't.

class Test_Example_Model_Observer
{
    public function cartProductAddAfter($observer)
    {
        $product = $observer->getEvent()->getQuoteItem(); // get product that gets added to cart
        $exampleQty = $product->getQtyToAdd(); // get quantity of added product

        $exampleProduct = Mage::getModel('catalog/product')->loadByAttribute('sku', 'EXAMPLE'); // get the example product
        $exampleToAdd = $exampleProduct->load($exampleProduct->getId()); // load the example product

        $quote = Mage::getSingleton('checkout/session')->getQuote(); // get quote
        $exampleItem = $quote->addProduct($exampleToAdd, $exampleQty); // add example product to quote matching quantity of the normal product
        $exampleItem->setCustomPrice(444);
        $exampleItem->setOriginalCustomPrice(444);
        $quote->save(); // save quote
        }
    }
2

1 Answer 1

0

I had to override this method from Mage_Checkout_Block_Cart_Item_Renderer to use $this->getItem()->getName() instead of $this->getProduct()->getName().

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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