Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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 = \Magento\Framework\App\ObjectManager::getInstance();

    $productAction = $objectManager->get('Magento\Catalog\Model\Product\Action');

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

        $collection = $this->_productCollectionFactory->create();
        $collection->addStoreFilter($storeId);
        $collection->addAttributeToFilter('status', ['eq' => \Magento\Catalog\Model\Product\Attribute\Source\Status::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 = \Magento\Framework\App\ObjectManager::getInstance();

                $productAction->getResource()->updateAttributes(
                    [
                        $product->getId(),
                    ],
                    [
                        'status' => \Magento\Catalog\Model\Product\Attribute\Source\Status::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'));
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top