I have an existing product with a multi-select attribute and I need to update that multi-select attribute update programmatically. So how can I Update that option selected through programmatically? In a below ImageI need to make Label 1 option selected through an update.
1 Answer
I found this answer finally, I tried for single product only and tried in root file in Magento 2.3.3, and used it in my project, and it's working properly. May this one help those ones who seeking help as this problem
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
//Passed option value which you want to selected
$value = [5729,5730];
$sku = '24-MB04';
//$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_product = $obj->create('\Magento\Catalog\Api\ProductRepositoryInterface')->get($sku,true, 0, true);
$_product->setDemofilter($value);
$_product->save($_product);
?>