how to save product name dynamically
-
26-02-2021 - |
سؤال
for example i have 3 product attributes color ,size ,location.
i do not want to enter product name instead of it should save combination of color,size,location.
product name. 'red color small in new york'
i need to use observer or plugin or back end model?
<?php
namespace Vendor\Module\Plugin;
class ProductName
{
public function beforeSetName(\Magento\Catalog\Model\Product $product, $name)
{
return [$product->getColor().$product->getSize().$product->getLoc()];
}
}
المحلول
I am suggesting to use catalog_product_save_before
event.
Fire an event on this observer and set Product Name.
<?php
namespace StackExchange\Magento\Test;
use Magento\Framework\Event\ObserverInterface;
class SetProductName implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$product = $observer->getEvent()->getProduct();
$product->setData('name', $product->getData('color').$product->getData('size').$product->getData('loc'));
return $this;
}
}
لا تنتمي إلى magento.stackexchange