Magento - 对哪种类型的价格应用新折扣?
我正在编写一个 Magento 扩展,它根据每小时的时间表对产品应用一种新的折扣。我希望在应用所有其他折扣(等级价格、特价等)后将折扣应用于最终价格。
Product 对象的哪个属性保存这个最终价格?是 getFinalPrice() 吗? getCalculatedFinalPrice()?还有别的事吗?
注意:出于我的目的,我想到了“搭载”目录价格规则,但我意识到这行不通,因为这些规则按每日计划工作,而我需要每小时安排一次。
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 getFinalPrice()? 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
getFinalPrice() 是用户在购物车中看到的价格。如果已在产品型号上明确设置,它将返回该值。否则,它返回产品价格模型方法 getFinalPrice() 的结果。
价格模型将检查产品是否设置了calculated_final_price属性。如果没有,它将应用分级定价,然后应用特殊定价,然后设置产品的最终价格。然后它会发送一个事件,让您有机会更改最终价格。最后,它将应用产品上自定义选项的任何价格。
完成您想要做的事情的最佳方法可能是挂钩catalog_product_get_final_price 事件并根据当时的小时设置产品的最终价格。因此,在您的配置中,为catalog_product_get_final_price 事件设置一个事件处理程序。您的观察者将可以访问 $this->getProduct() 和 $this->getQty() ,您可以在其中更新价格。
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.