我想覆盖product.js文件以在某些函数中添加一些额外的值。我已将文件从js/mage/adminhtml/product.js复制到我的文件夹,如js/myfolder/myproduct.js。如何才能我尝试使用该文件的功能,但它对我不起作用。当我更改对象名称时,它不会显示任何错误,但什么也没有发生 (Products.Gallery = Class.create()
原始是 Product.Gallery = Class.create();)。
谁能告诉我如何使用myproduct的所有功能而不与原有功能冲突。
谢谢
最佳答案
假设您要覆盖 function loadImage
来自js/mage/adminhtml/product.js
在产品编辑页面。
创建您的自定义 js:
js/myfolder/myproduct.js
:
Product.Gallery.addMethods({
loadImage : function(file) {
alert('hi there');
var image = this.getImageByFile(file);
this.getFileElement(file, 'cell-image img').src = image.url;
this.getFileElement(file, 'cell-image img').show();
this.getFileElement(file, 'cell-image .place-holder').hide();
}
});
引用:http://prototypejs.org/learn/class-inheritance.html
然后在布局 xml 中添加自定义 js:
<adminhtml_catalog_product_edit>
<reference name="head">
<action method="addJs"><script>myfolder/myproduct.js</script></action>
</reference>
</adminhtml_catalog_product_edit>
使用此方法,function loadImage
仅当您包含 js/myfolder/myproduct.js
时才会被覆盖.
js/myfolder/myproduct.js
包含在 js/mage/adminhtml/product.js
之后(尽管默认情况下是这样,因为 js/mage/adminhtml/product.js
包含在 <default>
标签中)
关于magento - 如何在magento中覆盖product.js文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13379034/