Magento -- 可配置产品的选项如何默认选中第一项
2017-10-06 16:05
387 查看
If you ever tried to do anything with Magento configurable products view page, most likely you needed changes in /js/varien/product.js in case you wanted to manipulate dropdowns.
This will be one of the ways to do it.
Basically, what we need to do in order to make initial selection of a product is the following:
Open this file: /app/design/frontend/default/your_theme/template/catalog/product/view/type/options/configurable.phtml
Right below
add this JavaScript code:
That’s it. I hope you can find this usable, however don’t use it on production site without extensive testing.
As you can see, all prototype functions in Magento (and in general) can be added as new into already existing class.
Same way you could override existing methods in existing classes.
I have coded this feature for the purpose of this article and I’m not claiming that it is production ready. It is only for informative purposes.
This will be one of the ways to do it.
Basically, what we need to do in order to make initial selection of a product is the following:
Open this file: /app/design/frontend/default/your_theme/template/catalog/product/view/type/options/configurable.phtml
Right below
var spConfig = new Product.Config(< ?php echo $this->getJsonConfig() ?>);
add this JavaScript code:
//we create new function spConfig.setInitialState = function(dropdown_id) { //select dropdown var dropdown = $(dropdown_id); //remove empty option from dropdown so it is not selectable after initial selection dropdown[0].remove(); //change selections in dropdowns for(index = 0; index < dropdown.length; index++) { if(dropdown[index].value != "") { dropdown.selectedIndex = index; var element = dropdown; var event = 'change'; //fire events if(document.createEventObject) { var evt = document.createEventObject(); return element.fireEvent('on'+event,evt) } else { var evt = document.createEvent("HTMLEvents"); evt.initEvent(event, true, true ); return !element.dispatchEvent(evt); } } } }; <?php foreach($_attributes as $_attribute): ?> spConfig.setInitialState("attribute< ?php echo $_attribute->getAttributeId() ?>") < ?php endforeach; ?>
That’s it. I hope you can find this usable, however don’t use it on production site without extensive testing.
As you can see, all prototype functions in Magento (and in general) can be added as new into already existing class.
Same way you could override existing methods in existing classes.
I have coded this feature for the purpose of this article and I’m not claiming that it is production ready. It is only for informative purposes.
相关文章推荐
- magento -- 可配置产品的选项如何默认选中第一项
- HTML中的<select>标签如何设置默认选中的选项
- HTML中的<select>标签如何设置默认选中的选项
- magento -- 如何修改产品列表默认排序
- HTML中的<select>标签如何设置默认选中的选项
- HTML中的<select>标签如何设置默认选中的选项
- Easyui combobox如何默认选中第一项???
- HTML中的<select>标签如何设置默认选中的选项
- select标签如何设置默认选中的选项
- HTML中的<select>标签如何设置默认选中的选项
- win7中如何恢复UltraEdit的默认配置
- Android中使单选项列表框默认选中前次保存的值(即setSingleChoiceItems方法的使用)
- JComboBox默认不选中任何选项的方法
- maven 本地仓库如何配置以及如何修改默认.m2仓库位置相关
- 如何修改eclipse中@author的默认选项
- 如何启用clr enabled配置选项
- 将sublime 配置成python开发工具及如何更改IPython默认编辑器
- EF的默认映射以及如何使用Data Annotations和Fluent API配置数据库的映射
- myeclipse配置下面没有tomcat选项,如何解决
- magento - 通过如何在magento的模板中获取到产品或产品分类的instance呢谈magento的helper类机制