事件观察者 - 触发事件
我想创建一个事件观察器,当购物车总重量超过 23 公斤时,我想显示消息/警报框(说实话,我想要一个事件来检查重量限制并在客户添加产品时触发警报框到购物车)。
有人可以帮我做这样一个观察者吗?
I would like to create an event observer that I want to show a message / alert box when total weight of cart surpass 23 kg (to tell the truth, I want an event to check weight limit and trigger the alert box when customer add a product to cart).
Could anybody help me to make such an observer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要任何如此复杂的内容...
您已经获得了用于写出重量的代码,请将这些代码放在一个块中,将其放在标题中(甚至是您的购物车侧边栏)并添加 IF 语句。
不要只是输入
if($weight>23) { echo "太重 - 购物车会自行爆裂!" }
在 admin 中放置一个自定义变量并将其与该变量进行比较。在该称重中,如果您更换快递公司,那么您的客户可以更新最大重量。
You don't need anything so involved...
Already you have been given the code to write the weight out, put this code in a block, put it in the header (or even your cart sidebar) and add an IF statement.
Don't just put
if($weight>23) { echo "Too Heavy - Shopping Cart is going to burst itselves!" }
put a custom variable in admin and compare it against that. In that weigh, if you change courier then your customer can update the max weight.
此链接可以帮助您:
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method
如果您有 SSH 访问权限,请 grep 'dispatchEvent' 获取所有事件的列表
This link could help you :
http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customizing_magento_using_event-observer_method
If you have SSH access, grep 'dispatchEvent' to get the list of all events