foreachループで製品の値を取得しているだけです。製品の量を取得すると、フォームの入力領域に挿入され、カートに追加するボタンがその製品の量をクリックすると、ロジックは次のようになります。チェックアウトページに表示されます..foreachループ内のコードは次のようになります
![<div class="cart">
<table class="discount-prices">
<tr>
<?php foreach ($discounts as $discount) { ?>
<td class="discount-price">
<?php echo sprintf($text_discount, $discount\['quantity'\], $discount\['price'\]); ?>
</td>
</tr>
</table>
<div>
<?php echo $text_qty; ?>
<input type="text" name="quantity" size="2" value="<?php echo $discount\['quantity'\]; ?>" />
<input type="hidden" name="product_id" size="2" value="<?php echo $product_id; ?>" />
<input type="button" value="<?php echo $button_cart; ?>" id="button-cart" class="button" />
</div>
<?php } ?>]
ボタンで動作しているjQueryスクリプトはこんな感じ
$('#button-cart').bind('click', function() {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
dataType: 'json',
success: function(json) {
$('.success, .warning, .attention, information, .error').remove();
if (json['error']) {
if (json['error']['option']) {
for (i in json['error']['option']) {
$('#option-' + i).after('<span class="error">' + json['error']['option'][i] + '</span>');
}
}
}
if (json['success']) {
$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');
//$('.success').fadeIn('slow');
$('#cart-total').html(json['total']);
$('html, body').animate({ scrollTop: 0 }, 'slow');
setTimeout(opencartpage(),1000);
}
}
});
});
ここで問題は、最初のカートに追加ボタンをクリックしているときに、チェックアウトページに移動しますが、値が 3 ではなく 5 になっていることです。ボタンの値は「3」ですが、「5」(最後の値) を取っています。もう 1 つの問題は、カートに追加するための最初のボタンがチェックアウト ページで機能しているが、カートに追加するための別の 2 つのボタンがまったく機能していないことです。残りの 2 つのボタンをクリックしても何も起こりません。それで、誰かが私を助けて、ここで間違っている部分を教えてもらえますか?
アップデート
$('.button-cart')
代わりに使用する$('#button-cart')
と、すべてのボタンがアクティブになり、そのボタンをクリックするとチェックアウトページが処理されますが、最初の画像に表示されている最後の値である 5 のみが取得されます。では、この問題を解決するにはどうすればよいでしょうか。