I'm trying to update product details by this code -

public function updateProducts(){
            $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // instance of object manager
            $product = $objectManager->create('\Magento\Catalog\Model\Product');
            $product->setSku('sku'); // Set your sku here
            $product->setName('name'); // Name of Product
            $product->setStatus(1); // Status on product enabled/ disabled 1/0
            $product->setWeight(10); // weight of product
            $product->setPrice(100); // price of product

Some of the values are updated like Sku and Price but Name and others are not. I tried to update custom attributes also but it results same. For example - case_back updated but case_material not.

I found out that fields with Global scope are updating but Store View scope are not even though I set storeId also.

So how can I update all of the details of product?


You can use the updateAttribute function to update the existing product attribute easily with storewise also.

Here is the sample Code:

$updateAttributes['case_back'] = "Black";
$updateAttributes['case_material'] = "Silver";
$action = objectManager->create('\Magento\Catalog\Model\ResourceModel\Product\Action');
$action->updateAttributes([3734], $updateAttributes, $storeId);
  • How can I update product for whole website with every store Jul 27 '20 at 9:32
  • Get all store ids and loop the action and update the products. Jul 29 '20 at 2:17

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.