TransWikia.com

Disable products per store

Magento Asked on December 30, 2021

My store looks like the following;

1 Website, with 2 Stores, with each 1 Store view.

I use these 2 Stores, because we sell products in 2 different countries.
For these stores I want to share my product, but I want to define what products are availbile trough each store.

I try to disable products inside a store, but that does not work.
Then the product is also disabled inside the other store.

How can I disable products per store?

2 Answers

Magento 2 Disable simple products per store as follows.

// Roshan!
    $storeIds = [0, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25];

    $objectManager = MagentoFrameworkAppObjectManager::getInstance();

    $productAction = $objectManager->get('MagentoCatalogModelProductAction');

    foreach ($storeIds as $storeId) {
        $this->logger->addInfo(__('Disabling Products...'));

        $collection = $this->_productCollectionFactory->create();
        $collection->addStoreFilter($storeId);
        $collection->addAttributeToFilter('status', ['eq' => MagentoCatalogModelProductAttributeSourceStatus::STATUS_ENABLED]);
        $collection->addAttributeToFilter('type_id', ['eq' => 'simple']);
        $collection->addAttributeToFilter('price', ['gteq' => 0.00]);

        $collection->joinField('manages_stock', 'cataloginventory_stock_item', 'use_config_manage_stock', 'product_id=entity_id', '{{table}}.use_config_manage_stock=1 or {{table}}.manage_stock=1');

        $collection->addAttributeToFilter('thumbnail', ['neq' => 'no_selection'])
            ->addAttributeToFilter('thumbnail', ['neq' => ''])
            ->addAttributeToFilter('thumbnail', ['neq' => null]);

        $i = 0;

        foreach ($collection as $product) {
            echo "n".'Disabling Products..'.$product->getSku().' Store: '.$storeId;

            $this->logger->addInfo(__("n".$product->getSku()));

            try { // Roshan!
                $objectManager = MagentoFrameworkAppObjectManager::getInstance();

                $productAction->getResource()->updateAttributes(
                    [
                        $product->getId(),
                    ],
                    [
                        'status' => MagentoCatalogModelProductAttributeSourceStatus::STATUS_DISABLED,
                    ],
                    $storeId
                );

                $this->logger->addInfo(__('Disabled success ---- Product sku:'.$product->getSku().' StoreID: '.$storeId));
                ++$i;
            } catch (Exception $e) {
                $this->logger->addInfo(__('Disable failure ---- Product sku:'.$product->getSku().' StoreID: '.$storeId.' error Message : '.$e->getMessage()));
            }
        }

        $this->logger->addInfo(__('Completed Disabling Products... Disabled '.$i.' products'));
    }

Answered by Yo Yo Roshan on December 30, 2021

You can disable a product per store view, but you should use the visibility attribute, since you can set that one on store view level.

Answered by Ruud N. on December 30, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP