Skip to main content
added 3 characters in body
Source Link
tanu
  • 22
  • 5

I want to add something with the product name dynamically while adding intoto the cart. Each product have different concatenation with product name. And that product name should be updated on everywhere like cart page, checkout, email, invoice, in sales grid etc. I have followed the step from below link. But product name has been updated in whole quote items not only the last added item. Magento 2 change productname adding to cart

namespace vendor\modulename\Plugin\Quote\Model\Quote;


class Item 

{
   public function afterSetProduct(
     \Magento\Quote\Model\Quote\Item $subject,
      $result
   ){

      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
      $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $product_Id = $cookieManager->getCookie('proid');
    $productId =  $subject->getProductId();
    if($productId == $product_Id){
     $subject->setName($product_name);
     return $subject;
    }
}

}

For minicartmini-cart

namespace vendor\modulename\Plugin\Checkout\CustomerData;

 class DefaultItem    
 {

    public function aroundGetItemData(
     \Magento\Checkout\CustomerData\AbstractItem $subject,
        \Closure $proceed,
        \Magento\Quote\Model\Quote\Item $item
    ){
        
         $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');
        $logger->info('text message11212 default');
        $data = $proceed($item);
        if($proceed($item)['product_id'] == $pro_id){       
         $data['product_name'] = $product_name;
        }else{
            $data['product_name'] = $data['product_name'];
        }       
        return $data;    
    }
}

For cart page

namespace vendor\modulename\Plugin\Checkout\Block\Cart\Item;

class Renderer

{

    public function afterGetProductName(

         \Magento\Checkout\Block\Cart\Item\Renderer $subject,
        $result
    ){

        $ $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');       
        return $product_name;
    }
 }

I want to add something with product name dynamically while adding into the cart. Each product have different concatenation with product name. And that product name should be updated on everywhere like cart page, checkout, email, invoice, in sales grid etc. I have followed the step from below link. But product name has been updated in whole quote items not only the last added item. Magento 2 change productname adding to cart

namespace vendor\modulename\Plugin\Quote\Model\Quote;


class Item 

{
   public function afterSetProduct(
     \Magento\Quote\Model\Quote\Item $subject,
      $result
   ){

      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
      $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $product_Id = $cookieManager->getCookie('proid');
    $productId =  $subject->getProductId();
    if($productId == $product_Id){
     $subject->setName($product_name);
     return $subject;
    }
}

}

For minicart

namespace vendor\modulename\Plugin\Checkout\CustomerData;

 class DefaultItem    
 {

    public function aroundGetItemData(
     \Magento\Checkout\CustomerData\AbstractItem $subject,
        \Closure $proceed,
        \Magento\Quote\Model\Quote\Item $item
    ){
        
         $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');
        $logger->info('text message11212 default');
        $data = $proceed($item);
        if($proceed($item)['product_id'] == $pro_id){       
         $data['product_name'] = $product_name;
        }else{
            $data['product_name'] = $data['product_name'];
        }       
        return $data;    
    }
}

For cart page

namespace vendor\modulename\Plugin\Checkout\Block\Cart\Item;

class Renderer

{

    public function afterGetProductName(

         \Magento\Checkout\Block\Cart\Item\Renderer $subject,
        $result
    ){

        $ $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');       
        return $product_name;
    }
 }

I want to add something with the product name dynamically while adding to the cart. Each product have different concatenation with product name. And that product name should be updated on everywhere like cart page, checkout, email, invoice, in sales grid etc. I have followed the step from below link. But product name has been updated in whole quote items not only the last added item. Magento 2 change productname adding to cart

namespace vendor\modulename\Plugin\Quote\Model\Quote;


class Item 

{
   public function afterSetProduct(
     \Magento\Quote\Model\Quote\Item $subject,
      $result
   ){

      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
      $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $product_Id = $cookieManager->getCookie('proid');
    $productId =  $subject->getProductId();
    if($productId == $product_Id){
     $subject->setName($product_name);
     return $subject;
    }
}

}

For mini-cart

namespace vendor\modulename\Plugin\Checkout\CustomerData;

 class DefaultItem    
 {

    public function aroundGetItemData(
     \Magento\Checkout\CustomerData\AbstractItem $subject,
        \Closure $proceed,
        \Magento\Quote\Model\Quote\Item $item
    ){
        
         $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');
        $logger->info('text message11212 default');
        $data = $proceed($item);
        if($proceed($item)['product_id'] == $pro_id){       
         $data['product_name'] = $product_name;
        }else{
            $data['product_name'] = $data['product_name'];
        }       
        return $data;    
    }
}

For cart page

namespace vendor\modulename\Plugin\Checkout\Block\Cart\Item;

class Renderer

{

    public function afterGetProductName(

         \Magento\Checkout\Block\Cart\Item\Renderer $subject,
        $result
    ){

        $ $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');       
        return $product_name;
    }
 }
Update Descriptions
Source Link
Dhiren Vasoya
  • 9.5k
  • 12
  • 35
  • 59

namespace vendor\modulename\Plugin\Checkout\CustomerData;

class DefaultItem
{

namespace vendor\modulename\Plugin\Checkout\CustomerData;

 class DefaultItem    
 {

    public function aroundGetItemData(
     \Magento\Checkout\CustomerData\AbstractItem $subject,
        \Closure $proceed,
        \Magento\Quote\Model\Quote\Item $item
    ){
        
         $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');
        $logger->info('text message11212 default');
        $data = $proceed($item);
        if($proceed($item)['product_id'] == $pro_id){       
         $data['product_name'] = $product_name;
        }else{
            $data['product_name'] = $data['product_name'];
        }       
        return $data;    
    }
}

}

For cart page

namespace vendor\modulename\Plugin\Checkout\Block\Cart\Item;

class Renderer

{

namespace vendor\modulename\Plugin\Checkout\Block\Cart\Item;

class Renderer

{

    public function afterGetProductName(

         \Magento\Checkout\Block\Cart\Item\Renderer $subject,
        $result
    ){

        $ $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');       
        return $product_name;
    }
 }

}

namespace vendor\modulename\Plugin\Checkout\CustomerData;

class DefaultItem
{

public function aroundGetItemData(
 \Magento\Checkout\CustomerData\AbstractItem $subject,
    \Closure $proceed,
    \Magento\Quote\Model\Quote\Item $item
){
    
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $pro_id = $cookieManager->getCookie('proid');
    $logger->info('text message11212 default');
    $data = $proceed($item);
    if($proceed($item)['product_id'] == $pro_id){       
     $data['product_name'] = $product_name;
    }else{
        $data['product_name'] = $data['product_name'];
    }       
    return $data;    
}

}

For cart page

namespace vendor\modulename\Plugin\Checkout\Block\Cart\Item;

class Renderer

{

public function afterGetProductName(

     \Magento\Checkout\Block\Cart\Item\Renderer $subject,
    $result
){

    $ $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $pro_id = $cookieManager->getCookie('proid');       
    return $product_name;
}

}

namespace vendor\modulename\Plugin\Checkout\CustomerData;

 class DefaultItem    
 {

    public function aroundGetItemData(
     \Magento\Checkout\CustomerData\AbstractItem $subject,
        \Closure $proceed,
        \Magento\Quote\Model\Quote\Item $item
    ){
        
         $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');
        $logger->info('text message11212 default');
        $data = $proceed($item);
        if($proceed($item)['product_id'] == $pro_id){       
         $data['product_name'] = $product_name;
        }else{
            $data['product_name'] = $data['product_name'];
        }       
        return $data;    
    }
}

For cart page

namespace vendor\modulename\Plugin\Checkout\Block\Cart\Item;

class Renderer

{

    public function afterGetProductName(

         \Magento\Checkout\Block\Cart\Item\Renderer $subject,
        $result
    ){

        $ $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
        $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
        $product_name = $cookieManager->getCookie('proname');
        $pro_id = $cookieManager->getCookie('proid');       
        return $product_name;
    }
 }
added 2252 characters in body
Source Link
tanu
  • 22
  • 5

I want to add something with product name dynamically while adding into the cart. Each product have different concatenation with product name. And that product name should be updated on everywhere like cart page, checkout, email, invoice, in sales grid etc. I have followed the step from below link. But product name has been updated in whole quote items not only the last added item. Magento 2 change productname adding to cart

namespace vendor\modulename\Plugin\Quote\Model\Quote;


class Item 

{
   public function afterSetProduct(
     \Magento\Quote\Model\Quote\Item $subject,
      $result
   ){

      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
      $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $product_Id = $cookieManager->getCookie('proid');
    $productId =  $subject->getProductId();
    if($productId == $product_Id){
     $subject->setName($product_name);
     return $subject;
    }
}

}

For minicart

namespace vendor\modulename\Plugin\Checkout\CustomerData;

class DefaultItem
{

public function aroundGetItemData(
 \Magento\Checkout\CustomerData\AbstractItem $subject,
    \Closure $proceed,
    \Magento\Quote\Model\Quote\Item $item
){
    
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $pro_id = $cookieManager->getCookie('proid');
    $logger->info('text message11212 default');
    $data = $proceed($item);
    if($proceed($item)['product_id'] == $pro_id){       
     $data['product_name'] = $product_name;
    }else{
        $data['product_name'] = $data['product_name'];
    }       
    return $data;    
}

}

For cart page

namespace vendor\modulename\Plugin\Checkout\Block\Cart\Item;

class Renderer

{

public function afterGetProductName(

     \Magento\Checkout\Block\Cart\Item\Renderer $subject,
    $result
){

    $ $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $pro_id = $cookieManager->getCookie('proid');       
    return $product_name;
}

}

I want to add something with product name dynamically while adding into the cart. Each product have different concatenation with product name. And that product name should be updated on everywhere like cart page, checkout, email, invoice, in sales grid etc. I have followed the step from below link. But product name has been updated in whole quote items not only the last added item. Magento 2 change productname adding to cart

I want to add something with product name dynamically while adding into the cart. Each product have different concatenation with product name. And that product name should be updated on everywhere like cart page, checkout, email, invoice, in sales grid etc. I have followed the step from below link. But product name has been updated in whole quote items not only the last added item. Magento 2 change productname adding to cart

namespace vendor\modulename\Plugin\Quote\Model\Quote;


class Item 

{
   public function afterSetProduct(
     \Magento\Quote\Model\Quote\Item $subject,
      $result
   ){

      $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
      $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $product_Id = $cookieManager->getCookie('proid');
    $productId =  $subject->getProductId();
    if($productId == $product_Id){
     $subject->setName($product_name);
     return $subject;
    }
}

}

For minicart

namespace vendor\modulename\Plugin\Checkout\CustomerData;

class DefaultItem
{

public function aroundGetItemData(
 \Magento\Checkout\CustomerData\AbstractItem $subject,
    \Closure $proceed,
    \Magento\Quote\Model\Quote\Item $item
){
    
     $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $pro_id = $cookieManager->getCookie('proid');
    $logger->info('text message11212 default');
    $data = $proceed($item);
    if($proceed($item)['product_id'] == $pro_id){       
     $data['product_name'] = $product_name;
    }else{
        $data['product_name'] = $data['product_name'];
    }       
    return $data;    
}

}

For cart page

namespace vendor\modulename\Plugin\Checkout\Block\Cart\Item;

class Renderer

{

public function afterGetProductName(

     \Magento\Checkout\Block\Cart\Item\Renderer $subject,
    $result
){

    $ $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $cookieManager = $objectManager->get('Magento\Framework\Stdlib\CookieManagerInterface');
    $product_name = $cookieManager->getCookie('proname');
    $pro_id = $cookieManager->getCookie('proid');       
    return $product_name;
}

}

Update Descriptions
Source Link
Dhiren Vasoya
  • 9.5k
  • 12
  • 35
  • 59
Loading
Source Link
tanu
  • 22
  • 5
Loading