当我在 opencart 中加载时出现错误

Bug when I .load in opencart

我编辑了我的 checkout/cart.tpl,最初一切看起来都很好,但是当我 "add cart" 代码自动更改时,一切都变得奇怪了。

例子

1- 当我进入网站并查看购物车时,一切正常:

2- BUG/MISTAKE。当我更新我的购物车时,当我点击 "Add cart" 时只出现我的购物车的这一部分,没有价格和结帐等:

HTML/cart.TPL

<div id="cart">
  <a href="#" data-loading-text="<?php echo $text_loading; ?>"><img src="images/bag.png" alt="Bag" />Cart: <span id="cart-total"><?php echo $text_items; ?></span></a>
  <div class="cart_menu">
    <?php if ($products || $vouchers) { ?>
    <div class="cart_items">
        <?php foreach ($products as $product) { ?>
          <div class="c_item_img floatleft">
          <?php if ($product['thumb']) { ?>
                            <a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" /></a>
            <?php } ?>
            </div>


            <div class="c_item_totals floatleft">
                            <div class="c_item_totals_detail floatleft">
                                <a href="<?php echo $product['href']; ?>"><h5><?php echo $product['name']; ?></h5></a>
                                <span><?php echo $product['quantity']; ?> x <?php echo $product['total']; ?></span>
                            </div>
                            <div class="close_icon_cart floatleft">
                                <img src="images/close.png" onclick="cart.remove('<?php echo $product['key']; ?>');" title="<?php echo $button_remove; ?>" alt="" />
                            </div>
                        </div>



            <?php } ?>
            </div>


    <div class="cart_totals">
    <?php foreach ($totals as $total) { ?>
                        <div class="c_totals_left floatleft">
                            <p></p>
                        </div>
                        <div class="c_totals_right floatleft">
                            <p><?php echo $total['title']; ?>   <?php echo $total['text']; ?></p>
                             </div>
                             <?php } ?>

                        </div>


        <div class="cart_view_bottom">
                        <div class="c_totals_left floatleft">
                            <a href="<?php echo $cart; ?>"><?php echo $text_cart; ?></a>
                        </div>
                        <div class="c_totals_right floatleft">
                            <a href="<?php echo $checkout; ?>"><?php echo $text_checkout; ?></a>
                        </div>
                    </div>


    <?php } else { ?>
    <div class="cart_items">
      <p class="text-center"><?php echo $text_empty; ?></p>
    </div>
    <?php } ?>
            </div>  
            </div>

.JS

<script type="text/javascript"><!--
$('#button-cart').on('click', function() {
    $.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'),
        dataType: 'json',
        beforeSend: function() {
            $('#button-cart').button('loading');
        },
        complete: function() {
            $('#button-cart').button('reset');
        },
        success: function(json) {
            $('.alert, .text-danger').remove();
            $('.form-group').removeClass('has-error');

            if (json['error']) {
                if (json['error']['option']) {
                    for (i in json['error']['option']) {
                        var element = $('#input-option' + i.replace('_', '-'));

                        if (element.parent().hasClass('input-group')) {
                            element.parent().after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                        } else {
                            element.after('<div class="text-danger">' + json['error']['option'][i] + '</div>');
                        }
                    }
                }

                if (json['error']['recurring']) {
                    $('select[name=\'recurring_id\']').after('<div class="text-danger">' + json['error']['recurring'] + '</div>');
                }

                // Highlight any found errors
                $('.text-danger').parent().addClass('has-error');
            }

            if (json['success']) {
                $('.breadcrumb').after('<div class="alert alert-success">' + json['success'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');

                $('#cart-total').html(json['total']);

                $('html, body').animate({ scrollTop: 0 }, 'slow');

                $('#cart > div').load('index.php?route=common/cart/info .cart_menu .cart_items');
            }
        }
    });
});
//--></script> 

我已经尝试将所有 div 类 放入 JavaScript 但不幸的是它没有用。

我几乎可以肯定,您的问题是由于您在 checkout/cart 模板中使用了 ID "cart",[=] 处理的购物车模块已在使用该 ID 11=]。重要的是要了解这是两个不同的东西,cart id 需要是唯一的 - 特别是当您使用 javascript 更新它的内容时。

尝试将 checkout/cart.tpl 中的 ID 更改为 "cart".

以外的其他内容