0

i need to add text swatch attribute value through script. I'am able to add the attribute but swatch value is not adding. Below is the code i using -

    $attributeDetails = $objectManager->create('Magento\Eav\Model\Config')->getAttribute("catalog_product", $attributeCode);
    //print_r($attributeDetails->getId()); exit();
    $attributeId = $attributeDetails->getId();
    $languageValues[0]=$label; 
    $languageValues[1]=$label;
    /* @var $attr \Magento\Eav\Model\Entity\Attribute */
    $attr = $objectManager->create('\Magento\Eav\Model\Entity\Attribute'); 
    $attr->load($attributeId); 
    $option = [];
    $option['value'][$languageValues[0]] = $languageValues;
    $attr->addData(array('option' => $option));
    $attr->save();

enter image description here

Here in image test is the value i am trying to create. Any idea how to do it? Any help would be appreciated. Thanks in advance.

Your Answer

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

Browse other questions tagged or ask your own question.