简体   繁体   English

前端问题中的“添加到购物车和产品选项”字段-Magento

[英]Add to cart and product options field in frontend issue - Magento

I have a issue on product view page. 我在产品查看页面上有问题。 I add two radio buttons to hide product options and to show. 我添加了两个单选按钮以隐藏产品选项并进行显示。 But I have a problem when hide is selected and the custom fields are hide, when I press on Add to cart button I have this error " Please specify the product required option(s). " Is there any to add the product in cart with the fields empty? 但是,当我选择“隐藏”并且自定义字段为“隐藏”时,当我按下“添加到购物车”按钮时,我遇到了这个错误“ 请指定所需的产品选项。 ”字段为空? So the idea is to Disable Validation when hideRadio.click(function() { is selected 因此,当选择hideRadio.click(function(){

This is my javascript code to make the radio buttons to hide and show: 这是我的JavaScript代码,用于隐藏和显示单选按钮:

    var showRadio = jQuery('.product-options .display ul li:nth-child(2)').find('input');
    var hideRadio = jQuery('.product-options .display ul li:nth-child(1)').find('input');
        if(hideRadio){
             jQuery('.product-options dd, .product-options dt').hide();
             hideRadio.parents('dd').show();
                hideRadio.parents('dd').prevAll('dt:first').show();

        }

        hideRadio.click(function() {
          jQuery('.product-options dd, .product-options dt').hide();
          jQuery(this).parents('dd').show();
          jQuery(this).parents('dd').prevAll('dt:first').show();
        })
        showRadio.click(function() {
          jQuery('.product-options dd, .product-options dt').show();
        })

New Update: 新更新:

Add this code into if(hideRadio){ 将此代码添加到if(hideRadio){

         hideRadio.parents('dd').prevAll('dt:first').remove();

But still the same message " Please specify the product required option(s). ". 但是仍然出现相同的消息“ 请指定产品所需的选项。 ”。 Anyone? 任何人?

You should use classes to hide and show elements (toggle their visibility, as .hidden or something of your convenience) because, as stated in the Jquery docs, different elements can behave differently. 您应该使用类来隐藏和显示元素(以.hidden或方便的方式切换它们的可见性),因为正如Jquery文档中所述,不同元素的行为可能不同。

When you use hide() the element and its children become "invisible" to other jquery scripts. 使用hide()时,该元素及其子元素对其他jquery脚本“不可见”。 I solved such problem with css absolute negative position to hide my container (everything involving display:none, even in css class made my element "invisible") 我用css绝对负位置解决了这个问题,以隐藏我的容器(所有与display:none无关的事情,即使在css类中也使我的元素“不可见”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM