我有一个带3个选项的可配置产品-下面是产品页面上的下拉菜单。
Bundle Deals
* Required Fields
Choose an Option...
- Single Product £10
- 5 Product Bundle £50
- 10 Product Bundle £100
页面加载的默认值是£10.00
,但如果我点击"添加到购物车",它会标记为-* Required Fields
&系统会提示用户从下拉列表中选择一个选项。
默认情况下,我希望以-Single Product £10
作为默认值加载下拉菜单。
希望这一切都有意义?我在Magento 1.9 CE版本中找不到这个功能,我正在使用
最终编辑>>感谢大家的帮助-得到了修复-非常高兴!访问链接类似于这里的建议,但代码中的某些内容似乎对我有效
http://iamvikram.com/magento-remove-choose-an-option-from-configurable-products-dropdown/
已发送感谢邮件:(
在本地中复制以下文件
/app/design/frontend/default/mytheme/template/catalog/product/view/type/options/configurable.phtml
<select name="super_attribute[<?php echo $_attribute->getAttributeId() ?>]" id="attribute<?php echo $_attribute->getAttributeId() ?>" class="required-entry super-attribute-select">
<option><?php echo $this->__('Choose an Option...') ?></option>
</select>
它显示"Choose an Option...
"作为默认值
你可以像下面这样更改,只需在你的选择中选择第一个真正的元素:
$$('#attribute525 option')[1].selected = true;
请查看您的属性。以上只是一个例子。
在您的magento管理员中导航到Catalog->Attributes->Manage Attributes
并搜索您的属性。
点击编辑并选择No
至Values required.
希望它能起作用。
JQuery默认选择第一个值为-
jQuery('#attribute135>option:eq(1)').attr('selected', true);
如果你有2个以上的选项,这可能会变得很棘手(这很令人困惑,但你上面描述的是1个选项有3个选项(,Color and Size说。假设"颜色"是第一个选项,则"大小"的选择将在选择"颜色"后更新。
例如,您有一件红色尺码(S,L(和蓝色尺码(M,L(的衬衫,一旦您选择蓝色,Magento就会观察颜色选项的事件"onChange",并将尺码选项更新为M,L。
这就是我在PrototypeJS:中正确完成它的方法
<script type='text/javascript>
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
document.observe('dom:loaded', function() {
var el = $('attribute<?php echo $_attribute->getAttributeId() ?>');
el.selectedIndex = 1;
el[0].remove();
if ("createEvent" in document) {
var ev = document.createEvent("HTMLEvents");
ev.initEvent("change", false, true);
el.dispatchEvent(ev);
} else {
el.fireEvent("onchange");
}
</script>
在configurable.phtml
中,请注意fireEvent/dispatchEvent。el[0].remove将取消"选择选项..">
这是我所知道的中侵入性最小的方法
Open app'design'frontend'[your package]'[your theme]'template'catalog'product'view'type'options'configurable.phtml
现在添加以下java脚本代码后:-
var spConfig = new Product.Config(<?php echo $this->getJsonConfig() ?>);
function fireEvent(element,event){
if (document.createEventObject){
// dispatch for IE
var evt = document.createEventObject();
return element.fireEvent('on'+event,evt)
}
else{
// dispatch for firefox + others
var evt = document.createEvent("HTMLEvents");
evt.initEvent(event, true, true ); // event type,bubbling,cancelable
return !element.dispatchEvent(evt);
}
}
Event.observe(window, 'load', function() {
spConfig.settings[0].selectedIndex = 1;
obj = spConfig.settings[0]; // this grabs the first select item
Event.observe(obj,'change',function(){});
fireEvent(obj,'change'); // this simulates selecting the first option, which triggers
spConfig.settings[1].selectedIndex = 1; // this selects the first option of the second attribute drop menu
});