0

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

| improve this question | | | | |
0

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);
      $product->setName($NAME);
      $product->save();
    }
}
| improve this answer | | | | |

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.