如何在magento中覆盖product.js文件 [英] How to override product.js file in magento
问题描述
我想覆盖product.js文件以在某些功能中添加一些额外的值,我已经将该文件从js/mage/adminhtml/product.js复制到了js/myfolder/myproduct.js之类的文件夹中.我尝试使用文件的功能,但对我不起作用.当我更改对象名称时,它不会显示任何错误,但是什么也没发生.(Products.Gallery = Class.create()
原始是Product.Gallery = Class.create();).
谁能告诉我如何使用myproduct的所有功能而又不会与原始功能发生冲突.
I want to override the product.js file to add some extra values in some functions.I have copy the file from js/mage/adminhtml/product.js to my folder like js/myfolder/myproduct.js.How can i use the functions of the file as i try and its not working for me .When i change the object name than it will show no error but nothing happend (Products.Gallery = Class.create()
orginal is Product.Gallery = Class.create();).
Can anyone tell me how to use all the functions of myproduct without conflicting of original funcitons.
谢谢
推荐答案
假设您要在产品编辑页面的js/mage/adminhtml/product.js
中覆盖function loadImage
.
Let's say you're going to override function loadImage
from js/mage/adminhtml/product.js
in product edit page.
创建自定义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:
Then in your layout xml add your custom js:
<adminhtml_catalog_product_edit>
<reference name="head">
<action method="addJs"><script>myfolder/myproduct.js</script></action>
</reference>
</adminhtml_catalog_product_edit>
使用此方法,仅当包含js/myfolder/myproduct.js
时,function loadImage
才会被覆盖.
Using this method, function loadImage
will be overridden only if you include your js/myfolder/myproduct.js
.
PS:
确保在js/mage/adminhtml/product.js
之后包含js/myfolder/myproduct.js
(尽管由于<default>
标记中包含js/mage/adminhtml/product.js
,所以默认情况下就像这样)
PS:
Make sure js/myfolder/myproduct.js
is included after js/mage/adminhtml/product.js
(though it is like that by default since js/mage/adminhtml/product.js
included in <default>
tag)
这篇关于如何在magento中覆盖product.js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!