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 ? Apr 25 '19 at 14:04
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
    Apr 25 '19 at 14:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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