dtbc37573 2013-01-14 10:09
浏览 17
已采纳

Opencart 1.5.4 addToCart()第一次页面显示功能不起作用

I am currently working on a project in Open Cart 1.5.4. I slighty moved the cart into another div without any problems. The thing is on new computers and first time they enter the site it´s not possible for the customer to add a product to cart. If they go into another page and then back it works just fine. The javascript file is loaded properly without any problems.

Hope this explanation explains the problem or bug pretty good.

Thanks in advance.

JAVASCRIPT

function addToCart(product_id, quantity) {
    quantity = typeof(quantity) != 'undefined' ? quantity : 1;

    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: 'product_id=' + product_id + '&quantity=' + quantity,
        dataType: 'json',
        success: function(json) {
            $('.success, .warning, .attention, .information, .error').remove();

            if (json['redirect']) {
                location = json['redirect'];
            }

            if (json['success']) {
                //$('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');

                $('.success').fadeIn('slow');
                try {
                    $('#cart-total').html(json['total']);
                }
                catch(err) {
                    console.log(err.message());
                }

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

                $(".heading").animate({backgroundColor: "#FFFFFF"}, 'slow');

                $(".cart_arrow").attr("style", "display: block;");

                $(".heading").animate({backgroundColor: "#585858"}, 'slow');

            }   
        }
    });
}
  • 写回答

2条回答 默认 最新

  • doutang9037 2013-01-25 07:36
    关注

    Found the cause of the problem. When Open Cart is installed and domain is about to be choosen, you can choose www or non-www. Depends on the one you choose the other wont work. So the solution to the problem htaccess redirect for this one from non-www to www adress

    RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
    RewriteRule ^(.*) http://www.domain.com/$1 [R=301,L]
    
    RewriteBase /
    RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
    RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
    RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
    

    The redirect has to be over RewriteBase /

    Thanks and I hope this helps in the future for anyone nedded this kind of support

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算