1

Which approach is better and fast to update bulk product update in magento 2.3+ ? e.g i want to update 1000+ products at a time using cron job or command line

please suggest

1
  • What type of information you want to update ? Commented Apr 25, 2019 at 14:04

1 Answer 1

0
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->create('\Magento\Store\Model\StoreManagerInterface');
$storeIds = array_keys($storeManager->getStores());
$action = objectManager->create('\Magento\Catalog\Model\ResourceModel\Product\Action');
$updateAttributes['name'] = "test";
$updateAttributes['price'] = 100;
$productCollectionFactory = $objectManager->get('\Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollectionFactory->create();
$collection->addAttributeToFilter('sku', 'A960-CQ');
$collection->addAttributeToSelect('*');
foreach ($collection as $product) 
{
    foreach ($storeIds as $storeId) {
        $action->updateAttributes([$product->getId()], $updateAttributes, $storeId);
    }
}
1
  • We can use “updateAttributes” method to update Specific Attribute for product instead update all the data You can pass multiple attribute that you want to updates detail.As show price and name are pass in an array and updateAttributes will update the name and price of the product
    – mohith
    Commented Apr 25, 2019 at 14:05

Your Answer

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

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