How to update the price for a specific store view via code?

Created by Esther Nguyen, Modified on Tue, 01 Mar 2022 at 09:33 AM by Esther Nguyen

QUESTION:

Our prices get pushed to us from a 3rd party system and we update them via code, I wonder if there is a specific function I can use to update the price for a specific store view via code?


ANSWER:

If you want to update the price per store view via code, you can use the function addAttributeUpdate($attrCode, $value, $scope)


For example: 

$product = $productRepository->getById($productId);

$product->addAttributeUpdate('price', 150000, $storeId1);

$product->addAttributeUpdate('price', 25, $storeId2);


Then, kindly remember to reindex the products that have just been updated.


If you need any further assistance, please feel free to contact us. We'd be happy to support you!


Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article