Question

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()];

    }

}
Was it helpful?

Solution

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;
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top