I have created a script file to update the multi select attribute for the products
here is my code
<?php
error_reporting(E_ALL);
use \Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$resource = $obj->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$sql = "SELECT `e`.* FROM `catalog_product_entity` AS `e` WHERE (`e`.`attribute_set_id` = '19') limit 3";
$result = $connection->query($sql);
$resultCollection = $result->fetchAll();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
foreach($resultCollection as $item){
$productId = $item['entity_id'];
$product = $objectManager->get('Magento\Catalog\Model\ProductFactory')->create()->load($productId);
$attrCode = 'pod_paper_size';
$sourceModel = $product->getResource()->getAttribute('pod_paper_size')->getSource();
$valuesText = explode(',', 'Extra_Small,Medium,Small,Large');
$valuesIds = array_map(array($sourceModel, 'getOptionId'), $valuesText);
$product->setData('pod_paper_size', $valuesIds);
$product->setVisibility(4);
$product->save();
}
Can anyone update me what is the correct code to update the multi-select attribute value pro grammatically, Thanks in Advance!!