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

Created by Esther Nguyen, Modified on Mon, 6 Apr at 11:30 AM by Support Agent

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.


Learn more about us:


BSS Commerce is a trusted Magento 2 extensions provider with 14+ years of experience, serving 75,000+ customers worldwide. We are an Adobe Commerce Solution Bronze Partner and a Select Magento Extensions Builder, reinforcing our expertise in the Magento ecosystem.


We specialize in developing 150+ high-quality Magento 2 extensions that enhance functionality, improve user experience, and support scalable growth. Our reputation is built on long-term partnerships, positive feedback, and proven performance-driven solutions.


Browse for more at: https://bsscommerce.com/magento-2-extensions.html 


Ready to explore our top tier extensions:



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 at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article