0

Im working on a 2.2 version of OpenChart (OC), and I'm new to OC, and I want to add quantity box in category pages and at featured products parts.

So I was trying to copy this code from theme/default/template/product/product.tpl, because I want the same result which OC have applied in product page.

<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; ?>" />

and was trying to paste it in theme/default/template/product/category.tpl page below price but got an error Undefined variable.

From R&D I got to know that I have to update it in catalog/controller/category.tpl page as well. I don't know what to do.

Please help me. Thanks alot in advance.

Joe Miller
  • 3,843
  • 1
  • 23
  • 38
Adi
  • 25
  • 1
  • 9

1 Answers1

2

You will replace the following changes in

category.tpl

Replace code with following

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

add following code before '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>  

change following code

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

to following

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

Add Javascript before

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

Cheers

Vipul Jethva
  • 647
  • 1
  • 7
  • 27
  • Vipul, I will try this thing later, i got an error in vqmod, could you please help me with this http://stackoverflow.com/questions/36908035/vqmod-logs-opencart-error – Adi Apr 28 '16 at 07:36
  • @Adi My code is working then give me once whote to me. – Vipul Jethva Apr 28 '16 at 08:37
  • Ya i will surely give. One more thing i need to ask you that is i have installed an extension which is "select weight" in category page only so if i edit this code then will it harm to extension functionality? – Adi Apr 28 '16 at 09:53
  • I don't think it will harm your extension functionality. But why are you set all of the thing in category page? You will use quick view in category page so customer will see all of thing in category page. There is no need to change core file of opencart. – Vipul Jethva Apr 28 '16 at 10:18
  • Client's requirement buddy. you can have a look to website, http://www.shreejifoods.in/ – Adi Apr 29 '16 at 02:18
  • I have tried your code and its working great if i disable installed extension. Hope you already had a look at the extension which is already installed in shreejifoods.in website. check this link, where your code is applied and extension is enabled. http://hananelraz.com/test-op/index.php?route=product/category&path=20_27 and this is extension file for category page. http://www.filedropper.com/addoptioncategory – Adi May 09 '16 at 04:05