skip to Main Content

I need to change the productname visible for the customer after adding it to the cart. Also it should show on invoice, order email and everything else visible for the customer.

I made an extension with observer checkout_cart_product_add_after

   $item = $observer->getEvent()->getData('quote_item');            
   $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
   $item->getProduct()->setName('this is the productname');
   $item->getProduct()->setIsSuperMode(true);

But the original productname is still visible on minicart, cartpage, etc.

The ‘add to cart message’ is the only place where the new changed productname is visible. What should I change?

2

Answers


  1. Chosen as BEST ANSWER

    Found the solutions myself.

    Hope this helps anyone searching for it, or if you have comments how it could be done a better way, please let me know.

    Created a plugin with this code:

    class Item 
    {
        public function afterSetProduct(
            MagentoQuoteModelQuoteItem $subject,
            $result
        ){
            $subject->setName('New Name');
        }
    }
    

    So this sets a new name to the quote item, visible in everything, excepting cart and mini cart.

    Now I have got my new productname visible in: - Added to cart message - Quote-item, even in admin and invoices

    But not in: - Mini cart - Cartpage

    For the cart page:

    I changed output of function getProduct in MagentoCheckoutBlockCartItemRenderer:

    class Renderer
    {
        public function afterGetProductName(
             MagentoCheckoutBlockCartItemRenderer $subject,
            $result
        ){
            return 'this is the name';
        }
    }
    

    For minicart, also with plugin:

    class DefaultItem
    {
        public function aroundGetItemData(
         MagentoCheckoutCustomerDataAbstractItem $subject,
            Closure $proceed,
            MagentoQuoteModelQuoteItem $item
        ){
            $data = $proceed($item);
            $data['product_name'] = 'this is the productname';
            return $data;    
    }
    

  2. use this event "sales_quote_item_set_product"
    and in observer set name like this:

    /* For minicart and cart */
    $item->getProduct()->setName('Custom Name');
    /* For checkout page cart items */
    $item->setName('Custom  Name');
    $item->getProduct()->setIsSuperMode(true);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search