0

How can I update storeview label without removing label on the rest of the storeviews?

The code works fine for updating just 1 storeview, but it removes all other labels. Updating store 2, removes label from store 1+3+4 ??

Relevant part of code:

use \Magento\Catalog\Api\ProductAttributeRepositoryInterface;
use \Magento\Eav\Api\Data\AttributeOptionLabelInterfaceFactory;

/* .......... */


         foreach($csv as $obj){
            $attr = $this->productAttributeRepository->get('xxxxxxxx');
            $options = $attr->getOptions();
            foreach ($options as $option) {
                if ($option->getLabel() == $obj[1]) {

                    $optionLabel = $this->optionLabelFactory->create();
                    $optionLabel->setStoreId(2);
                    $optionLabel->setLabel($obj[5]);

                    $option->setStoreLabels([$optionLabel]);
                    $attr->setOptions([$option]);
                    $this->productAttributeRepository->save($attr);
                }
            }
        }

0

Your Answer

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