0

我正在开发 2.2 版本的 OpenChart (OC),而且我是 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页面中更新它。我不知道该怎么办。

请帮我。非常感谢提前。

4

1 回答 1

2

您将替换以下更改

类别.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>

干杯

于 2016-04-28T07:24:52.030 回答