Magento – Add Special Price to Product Programmatically

productspecial-price

I'm looking to extend the special price functionality in Magento and add some custom logic for when special prices should apply to products.

What is the most efficient way of doing this? Currently, there are observers for whenever the product is loaded (or whenever collections are loaded) and then the module checks if special price applies.

Obviously this way is very slow, what is a more effective way of doing this, possibly when the product itself is being pulled from the DB.

Any thoughts?

Best Answer

In the observer, do you save the special price on the product?

For example:

$product->setSpecialPrice(123);

If so, then I would probably make a cronjob and run it each night. So every night you just run through all your products, if the price rules applies and are not already set, you just update the products special price and save it.

And if you want to run the script another time, just make a shell script and activate it that way at will.