覆盖/扩展 Magento 核心 javascript 文件 [英] Overriding/Extending the Magento core javascript files
问题描述
最近几天,由于一些客户的抱怨以及与我们的营销人员的讨论,我收到了更改可配置产品选项的默认行为的请求.他们要求我从选项下拉列表中删除 + $xx.xx,因为它会使客户/访客感到困惑,并且只保留可用选项而不显示价格变化.从他们的角度来看,这很公平,但从开发人员的角度来看,我认为这有点棘手.该站点正在运行 Magento CE 1.6.2,我们需要覆盖/更改的文件是/public_html/js/varien/configurable.js.我们需要更改其中的 getOptionLabel 函数,使其不显示价格变化.所以我的问题是:更改此文件而不触及核心 javascript 文件的正确 Magento 方法是什么?提前致谢.
Last days as a result of some customer complains and discussion with our marketing guys I've got a request to change the default behavior of the configurable products options. They asked me to remove the + $xx.xx from the options drop-down as it is confusing the customers/visitors and just leave the available options without displaying the price change. Fair enough from their point of view, but it is a bit tricky from developers point of view I think. The site is running Magento CE 1.6.2, and the file which we need to override/change is /public_html/js/varien/configurable.js. We need to change the getOptionLabel function in it so that it does not display the price change. So my question is: what is the right Magento way to change this file and not touch the core javascript file? Thanks in advance.
推荐答案
参见原型手册 http://prototypejs.org/doc/latest/language/Function/prototype/wrap/ 你可以包装任何对象方法,甚至在需要时调用父",这是一个伪示例:
See this from prototype manual http://prototypejs.org/doc/latest/language/Function/prototype/wrap/ you can wrap whatever object method and even call "parent" if needed and here's a pseudo sample:
//where Product.Config is the object/class you need to "override"
Product.Config.prototype.getOptionLabel = Product.Config.prototype.getOptionLabel.wrap(function(parentMethod){
//replace the original method here with your own stuff
//or call parentMethod(); if conditions don't match
});
这篇关于覆盖/扩展 Magento 核心 javascript 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!