2017-09-09 1 views
0

몇 시간을 보내고 많은 일을 시도했지만 작동하지 않습니다. 이 그림과 같이 나는 OpenCart 3의 Add to basket을 수정하고 있습니다 :각 옵션마다 장바구니에 제품을 하나씩 추가하는 방법은 무엇입니까?

enter image description here

현재 결과 :

enter image description here

예상 결과 :
나는 제품 갖고 싶어 - 옵션 1 - 장바구니의 각 행마다 옵션 2.

enter image description here

나는 한 번에 함께 각 옵션과 하나 관련 제품 하나가 아니라 하나 개의 제품 및 모든 옵션을 추가하고 싶습니다.

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

가 렌더링 JS와 HTML은 : : 모든 종류의 도움이

$('#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 호출에 응답을 가지고 있다면 우리는 알려져 있지 않는 한 이해하고, 리디렉션 또는 아약스 구문 분석하지 않았다 경우 HTML을 구문 분석하는 방법 임의의 성공 익명 함수를 보여주고 page.php index.php? route = checkout/cart/add가 split 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); 
    } 

...

관련 문제