0

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 2

2

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.

5
  • Thanks for your reply. Will be the following config a better idea, 1 Website, 1 Store, 2 Store Views? Because in that case I can disable products per store view, right?
    – JGeer
    Aug 3, 2016 at 9:41
  • 1 website 2 stores and 1 store view per store would also work, since you can set the visibility in the exact same way you would with 1 website 1 store and 2 store views. It doesn't matter for this purpose.
    – Ruud N.
    Aug 3, 2016 at 10:35
  • Thanks! The only problem I face, is that we have over 100.000 products, with a lot of attributes, so that easiliy update attributes is not possible. Then I receive the Magento error, General error: 1116 Too many tables; MariaDB can only use 61 tables in a join.
    – JGeer
    Aug 3, 2016 at 11:28
  • What's your current approach to updating the attributes?
    – Ruud N.
    Aug 3, 2016 at 12:27
  • Not, I currently do not use the bulk update attribute option. I only use the status change for bulk products.
    – JGeer
    Aug 3, 2016 at 13:14
1

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'));
    }

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.