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 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路