Blogs of e-commerce

We are a web development and outsourcing agency based in Kochi, India.

How can products be assigned to multiple stores programmatically in Magento 2?

Let’s say you have a Magento multi-website/store installation and you want to assign the products of a particular category to the new store. I wrote a few lines of code to accomplish this. <?php use Magento\Framework\App\Bootstrap; require __DIR__ . '/../app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $categoryIds = [41]; // Category IDs whose products you want to assign foreach ($categoryIds as $categoryId) { $category = $objectManager->create('Magento\Catalog\Model\Category')->load($categoryId); $productCollection = $category->getProductCollection(); foreach ...

2hats Logic HelpBot