comment faire une redirection vers une URL spécifique ?


AMC

J'exécute opecart 3 avec le nouveau thème de journal 3. La page du produit comporte un bouton "achat rapide" qui ajoute automatiquement les détails du produit au panier, puis redirige le client vers la page de paiement.

Je n'arrive pas à changer l'URL du bouton quick_buy. J'en ai besoin pour faire ce qu'il fait comme ci-dessus, mais pour rediriger l'utilisateur vers une URL personnalisée.

Comment puis-je atteindre cet objectif?

Code comme vu ici :

// Array includes polyfill
if (!Array.prototype.includes) {
    Object.defineProperty(Array.prototype, 'includes', {
        value: function (searchElement, fromIndex) {

            if (this == null) {
                throw new TypeError('"this" is null or not defined');
            }

            // 1. Let O be ? ToObject(this value).
            var o = Object(this);

            // 2. Let len be ? ToLength(? Get(O, "length")).
            var len = o.length >>> 0;

            // 3. If len is 0, return false.
            if (len === 0) {
                return false;
            }

            // 4. Let n be ? ToInteger(fromIndex).
            //    (If fromIndex is undefined, this step produces the value 0.)
            var n = fromIndex | 0;

            // 5. If n ≥ 0, then
            //  a. Let k be n.
            // 6. Else n < 0,
            //  a. Let k be len + n.
            //  b. If k < 0, let k be 0.
            var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);

            function sameValueZero(x, y) {
                return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
            }

            // 7. Repeat, while k < len
            while (k < len) {
                // a. Let elementK be the result of ? Get(O, ! ToString(k)).
                // b. If SameValueZero(searchElement, elementK) is true, return true.
                if (sameValueZero(o[k], searchElement)) {
                    return true;
                }
                // c. Increase k by 1.
                k++;
            }

            // 8. Return false
            return false;
        }
    });
}

$(function () {
    // Currency
    $('#form-currency .currency-select').unbind().on('click', function (e) {
        e.preventDefault();

        $('#form-currency input[name=\'code\']').val($(this).data('name'));

        $('#form-currency').submit();
    });

    // Language
    $('#form-language .language-select').unbind().on('click', function (e) {
        e.preventDefault();

        $('#form-language input[name=\'code\']').val($(this).data('name'));

        $('#form-language').submit();
    });
});

window['cart'].add = function (product_id, quantity, quick_buy) {
    quantity = quantity || 1;

    $.ajax({
        url: 'index.php?route=checkout/cart/add',
        type: 'post',
        data: 'product_id=' + product_id + '&quantity=' + quantity,
        dataType: 'json',
        beforeSend: function () {
            $('[data-toggle="tooltip"]').tooltip('hide');
            $('[onclick*="cart.add(\'' + product_id + '\'"]').button('loading');
        },
        complete: function () {
            $('[onclick*="cart.add(\'' + product_id + '\'"]').button('reset');
        },
        success: function (json) {
            $('.alert, .text-danger').remove();

            if (json['redirect']) {
                if (json['options_popup']) {
                    if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
                        iNoBounce.enable();
                    }

                    var html = '';

                    html += '<div class="popup-wrapper popup-options">';
                    html += '    <div class="popup-container">';
                    html += '        <button class="btn popup-close"></button>';
                    html += '        <div class="popup-body">';
                    html += '        <div class="popup-inner-body">';
                    html += '            <div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
                    html += '            <iframe src="index.php?route=journal3/product&product_id=' + product_id + '&popup=options&product_quantity=' + quantity + '&' + (quick_buy ? 'quick_buy=true' : '') + '" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').fadeOut();"></iframe>';
                    html += '        </div>';
                    html += '        </div>';
                    html += '    </div>';
                    html += '    <div class="popup-bg popup-bg-closable"></div>';
                    html += '</div>';

                    // show modal
                    $('.popup-wrapper').remove();

                    $('body').append(html);

                    setTimeout(function () {
                        $('html').addClass('popup-open popup-center');
                    }, 10);
                } else {
                    location = json['redirect'];
                }
            }

            if (json['success']) {
                if (json['options_popup']) {
                    if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
                        iNoBounce.enable();
                    }

                    var html = '';

                    html += '<div class="popup-wrapper popup-options">';
                    html += '    <div class="popup-container">';
                    html += '        <button class="btn popup-close"></button>';
                    html += '        <div class="popup-body">';
                    html += '        <div class="popup-inner-body">';
                    html += '            <div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
                    html += '            <iframe src="index.php?route=journal3/product&product_id=' + product_id + '&popup=options&' + (quick_buy ? 'quick_buy=true' : '') + '" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').fadeOut();"></iframe>';
                    html += '        </div>';
                    html += '        </div>';
                    html += '    </div>';
                    html += '    <div class="popup-bg popup-bg-closable"></div>';
                    html += '</div>';

                    // show modal
                    $('.popup-wrapper').remove();

                    $('body').append(html);

                    setTimeout(function () {
                        $('html').addClass('popup-open popup-center');
                    }, 10);
                } else {
                    if (json['notification']) {
                        show_notification(json['notification']);

                        if (quick_buy) {
                            location = 'index.php?route=checkout/checkout';
                        }
                    } else {
                        $('header').after('<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-total').html(json['total']);
                    $('#cart-items').html(json['items_count']);
                }, 100);

                if (Journal['scrollToTop']) {
                    $('html, body').animate({ scrollTop: 0 }, 'slow');
                }

                $('.cart-content ul').load('index.php?route=common/cart/info ul li');

                if (parent.window['_QuickCheckout']) {
                    parent.window['_QuickCheckout'].save();
                }
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
        }
    });
};

window['cart'].remove = function (key) {
    $.ajax({
        url: 'index.php?route=checkout/cart/remove',
        type: 'post',
        data: 'key=' + key,
        dataType: 'json',
        beforeSend: function () {
            $('#cart > button').button('loading');
        },
        complete: function () {
            $('#cart > button').button('reset');
        },
        success: function (json) {
            // Need to set timeout otherwise it wont update the total
            setTimeout(function () {
                $('#cart-total').html(json['total']);
                $('#cart-items').html(json['items_count']);
            }, 100);

            if ($('html').hasClass('route-checkout-cart') || $('html').hasClass('route-checkout-checkout')) {
                location = 'index.php?route=checkout/cart';
            } else {
                $('.cart-content 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);
        }
    });
};

window['cart'].update = function (key, quantity) {
    $.ajax({
        url: 'index.php?route=checkout/cart/edit',
        type: 'post',
        data: 'key=' + key + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
        dataType: 'json',
        beforeSend: function () {
            $('#cart > button').button('loading');
        },
        complete: function () {
            $('#cart > button').button('reset');
        },
        success: function (json) {
            // Need to set timeout otherwise it wont update the total
            setTimeout(function () {
                $('#cart-total').html(json['total']);
                $('#cart-items').html(json['items_count']);
            }, 100);

            if ($('html').hasClass('route-checkout-cart') || $('html').hasClass('route-checkout-checkout')) {
                location = 'index.php?route=checkout/cart';
            } else {
                $('.cart-content 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);
        }
    });
};

window['wishlist'].add = function (product_id) {
    $.ajax({
        url: 'index.php?route=account/wishlist/add',
        type: 'post',
        data: 'product_id=' + product_id,
        dataType: 'json',
        success: function (json) {
            $('.alert').remove();

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

            if (json['success']) {
                $('[data-toggle="tooltip"]').tooltip('hide');

                if (json['notification']) {
                    show_notification(json['notification']);
                } else {
                    $('header').after('<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>');
                }
            }

            $('#wishlist-total span').html(json['total']);
            $('#wishlist-total').attr('title', json['total']);
            $('.wishlist-badge').text(json['count']);

            if (Journal['scrollToTop']) {
                $('html, body').animate({ scrollTop: 0 }, 'slow');
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
        }
    });
};

window['compare'].add = function (product_id) {
    $.ajax({
        url: 'index.php?route=product/compare/add',
        type: 'post',
        data: 'product_id=' + product_id,
        dataType: 'json',
        success: function (json) {
            $('.alert').remove();

            if (json['success']) {
                $('[data-toggle="tooltip"]').tooltip('hide');

                if (json['notification']) {
                    show_notification(json['notification']);
                } else {
                    $('header').after('<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>');
                }

                $('#compare-total').html(json['total']);
                $('.compare-badge').text(json['count']);

                if (Journal['scrollToTop']) {
                    $('html, body').animate({ scrollTop: 0 }, 'slow');
                }
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
        }
    });
};

window['quickview'] = function (product_id) {
    product_id = parseInt(product_id, 10);

    // hide tooltip
    $('[data-toggle="tooltip"]').tooltip('hide');

    var html = '';

    html += '<div class="popup-wrapper popup-quickview">';
    html += '    <div class="popup-container">';
    html += '        <button class="btn popup-close"></button>';
    html += '        <div class="popup-body">';
    html += '            <div class="popup-inner-body">';
    html += '                <div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
    html += '                <iframe src="index.php?route=journal3/product&product_id=' + product_id + '&popup=quickview" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').hide();"></iframe>';
    html += '            </div>';
    html += '        </div>';
    html += '    </div>';
    html += '    <div class="popup-bg popup-bg-closable"></div>';
    html += '</div>';

    // show modal
    $('.popup-wrapper').remove();

    $('body').append(html);

    setTimeout(function () {
        $('html').addClass('popup-open popup-center');
    }, 10);
};

window['open_popup'] = function (module_id) {
    if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
        iNoBounce.enable();
    }

    module_id = parseInt(module_id, 10);

    var html = '';

    html += '<div class="popup-wrapper popup-module">';
    html += '    <div class="popup-container">';
    html += '        <button class="btn popup-close"></button>';
    html += '        <div class="popup-body">';
    html += '        <div class="popup-inner-body">';
    html += '        </div>';
    html += '        </div>';
    html += '    </div>';
    html += '    <div class="popup-bg popup-bg-closable"></div>';
    html += '</div>';

    // show modal
    $('.popup-wrapper').remove();

    $('body').append(html);

    setTimeout(function () {
        $('html').addClass('popup-open popup-center');
    }, 10);

    $('.popup-container').css('visibility', 'hidden');

    $.ajax({
        url: 'index.php?route=journal3/popup/get&module_id=' + module_id + '&popup=module',
        success: function (html) {
            var $html = $(html);
            var $popup = $html.siblings('.module-popup');
            var $style = $html.siblings('style');
            var $content = $popup.find('.popup-container');

            $('#popup-style-' + module_id).remove();
            $('head').append($style.attr('id', 'popup-style-' + module_id));
            $('.popup-wrapper').attr('class', $popup.attr('class'));
            $('.popup-container').html($content.html());

            $('.popup-container').css('visibility', 'visible');
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(thrownError + '\r\n' + xhr.statusText + '\r\n' + xhr.responseText);
        }
    });
};

window['open_login_popup'] = function () {
    if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
        iNoBounce.enable();
    }

    var html = '';

    html += '<div class="popup-wrapper popup-login">';
    html += '    <div class="popup-container">';
    html += '        <button class="btn popup-close"></button>';
    html += '        <div class="popup-body">';
    html += '        <div class="popup-inner-body">';
    html += '            <div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
    html += '            <iframe src="index.php?route=account/login&popup=login" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').fadeOut();"></iframe>';
    html += '        </div>';
    html += '        </div>';
    html += '    </div>';
    html += '    <div class="popup-bg popup-bg-closable"></div>';
    html += '</div>';

    // show modal
    $('.popup-wrapper').remove();

    $('body').append(html);

    setTimeout(function () {
        $('html').addClass('popup-open popup-center');
    }, 10);
};

window['open_register_popup'] = function () {
    if ($('html').hasClass('iphone') || $('html').hasClass('ipad')) {
        iNoBounce.enable();
    }

    var html = '';

    html += '<div class="popup-wrapper popup-register">';
    html += '    <div class="popup-container">';
    html += '        <button class="btn popup-close"></button>';
    html += '        <div class="popup-body">';
    html += '        <div class="popup-inner-body">';
    html += '            <div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div>';
    html += '            <iframe src="index.php?route=account/register&popup=register" width="100%" height="100%" frameborder="0" onload="this.height = this.contentWindow.document.body.offsetHeight; $(this).prev(\'.journal-loading\').fadeOut();"></iframe>';
    html += '        </div>';
    html += '        </div>';
    html += '    </div>';
    html += '    <div class="popup-bg popup-bg-closable"></div>';
    html += '</div>';

    // show modal
    $('.popup-wrapper').remove();

    $('body').append(html);

    setTimeout(function () {
        $('html').addClass('popup-open popup-center');
    }, 10);
};

window['show_notification'] = function (opts) {
    opts = $.extend({
        position: 'center',
        className: '',
        title: '',
        image: '',
        message: '',
        buttons: [],
        timeout: Journal.notificationHideAfter
    }, opts);

    if ($('.notification-wrapper-' + opts.position).length === 0) {
        $('body').append('<div class="notification-wrapper notification-wrapper-' + opts.position + '"></div>');
    }

    var html = '';

    var buttons = $.map(opts.buttons, function (button) {
        return '<a class="' + button.className + '" href="' + button.href + '">' + button.name + '</a>';
    });

    html += '<div class="notification ' + opts.className + '">';
    html += '    <button class="btn notification-close"></button>';
    html += '    <div class="notification-content">';

    if (opts.image) {
        html += '        <img src="' + opts.image + '" srcset="' + opts.image + ' 1x, ' + opts.image2x + ' 2x">';
    }

    html += '        <div>';
    html += '            <div class="notification-title">' + opts.title + '</div>';
    html += '            <div class="notification-text">' + opts.message + '</div>';
    html += '        </div>';
    html += '    </div>';

    if (buttons && buttons.length) {
        html += '<div class="notification-buttons">' + buttons.join('\n') + '</div>';
    }

    html += '</div>';

    var $notification = $(html);

    $('.notification-wrapper-' + opts.position).append($notification);

    if (opts.timeout) {
        setTimeout(function () {
            $notification.find('.notification-close').trigger('click');
        }, opts.timeout);
    }

    return $notification;
};

window['loader'] = function (el, status) {
    var $el = $(el);

    if (status) {
        $el.attr('style', 'position: relative');
        $el.append('<div class="journal-loading-overlay"><div class="journal-loading"><i class="fa fa-spinner fa-spin"></i></div></div>');
    } else {
        $el.attr('style', '');
        $el.find('.journal-loading-overlay').remove();
    }
};

window['resize_iframe'] = function (module_id, height) {
    $('.module-popup-' + module_id + ' iframe').height(height);
};

Dmitriy Jouk

à partir du code fourni, je peux voir qu'il n'y a qu'une seule méthode qui redirige vraiment, et c'est window['cart'].add

évidemment, ce code est responsable de la redirection

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

pourtant, le locationn'est utilisé nulle part après cela. C'est donc une impasse.

Journal est l'un des frameworks les plus mystérieux que je connaisse, ce n'est donc pas une surprise pour moi. Voici quelque chose que je ferais.

  1. modifiez ce locationparamètre sur le lien personnalisé comme cecilocation = 'index.php?route=product/special';
  2. vider le cache des brindilles afin que nous soyons sûrs que les changements ont lieu
  3. si cela ne fonctionne pas, vérifiez le fichier du contrôleur de la catalog/controller/checkout/cartméthode in addet voyez s'il existe une redirection personnalisée.
  4. n'oubliez pas de vérifier les fichiers de modification system/storage/modification/...pour le controller/checkout/cart.phpet la brindilleview/theme/.../...twig

J'espère avoir réussi à vous pousser dans la bonne direction.

Articles connexes


Redirection Spring MVC vers jsp pour une URL spécifique

Gautam Kumar J'utilise Spring MVC pour le projet AngularJS. Je sers JSON à partir de l'URL préfixée par "/ rest / *". Tous les fichiers jsp sont accessibles directement et le routage est géré en utilisant angular-js. Je dois faire des validations personnalisée

Comment faire une redirection?

MrAndy Comment rediriger de http://127.0.0.1:8000/accounts/signin/ vers http://127.0.0.1:8000/profile/ avec HttpResponseRedirect Hayden Eastwood En supposant que vous avez correctement configuré votre fichier urls.py, il devrait s'agir simplement de: HttpRes

Comment rediriger vers une URL spécifique

Gamelle J'ai le code suivant: public function numbergrouppost() { $groupname = Input::get('groupname'); $no_of_members = Input::get('no_of_members'); $create = Group::create([

.htaccess redirection vers une route spécifique

Dhimant Jadeja J'ai besoin de rediriger un ensemble de pages spécifiques avec des paramètres particuliers dans l'URL. Je connais un peu les redirections .htaccess mais celle-ci me donne mal à la tête. Je souhaite rediriger https://www.xxxxxx.com/index.php?page

Comment faire une requête rapide vers une URL spécifique

Martin Kostadinov Je suis nouveau dans la programmation rapide et j'ai besoin d'aide. Je veux savoir comment je peux faire une requête get sur une URL spécifique et enregistrer les données de réponse dans une variable. Je suis désolé de ne pas pouvoir vous mon