2017-09-09 18 views
0

私は数時間を費やして多くのことを試しましたが、うまくいきません。この写真のように 私はOpenCart 3のAdd to basketを修正しています:カートに商品を1つ1つずつ追加する方法を教えてください。

enter image description here

現在の結果を:

enter image description here

期待される結果:
私は製品が欲しい - オプション1 - ショッピングカートの各行ごとにオプション2。

enter image description here

私は、一度にまとめて一つの製品とそのすべてのオプション、各オプションとその関連製品を一つずつない追加したいです。これを行うには、私はこれらのコードを持っている:

これは、チェックボックスのための私のレンダリングされていないコードです:JSとHTMLレンダリング

<div class="checkbox"> 
    <label> 
     <input type="checkbox" 
        data-input-group="chart-group-{{ option.product_option_id }}-{{ option_value.product_option_value_id }}" 
        id="option-{{ option.product_option_id }}-{{ option_value.product_option_value_id }}" 
        name="option[{{ option.product_option_id }}][]" 
        value="{{ option_value.product_option_value_id }}" 
        class="chart-group" /> 
     {% if option_value.image %} <img src="{{ option_value.image }}" alt="{{ option_value.name }} {% if option_value.price %} {{ option_value.price_prefix }} {{ option_value.price }} {% endif %}" class="img-thumbnail" /> {% endif %}     
     {{ option_value.name }} 
    </label> 
</div> 

:任意の種類が役立ちます

$('#button-cart').on('click', function() { 
 
    $(".chart-group:input:checked").each(function() { 
 
     group_id = $(this).data('input-group'); 
 
     $('#input-quantity').val(
 
      $('input[name=quantity][data-input-group=' + group_id + ']').val() 
 
     ); 
 
     
 
     $.ajax({ 
 
      url: 'index.php?route=checkout/cart/add', 
 
      type: 'post', 
 
      data: $('#product input[type=\'text\'], #product input[type=\'hidden\'], #product input[type=\'radio\']:checked, #product input[type=\'checkbox\']:checked, #product select, #product textarea') 
 
     }); 
 
    }); 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> 
 
\t <div class="form-group required "> 
 
\t \t <div id="input-option229"> 
 
\t \t \t <input type="hidden" name="product_id" value="53"> 
 
\t \t \t <table> 
 
\t \t \t \t <tr> 
 
\t \t \t \t \t <td><div class="checkbox"> 
 
\t \t \t \t \t \t \t <label> 
 
\t \t \t \t \t \t \t \t <input type="checkbox" data-input-group="chart-group-229-26" id="option-229-26" name="option[229][]" value="26" class="chart-group"> 
 
\t \t \t \t \t \t \t \t 70B </label> 
 
\t \t \t \t \t \t </div></td> 
 
\t \t \t \t \t <td><input type="text" data-input-group="chart-group-229-26" name="quantity" value="0" size="2" id="input-quantity-229-26" class="qty text-center"></td> 
 
\t \t \t \t </tr> 
 
\t \t \t \t <tr> 
 
\t \t \t \t \t <td><div class="checkbox"> 
 
\t \t \t \t \t \t \t <label> 
 
\t \t \t \t \t \t \t \t <input type="checkbox" data-input-group="chart-group-229-27" id="option-229-27" name="option[229][]" value="27" class="chart-group"> 
 
\t \t \t \t \t \t \t \t 75B </label> 
 
\t \t \t \t \t \t </div></td> 
 
\t \t \t \t \t <td><input type="text" data-input-group="chart-group-229-27" name="quantity" value="0" size="2" id="input-quantity-229-27" class="qty text-center"></td> 
 
\t \t \t \t </tr> 
 
\t \t \t \t <tr> 
 
\t \t \t \t \t <td><div class="checkbox"> 
 
\t \t \t \t \t \t \t <label> 
 
\t \t \t \t \t \t \t \t <input type="checkbox" data-input-group="chart-group-229-28" id="option-229-28" name="option[229][]" value="28" class="chart-group"> 
 
\t \t \t \t \t \t \t \t 80B </label> 
 
\t \t \t \t \t \t </div></td> 
 
\t \t \t \t \t <td><input type="text" data-input-group="chart-group-229-28" name="quantity" value="0" size="2" id="input-quantity-229-28" class="qty text-center"></td> 
 
\t \t \t \t </tr> 
 
\t \t \t </table> 
 
\t \t \t <button type="button" id="button-cart" data-loading-text="Loading..." class="button-cart btn btn-primary btn-sm btn-block"><i class="fa fa-cart-plus" aria-hidden="true"></i> Add to Cart</button> 
 
\t \t \t <input type="hidden" name="quantity" id="input-quantity" value="0"> 
 
\t \t </div> 
 
\t </div>

は非常にあります感謝!

+0

こんにちは少し複雑なあなたはAJAX呼び出しに応答を得た場合、我々は知られていないとして理解し、リダイレクトがあるか、Ajaxの解析がなかった場合は、HTMLを解析する方法任意の成功した無名関数を表示し、page.php index.php?route = checkout/cart/addを分割して2つの異なる製品cosを同じサイズにしないでください。よろしくお願いいたします。 –

+0

@headmaxあなたが興味があるなら、私はFTP情報を提供できます。 – Kardo

+0

プライベートで私はここに新しいですので、あなたが私を運転すればそれは良いでしょう。 –

答えて

0

修正済み!

$('#button-cart').on('click', function() { 

    $(".iqty:input:text").each(function() { 
    $('.chart-group:input:checkbox').prop("checked", false); 

    if ($(this).val() > 0) { 
     group_id = $(this).data('input-group'); 
     $('input[type=checkbox][data-input-group=' + group_id + ']').prop("checked", true); 
     $('#input-quantity').val(
      $('input[name=quantity][data-input-group=' + group_id + ']').val() 
     ); 

     $('input[name=quantity][data-input-group=' + group_id + ']').val(0) 
    } else { 
     $('#input-quantity').val(0); 
    } 

...

関連する問題