skip to Main Content

I have a fresh install of Opencart 1.5.6.4 – link is here

On all my product pages (not the category pages) – when you click ‘add to cart’ it adds x2 of everything.

I have tried re-creating a product with a new SEO title, title, product, new model number – but still, it adds it twice to my cart?

Any ideas? Any help would be greatly appreciated.

2

Answers


  1. This is definitely a conflict or bug with the mmenu jquery extension being used for your nav bar and being included as jquery.mmenu.min.all.js.

    Comment out the line:

    $('nav#menu').mmenu();
    

    And you’ll see the cart button functions normally. Unfortunately this breaks your nav bar. I wish I could tell you more but perhaps worth contacting the developer of that extension:

    http://mmenu.frebsite.nl/support/problem-solving.html

    or file an issue here:

    https://github.com/BeSite/jQuery.mmenu/issues

    Since you appear to be running the most recent version, if there is indeed a bug it hasn’t been fixed yet. I’ve gone ahead and added the mmenu tag to your question which hopefully may draw the attention of someone with answers. Good luck.

    Login or Signup to reply.
  2. [SOLVED]

    On all my product pages (not the category pages) – when you click ‘add
    to cart’ it adds x2 of everything.

    You will have two functions for controlling the add to cart buttons. Proper placement/execution of the code will yield different results. Please see code snippets below.

    The first one is found in /catalog/view/javascript/common.js:

    function addToCart(product_id) {
        $.ajax({
                url: 'index.php?route=checkout/cart/add',
                type: 'post',
                data: 'product_id=' + product_id,
                dataType: 'json',
                success: function(json) {
    

    The second one is typically found in /catalog/view/theme/template/yourtheme/product/product.tpl:

    $('#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) {
    

    If you will notice the data: parts of the code. One is checking for options and then adding to cart and the other is just adding to cart.

    This snippet of code 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'),
    is checking for options and then adding to cart. This is typically used on the product detail page (product.tpl).
    This snippet of code data: 'product_id=' + product_id, is directly adding the product to cart and is typically used elsewhere on the site (other than product detail page). Where the user can just add the item to the cart and then checkout.

    The reason you are getting 2x items added to the cart is because you are using the snippet of code that checks for options and then adds to cart. To make any add to cart button only place one item in the cart (without checking for options) you will need to use data: 'product_id=' + product_id,

    It will look like this

    $('#button-cart').bind('click', function() {
    $.ajax({
    url: 'index.php?route=checkout/cart/add',
    type: 'post',
    data: 'product_id=' + product_id,
    dataType: 'json',
    success: function(json) {
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search