I have my own price/product service that I need to connect to Magento. The service has a variable amount of products with very variable prices. The price can change with every request a customer makes. So it needs to be fetched every time a customer requests the page at least. But probably even in between, informing him/her of an updated price.

What is the best practice to do this in Magento 2? Do I completely drag out the price part of Magento to my API? Do I overwrite prices in the Magento database with my API? Do I fetch prices on the fly with the API or do I overwrite them after Magento sets the prices? Or ...?

At most I want to prevent being forced to maintain products and prices in two places (Magento, my database).

Thanks for any information, read-ups, books about the topic!

  • Did you implement this feature? If yes could you share the details.
    – Mukesh
    Jun 1, 2022 at 14:38

4 Answers 4


This is just a part of a part of an idea.
For the product view pages and the cart you can simply retrieve the prices from your external source using the vent catalog_product_get_final_price.
But if you have a lot of products you might get into performance problems.

But this approach won't work for listing products.
The product prices are indexed in catalog_product_index_price.
If you have a lot of discount rules and a lot of tier prices I have no idea how you can achieve this, but if you have just simple prices, you can try to rewrite the method \Magento\Catalog\Model\ResourceModel\Product::_productLimitationPrice and retrieve your prices from the third party for the current collection.

but again, if you have a lot of products, this will end up in performance issues.

  • Sorry I hardly get your post, it is too detailed already. I'm just a magento beginner. Why does one thing do not work for the other? A product should have one base price, not? So using this as an entry point should work. But probably magento works in other ways (I don't understand yet).
    – steros
    Jul 19, 2016 at 12:10

I would highly recommend a cron based or periodical price fetching of prices from custom table instead of pulling the prices from api, as there would some cases where you may fail to fetch prices like connectivity issues.This would also be reliable and will not have performance issues.It should be something like magento updates currency values.

There are other cases to consider to draw a complete solution like

1) what is the frequency of the price changes

2) Are the products only simples

3) Do you have other promotions,tier prices etc.

Well thats just an idea to start with

  • 1) the frequency is random for a random number of prices 2) what is a simple product? 3) yes there might be tier prices in the future like order 3 for the price of two I don't think that a periodical price fetching via would work. You would have to fetch very often in very short times. Also the number of prices can go into millions easily due to several multiplying factors.
    – steros
    Jul 19, 2016 at 12:01

If the prices are essentially 'live' then a realistic option may be to remove prices from the catalog listings (category pages, search results etc) and only show them on the product pages. Here they could be pulled asynchronously using Javascript and applied to the basket directly if a customer wishes to buy. This would then 'lock in' that price, if this is the desired behavior?

In addition, a server-side technology such as Node.js could be used to achieve real-time price updates on the product pages. Of course, there's nothing to stop this same approach being rolled out to the catalog pages too, but this would involve significantly more complex development.

Without understanding the whole problem I can't be more specific, but hopefully this at least gives you some ideas.

  • Yes prices are basically 'live'. At most I would want magento to store prices the customer bought at. But even those historical prices might come from my api and in magento there is just a link to the historic price. But I have no idea if magento is even remotely ready for this. I could probably give more details if you point me to any direction.
    – steros
    Jul 19, 2016 at 12:00
  • @4485670 This level of integration is something I have worked on previously, so it's certainly possible; but of course what's achievable depends on your budget and schedule, and the skills you can deploy to the project.
    – James
    Jul 20, 2016 at 10:29

What about:

Use fast api to show product on frontend (direct frontend). Because customer change price regularly if save price in table catalog_product you will meet problem about performance. Use it directly on frontend.

When a finally price confirmed. save price for that product. So other part will follow original Magento process.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.