Magento -- 可配置产品的选项如何默认选中第一项
来源:互联网 发布:软件开发工资待遇 编辑:程序博客网 时间:2024/06/05 02:35
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
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 -- 可配置产品的选项如何默认选中第一项
- Magento -- 可配置产品的选项如何默认选中第一项
- 取消grideview默认选中的第一项
- Magento中 可配置产品 价格不根据选项变化
- 设置ListView默认选中第一项
- easyui Combotree默认选中第一项
- easyui combobox 默认选中第一项
- magento -- 获得可配置产品的所有子产品
- Android ListView默认选中第一项或第N项
- Magento获取可配置类型的产品方法
- ComboBox控件 ComboBoxEX 控件 ,通过SetCurSel()默认选中第一项
- IsSynchronizedWithCurrentItem 会让 ListBox 默认选中第一项
- ComboBox控件,通过SetCurSel()默认选中第一项
- jquery easyui combobox设置默认选中第一项
- 【WPF】ListBox使用DataTemplate 以及默认选中第一项Item
- angular使用ng-option。默认选中列表第一项
- magento -- 判断一个产品是否是一个可配置产品的子产品
- GridEx选中第一项的方法
- OSI七层模型与TCP/IP五层模型
- 链接器工具错误 LNK2026 XXX模块对于 SAFESEH 映像是不安全的"
- JavaScript学习笔记 isPrototypeOf和hasOwnProperty使用区别
- JZOJsenior3476.【NOIP2013初赛】整除
- SpringBoot使用JdbcTemplate案例(学习笔记)
- Magento -- 可配置产品的选项如何默认选中第一项
- 【数论 && 公式转换】HDU
- 矩阵乘法
- NOIP2017 模拟考试day1 2017.10.06
- 快速排序
- bzoj2086[Poi2010]Blocks 单调栈
- 一个简单的判断字符串所含字母是否有大写,并将所有字母改为大写的小程序
- tensorflow(1)
- 论文投稿需要注意哪些细节