I try set new sku using catalog_product_save_after
event, its continuously run this observer, But Not save the sku value.
events.xml:
<event name="catalog_product_save_after">
<observer name="my_custom_product_save_observer" instance="Vendor\module\Observer\Productsaveafter" />
</event>
Code:
<?php
namespace Vendor\Module\Observer;
use Magento\Framework\Event\ObserverInterface;
class Productsaveafter implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$_product = $observer->getProduct(); // you will get product object
$_sku=$_product->getSku(); // for sku
$this->logger->addDebug($_sku);
$_product->setSku("testNew1");
$_product->save();
}
}
Suggest Me, Why Its Not saved Sku value in magento 2.