0

I added a custom field to product module which is getting a multi-select list. When i'm using SetData to get data added to my table for specified product, it is not working.

$product = $observer->getEvent()->getProduct();

if ($product instanceof \Magento\Catalog\Model\Product) {
    $product->setData("custom_field", '1,2');
}

1 Answer 1

0
$product = $observer->getEvent()->getProduct();

if ($product instanceof \Magento\Catalog\Model\Product) {
    $product->setData("custom_field", '1,2');
    $product->save();
}
1
  • "$product->save();" it causes the observer to enter into an infinite loop, this solution is wrong !
    – Mhroauf
    Dec 5, 2020 at 10:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.