0

我有一个带有 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/

谢谢你的消息已邮寄:)

4

4 回答 4

0

导航到Catalog->Attributes->Manage Attributes您的 magento 管理员并搜索您的属性。

点击编辑并No选择Values required.

希望它会奏效。

JQuery默认选择第一个值是 -

jQuery('#attribute135>option:eq(1)').attr('selected', true);
于 2014-07-24T12:22:44.457 回答
0

将以下文件复制到本地

/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;

检查您的attributeid。以上只是一个例子。

于 2014-07-24T12:38:01.960 回答
0

如果您有 2 个以上的选项,这可能会变得棘手(这很令人困惑,但您上面描述的是 1 个选项和 3 个选项),颜色和大小说。假设颜色是第一个选项,一旦选择颜色,尺寸的选择就会更新。

例如,您有一件尺寸为红色 (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 将摆脱“选择一个选项..”

这是我所知道的侵入性最小的方法

于 2014-07-24T13:57:00.687 回答
0
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
});
于 2016-01-06T14:28:19.787 回答