Question

I've met with a case. A customer placed an order with products that should be on a sale, but they are bought without a discount. As it turned out, he placed the order when catalogrule_apply_all cronjob was applying catalog price rules. It looks like a normal behaviour of Magento, but it leads to a bad user experience.

I would like to avoid the same issues in the future, but I'm not sure in which way I will be able to do it.

Was it helpful?

Solution

I can suggest two options here. Price rules applying is related to the price index generation. Normally, the product prices on the frontend are being fetched from the price index table in order to avoid heavyweight price calculation on the fly. If the price for some product is not in the index - it will be calculated. However, this calculation will not involve the catalog price rules. So, you need to involve the catalog price rules during the price calculation. It can be achieved by extending the standard price model. Magento already has a method for price calculation including the price rules, check the \Mage_Catalog_Model_Product_Type_Price::calculatePrice method. Roughly, the approach is the following:

  • Check if the price reindex is in progress
  • If it is, call the mentioned method for the price calculation instead of getting the price from index
  • If it is not, use the standard way

It will be slower in comparison with a standard way, but the price will be correct. To avoid a huge database loading you can use this approach only for price calculation during the checkout process. In that way, customer will buy the product with the correct price but the price on the catalog pages might be outdated. Once the reindexing process is finished, the prices will be fetched from the index.

The second approach is to calculate the prices indexes before sales start but put the data somewhere else (not to the price index table). After that you will be able to replace the current price index table data with the calculated data. But ensure that the reindex process will not be started again.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top