When I load product by below code then product name not updating. what problem in my code?

foreach ($catval as $p) { $model = $p->MODEL; $NAME = $p->NAME; $product = $objectManager->create('\Magento\Catalog\Model\Product'); $productId = $product->getIdBySku($model); if (false !== $productId) { $product = $objectManager->create('\Magento\Catalog\Model\Product')->load($productId); $product->setName($NAME); $product->save(); } }

1 Answer 1


try use code

foreach ($catval as $p) {
    $model          = $p->MODEL;
    $NAME           = $p->NAME;
    $productModel   = $objectManager->create('\Magento\Catalog\Model\Product');
    $productId      = (int)$productModel->getIdBySku($model);

    if ($productId) {
      $product = $productModel->load($productId);

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.