1

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. enter image description here

  • Do you mean create product attribute with custom source model? – Dominic Xigen Jul 2 at 18:30
  • No Product and attribute is already created, Just I want to update that multi-select attribute part through programatically – RAKESH ROY Jul 3 at 3:21
0

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

?>
| improve this answer | |

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.