How to do this? I am using checkout_cart_product_add_after
event.
EDIT:
After I did it like this
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="sales_quote_item_set_product">
<observer name="changesku" instance="Vdndor\ProductChanger\Observer\ChangeSKU" />
</event>
</config>
and Observer as
<?php
namespace Vendor\ProductChanger\Observer;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;
class ChangeSKU implements ObserverInterface
{
/**
* Below is the method that will fire whenever the event runs!
*
* @param Observer $observer
*/
public function execute(Observer $observer)
{
$event = $observer->getEvent();
$quoteItem = $event->getQuoteItem();
$quoteItem->setSKU('SAMPLE');
$quoteItem->setName("SAMPLE NAME");
}
}
But still it is changing the SKU and NAME in quote_item table perfectly when I add it to cart. But whenever I go the cart page or I place the order the old NAME and SKU are saving back. any help?