在magento中设置可配置下拉列表的默认值

时间:2014-07-24 12:17:08

标签: javascript php magento configurable-product

我有一个带有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 个答案:

答案 0 :(得分:0)

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

点击进行修改,然后选择NoValues required.

希望它能奏效。

JQuery默认选择第一个值是 -

jQuery('#attribute135>option:eq(1)').attr('selected', true);

答案 1 :(得分: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>

它显示&#39; Choose an Option...&#39;作为默认值

您可以像下面一样更改它,只需选择选择中的第一个真实元素:

$$('#attribute525 option')[1].selected = true;

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

答案 2 :(得分:0)

如果您有2个以上的选项(但上面描述的是1选项和3个选项),这可能会变得棘手,颜色和大小说。假设Color是第一个选项,一旦选择了Color,将更新Size的选择。

例如,你有一件红色尺码(S,L)和蓝色尺码(M,L)的衬衫,一旦你选择了蓝色,Magento会观察事件&#39; onChange&#39;选择Color选项并将Size选项更新为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]。删除&#34;选择一个选项..&#34;

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

答案 3 :(得分: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
});