Magento 2 Update Product Price Programmatically– We can update product price using product object in Magento 2. Sometimes we need to update product price on run time, we can update price on website and store level using product object. Here in this tutorial, we are going to explain the one of the simplest way to update product price in Magento 2.
Magento 2 Update Product Price Programmatically Example
Let us understand how to update product price in Magento 2. Here is an example-
Example:
$storeId = '2'; //SET Store ID $productId = 190; $price = 50.20; $productFactory = $objectManager->get('\Magento\Catalog\Model\ProductFactory'); $product = $productFactory->create()->setStoreId($storeId)->load($productId); $product->setPrice($price); $product->save(); |
In the above example we have loaded product by id(190), Using object manager we have loaded product for store( store id = 2). Then we have updated price for product simply as in above example.