magento -- 可配置产品的选项如何默认选中第一项

简介:

 

How to make configurable options autoselected on configurable product view page

 

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.

 

原文链接地址:http://inchoo.net/ecommerce/magento/how-to-make-configurable-options-autoselected-on-configurable-product-view-page/

 

 

目录
相关文章
|
8月前
|
API
ant.design Table组件点击一个选项框却把所有选项都选中了
ant.design Table组件点击一个选项框却把所有选项都选中了
88 0
ant.design Table组件点击一个选项框却把所有选项都选中了
html+css实战34-单选功能和默认选中
html+css实战34-单选功能和默认选中
104 0
html+css实战34-单选功能和默认选中
|
JavaScript
【mpvue】radio-group 标签组设置默认选择checked: 'true',选择了单选按钮的非默认选项,再点击其他的选择,单选按钮又会变成默认的选项
1、问题举例描述: radio-group 标签组设置默认选择checked: ‘true’,选择了单选按钮的非默认选项(场外),再点击其他的选择(手续费率),单选按钮又会变成默认的选项(场内) 默认状态如下:
384 0
【mpvue】radio-group 标签组设置默认选择checked: 'true',选择了单选按钮的非默认选项,再点击其他的选择,单选按钮又会变成默认的选项
win7,如何把文件夹和文件,视图改成平铺,默认是列表
win7,如何把文件夹和文件,视图改成平铺,默认是列表
154 0
Confluence 6 如何配置快速导航的同时查找数量
进入后台后查看快速导航的启用和可以同时查找的数量。 然后进行通过单击右上角的编辑(Edit)按钮进行编辑。   对配置进行配置,启用快速查询和可以同时使用的最大查询数量。
788 0
|
Web App开发 Java
修改Myecclipse servlet/jsp的默认模板
点击图片下载模板: 用winrar等打开myeclipse安装目录下的com.genuitec.eclipse.wizards*.jar,替换响应文件。   详细版:http://www.cnblogs.com/xdp-gacl/p/3769058.html
713 0