如何在类别页面中添加数量框 打开购物车 2.2.


How to add quantity box in category pages opencart 2.2

我正在开发OpenChart(OC)的2.2版本,我是OC的新手,我想在类别页面和特色产品部分添加数量框。

所以我试图从 theme/default/template/product/product.tpl,因为我想要与OC在产品页面中应用的结果相同的结果。

<label class="control-label" for="input-quantity"><?php echo $entry_qty; ?></label>
          <input type="text" name="quantity" value="<?php echo $minimum; ?>" size="2" id="input-quantity" class="form-control" />
          <input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />

并试图将其粘贴到价格以下theme/default/template/product/category.tpl页面中,但Undefined variable出现错误。

从研发中,我知道我也必须catalog/controller/category.tpl页面中更新它。我不知道该怎么办。

请帮助我。提前非常感谢。

您将替换以下更改

类别.tpl

将代码替换为以下内容

<div class="image"><a href="<?php echo $product['href']; ?>" id="location-<?php echo $product['product_id']; ?>"><img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-responsive" /></a></div>

在"div class="button-group"之前添加以下代码>

<div class="form-group">
    <label class="control-label" for="input-quantity">Qty</label>
    <input type="text" name="quantity" value="<?php echo $product['minimum']; ?>" size="2" id="input-quantity-<?php echo $product['product_id']; ?>" class="form-control" />
    </div>  

更改以下代码

<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>

到关注

<button type="button" onclick="addTocart('<?php echo $product['product_id']; ?>')"><i class="fa fa-shopping-cart"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span></button>

在之前添加 JavaScript

<script type="text/javascript">
function addTocart(product_id){
    var product_id = product_id;
    var qty = $('#input-quantity-'+product_id).val();
    var location = $('#location-'+product_id).attr('href');
    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: 'product_id='+product_id+'&quantity='+qty,
        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']) {
                    window.location = location;
                }
                if (json['error']['recurring']) {
                    window.location = location;
                }
                // 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 > button').html('<i class="fa fa-shopping-cart"></i> ' + json['total']);
                $('html, body').animate({ scrollTop: 0 }, 'slow');
                $('#cart > ul').load('index.php?route=common/cart/info ul li');
            }
        },
        error: function(xhr, ajaxOptions, thrownError) {
            alert(thrownError + "'r'n" + xhr.statusText + "'r'n" + xhr.responseText);
        }
    });
}
</script>

干杯