我试图跳过结帐页面中的付款地址

时间:2019-09-13 20:28:58

标签: php opencart opencart-3

在结帐过程中,我试图隐藏第二步,即付款地址。我的解决方案是先调用传递地址,然后再使用相同的地址使用ajax post方法保存付款地址的数据。

但是我在index.php?route=checkout/payment_address/save

的ajax post方法中遇到错误

我试图在#button-shipping-address点击功能中进行Payment_address / save POST调用,但是它不起作用。

// Shipping Address
...
$(document).delegate('#button-shipping-address', 'click', function() {
    $.ajax({
        url: 'index.php?route=checkout/shipping_address/save',
        type: 'post',
        data: $('#collapse-shipping-address input[type=\'text\'], #collapse-shipping-address input[type=\'date\'], #collapse-shipping-address input[type=\'datetime-local\'], #collapse-shipping-address input[type=\'time\'], #collapse-shipping-address input[type=\'password\'], #collapse-shipping-address input[type=\'checkbox\']:checked, #collapse-shipping-address input[type=\'radio\']:checked, #collapse-shipping-address textarea, #collapse-shipping-address select'),
        dataType: 'json',
        beforeSend: function() {
            $('#button-shipping-address').button('loading');
        },
        success: function(json) {      
            $('.alert-dismissible, .text-danger').remove();
            $('.form-group').removeClass('has-error');

            if (json['redirect']) {
                location = json['redirect'];
            } else if (json['error']) {
                $('#button-shipping-address').button('reset');

                if (json['error']['warning']) {
                    $('#collapse-shipping-address .panel-body').prepend('<div class="alert alert-warning alert-dismissible">' + json['error']['warning'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
                }

                for (i in json['error']) {
                    var element = $('#input-shipping-' + i.replace('_', '-'));

                    if ($(element).parent().hasClass('input-group')) {
                        $(element).parent().after('<div class="text-danger">' + json['error'][i] + '</div>');
                    } else {
                        $(element).after('<div class="text-danger">' + json['error'][i] + '</div>');
                    }
                }

                // Highlight any found errors
                $('.text-danger').parent().parent().addClass('has-error');
            } else {

            //****** start payment address

                                $.ajax({
        url: 'index.php?route=checkout/payment_address/save',
        type: 'post',
        data: $('#collapse-shipping-address input[type=\'text\'], #collapse-shipping-address input[type=\'date\'], #collapse-shipping-address input[type=\'datetime-local\'], #collapse-shipping-address input[type=\'time\'], #collapse-shipping-address input[type=\'password\'], #collapse-shipping-address input[type=\'checkbox\']:checked, #collapse-shipping-address input[type=\'radio\']:checked, #collapse-shipping-address textarea, #collapse-shipping-address select,collapse-shipping-address label'),
        dataType: 'json',
        beforeSend: function() {
            //$('#button-payment-address').button('loading');
        },
        complete: function() {
            //$('#button-payment-address').button('reset');
        },
        success: function(jsons) {
            console.log('sent payment add'+JSON.stringify(jsons));
        }
    });

                            //******* end of payment call

                $.ajax({
                    url: 'index.php?route=checkout/shipping_method',
                    dataType: 'html', 

这不起作用,没有数据保存到“ / payment_address / save”。通常,它应该给null数组响应([])这样的东西,但是它给出以下错误:

{
    "error": {
        "firstname": "First Name must be between 1 and 32 characters!",
        "lastname": "Last Name must be between 1 and 32 characters!",
        "address_1": "Address 1 must be between 3 and 128 characters!",
        "city": "City must be between 2 and 128 characters!",
        "custom_field1": "Mobile required!"
    }
}

过去2天我一直在努力,但找不到解决方案。

1 个答案:

答案 0 :(得分:2)

在OC3.0.x上隐藏3个步骤的有效解决方案: 在$this->load->language('checkout/checkout');之后的文件目录/控制器/结帐/shipping_address.php中添加:

if (!empty($this->session->data['shipping_address']['address_id'])) {
    $this->session->data['shipping_address']['address_id'] = $this->session->data['payment_address']['address_id'];
}

之后,您需要跳过3步前进。 在文件中:catalog / view / theme / your_template / template / checkout / shipping_address.twig 添加此脚本:

<script type="text/javascript"><!--
    if ($('#shipping-address-clicked').length == 0) {
        setTimeout(function(){
            $('#button-guest-shipping').click();
            $('#button-shipping-address').click();
            $('body').append('<div id="shipping-address-clicked" />');
                                }, 500);
                            }
        $('#button-guest, #button-register, #button-payment-address, #collapse-payment-address').click(function(){
        $('#shipping-address-clicked').remove();
        });
   //--></script>

之后,您需要使用CSS隐藏此步骤 在文件目录/视图/主题/your_theme/template/checkout/checkout.twig中 添加样式:

    <style type="text/css">
        #accordion > div:nth-child(3)  {
        display: none;
        }
   </style>

并使用样式隐藏复选框,并在文件中需要运输时添加值1: 目录/视图/主题/您的主题/模板/签出/guest.twig 目录/视图/主题/您的主题/模板/签出/register.twig 查找:{% if shipping_required %}  在以下位置添加:

<input type="checkbox" name="shipping_address" value="1" checked="checked" style="display: none" />
{% else %}