I am in need to disable a list of SKUs. For that I have created a console command, read the CSV and then setting product as disabled.

I am facing an issue that I am not able to make product disabled for global store.

Whereas my code is working fine for specific store only i.e. if I switch store, product status is disabled else it is enables.

    \Magento\Catalog\Model\ProductRepository $productRepository,

             try {
                    $product = $this->_productRepository->get(
                        true/* edit mode */,
                        0/* global store*/,
                        true/* force reload*/
                    //$product = $this->_productRepository->get($sku[0]);
                } catch (\Exception $exception) {
                    echo $exception->getMessage();exit;

Any idea what I am doing wrong ?

[Edit] I figured out the cause - in configuration for status attribute I am having scope set to website. If I set it to global and then try it is saving for default value as well.

But as I can not change the scope of attribute on production site, any idea how I can save it for default value as well even if attribute has "website" level scope.


1 Answer 1


Posting answer is anyone else running into the same issue. I was able to fix my issue by below mentioned logic instead.

                    $store_id = 0; // or 1,2,3,... ?
                    $attribute_code = 'status';
                    $value = '2';
                    $product = $this->_productRepository->get($sku[0]);
                    $product->addAttributeUpdate($attribute_code, $value, $store_id);

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.