Magento - Which type of Price to apply a new discount to?
I'm writing a Magento extension that applies a new kind of discount to products based on an hourly schedule. I'd like the discount to apply to the final price after all other discounts (tier price, special price etc.) have been applied.
Which property of a Product object holds this final price? is it getFinalPri开发者_如何学JAVAce()? getCalculatedFinalPrice()? Something else?
Note: I thought of "piggybacking" Catalog Price Rules for my purposes but I realized that won't work because these work on a daily schedule and I need to schedule hourly.
getFinalPrice() is the price the user sees in their cart. If this has been set explicitly on the product model, it will return that value. Otherwise it returns the result of the product's price model method getFinalPrice().
The price model will check to see if the product has a calculated_final_price property set. If not, it will apply tier pricing then special pricing then set the final price on the product. It will then dispatch an event giving you an opportunity to change the final price. Finally, it will apply any prices for custom options on the product.
The best way to do what your are trying to do would probably be to hook into the catalog_product_get_final_price event and set the final price of the product based on the hour at that time. So in your config, set up an event handler for the catalog_product_get_final_price event. Your observer will have access to the $this->getProduct() and the $this->getQty() where you can update the price.
精彩评论