I want to disable product for admin store means product should be disable for all store/website.
I am trying to do something like this but product disable for default store only:
$productRepository = $objectManager->get('\Magento\Catalog\Api\ProductRepositoryInterface');
$productObj = $productRepository->get('sku');
$productObj->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
$productRepository->save($productObj);
I have also tried to pass global store id i.e. 0 like this but it is also disable only default store.
$productRepository = $objectManager->get('\Magento\Catalog\Api\ProductRepositoryInterface');
$productObj = $productRepository->get('sku',true,0,true);
$productObj->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
$productRepository->save($productObj);
Can anyone help? Thanks in advance 🙂
Best Answer
You can use product action class instead of using product repository and load for each product.
Refer what updateAttributes function does git
I have not tested this code but hope this works for you.