【问题标题】:Need to add direct checkout instead of adding to the cart in opencart 2.3.0.2在 opencart 2.3.0.2 中需要添加直接结帐而不是添加到购物车
【发布时间】:2017-03-12 08:30:44
【问题描述】:

来自opencart的原始代码:-

var cart = {
    'add': function(product_id, quantity) {
        $.ajax({
            url: 'index.php?route=checkout/cart/add',
            type: 'post',
            data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
            dataType: 'json',
            beforeSend: function() {
                $('#cart > button').button('loading');
            },
            complete: function() {
                $('#cart > button').button('reset');
            },
            success: function(json) {
                $('.alert, .text-danger').remove();

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

                if (json['success']) {
$('#content').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');

                    // Need to set timeout otherwise it wont update the total
                    setTimeout(function () {
                        $('#cart > button').html('<span id="cart-total"><i class="fa fa-shopping-cart"></i> ' + json['total'] + '</span>');
                    }, 100);

                    $('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);
            }
        });
    },

我尝试以这些方式进行编辑,但它对前端没有任何影响,一切都一样 检查下面我尝试在这里替换代码:-

    var cart = {
        'add': function(product_id, quantity) {
            $.ajax({
                url: 'index.php?route=checkout/cart/add',
                type: 'post',
                data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
                dataType: 'json',
                beforeSend: function() {
                    $('#cart > button').button('loading');
                },
                complete: function() {
                    $('#cart > button').button('reset');
                },
                success: function(json) {
                    $('.alert, .text-danger').remove();

                    if (json['redirect']) {
                        location = json['redirect'];
                    }
           //here i replaced the code
                    if (json['success']) {
                    window.location='index.php?route=checkout/checkout';
                    }
                },
                error: function(xhr, ajaxOptions, thrownError) {
                    alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
                }
            });
        },

谁能帮我解决这些 opencart 2.3.0.2 问题..??

【问题讨论】:

    标签: opencart checkout


    【解决方案1】:

    这应该可行,我在 2.3.0.2 上,并且有多个商店在 Success 语句中使用它在单击添加到购物车后重定向到购物车页面。

      window.location.href = "index.php?route=checkout/cart"; 
    

    显然你想把它改成:

      window.location.href = "index.php?route=checkout/checkout";
    

    祝你好运!

    【讨论】:

    • 嘿,Alexander,我必须在哪里替换哪个页面上的代码??
    • 该页面在您的目录/视图/主题/(主题名称)/product/product.tpl 您需要查看添加到购物车成功功能(根据您的主题),它几乎总是在页面的底部。您也可以在此处发布您的 javascript 函数的内容,我可以提供进一步的帮助。
    • 嘿,Alexander,谢谢我做到了,但它仍然存在一个问题,它仅在产品页面上的 iam 时有效,而当 iam 在主屏幕或产品列表中时它不起作用。也请帮助我..
    • 嘿萨尔曼,没问题,现在您已经在 product.tpl 页面上完成了它,这非常简单。您能告诉我您使用哪些模块在这些页面上显示这些产品吗?精选?旋转木马?我必须先知道这一点。
    • 好的,所以在特色产品模块上,在 /catalog/view/theme/(themename)/extensions/module/featured.tpl 中,你会想要做和你在product.tpl 如果这对您有用,您可以投票或将其标记为答案吗?自从我刚开始,我仍然对我的低分帮助别人有多少帮助是有限的。谢谢!
    【解决方案2】:

    用下面的代码替换你已经更改的重定向功能

    window.location='index.php?route=checkout/checkout';
    

    使用此代码,这将重定向到您的结帐。

    location.href='index.php?route=checkout/checkout';
    

    【讨论】:

    • 请格式化您的代码。另外,请让 OP 知道您在回答中提到的陈述之间的区别,这将有助于他们理解问题。
    猜你喜欢
    • 2012-07-02
    • 1970-01-01
    • 2015-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多