Magento,可配置产品:属性与单选按钮的同步

时间:2013-07-09 16:37:27

标签: jquery magento magento-1.7 configurable-product

我有一个包含3个属性字段的可配置产品(Field1, Field2, Field3) 我需要的是第二个(Field1,其中id为attribute134)有一个按钮收音机,有两个选项,如下所示:

<input type="radio" name="revision" id="revision1" value="base" disabled>
<input type="radio" name="revision" id="revision2" value="complete" disabled>

实际上,不可能使用带有magento的单选按钮,所以我决定将我自己的字段单选按钮同步到Field2,其ID为attribute135 =&GT;第一个属性Field1中的选择仅在Field2中生成两个不同的选项。

所以我做了以下同步:

jQuery("#revision1").click(function(){jQuery('#attribute135').val(jQuery('#attribute135 option:eq(1)').val());});
jQuery("#revision2").click(function(){jQuery('#attribute135').val(jQuery('#attribute135 option:eq(2)').val());});
jQuery("#attribute134").change(function(){jQuery("#revision1").prop('checked', false);jQuery("#revision2").prop('checked', false);jQuery("#revision1").prop("disabled",false);jQuery("#revision2").prop("disabled",false)});

但由于标准行为,我有错误。 =&GT;价格未更新,字段3未激活且预先填写了良好的价值...... 实际上,似乎我的同步是一个自动动作,不会重现通过更改字段2中的值手动生成的comportement。

您是否知道如何解决此问题?什么是良好的jQuery事件,以便手动重现完全相同的comportement?

提前致谢。

2 个答案:

答案 0 :(得分:1)

最后我更改了varien configurable.js中收听的事件,如下所示:

 Event.observe(element, 'change', this.configure.bind(this))
by
 Event.observe(element, 'click', this.configure.bind(this))

我使用你的fonction trigger()如下:

    jQuery("#revision1").click(function(){
    jQuery('#attribute135').val(jQuery('#attribute135 option:eq(1)').val());
    jQuery('#attribute135').trigger('click');
});
jQuery("#revision2").click(function(){
    jQuery('#attribute135').val(jQuery('#attribute135 option:eq(2)').val());
    jQuery('#attribute135').trigger('click');
});

=&GT;我不知道为什么,它不适用于change事件,但它正在使用click事件。

答案 1 :(得分:0)

我在这里有点失落,但我认为jQuery trigger()应该有所帮助。 尝试

jQuery("#revision1").click(function(){
    jQuery('#attribute135').val(jQuery('#attribute135 option:eq(1)').val());
    jQuery('#attribute135').trigger('change');
});
jQuery("#revision2").click(function(){
    jQuery('#attribute135').val(jQuery('#attribute135 option:eq(2)').val());
    jQuery('#attribute135').trigger('change');
});