2017-09-09 4 views
0

Je passe quelques heures et j'essaye beaucoup de choses, mais ça ne marche pas. Je modifier Add to basket de OpenCart 3 comme le montre cette image:Comment ajouter des produits au panier un par un pour chaque option?

enter image description here

Résultat actuel:

enter image description here

Résultat attendu:
Je veux avoir produit - Options 1 - Option 2 pour chaque ligne dans le panier.

enter image description here

Je veux ajouter chaque option et son produit connexe, un par un, pas un seul produit et toutes ses options ensemble à la fois. Pour ce faire, j'ai ces codes:

C'est mon code unrendered pour case à cocher:

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

Rendus JS et 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>

Tout type aide est très apprécié!

+0

Salut Un petit peu complexe à comprendre que nous ne sait pas si vous avez obtenu une réponse sur l'appel ajax et comment vous analysez html si une redirection ou un Parse ajax n'a pas montrer toute fonction anonyme de succès et si le page.php index.php? route = checkout/panier/ajouter faire le travail en tant que scission 2 produits différents cos n'est pas la même taille grâce à clarifier ce point. Cordialement –

+0

@headmax Je peux fournir des informations FTP si vous êtes intéressé. Merci beaucoup d'avance! – Kardo

+0

ok en privé je suis nouveau ici, donc si vous me conduisez ce sera bon. –

Répondre

0

Fixé!

$('#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); 
    } 

...