2

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

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

1 Answer 1

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

?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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