Browse files

[FIX] website_sale: correctly set access token for cart recovery

The access token is automatically generated when calling `_get_share_url` but
for the cart recovery we don't use that standard method because we need to send
the user to a specific route, so we need to generate the access token manually.

Without this fix, the user will receive the link with access_token=False which
would lead to a 404 page.

Also added a test for the cart recovery flow.

PR: #30000
  • Loading branch information...
seb-odoo committed Jan 10, 2019
1 parent f0e92de commit 9fe3d26b89e55c6cd430d9d9466ef3482321134b
@@ -312,6 +312,7 @@ def _cart_accessories(self):

def action_recovery_email_send(self):
composer_form_view_id = self.env.ref('mail.email_compose_message_wizard_form').id
default_template = self.env.ref('website_sale.mail_template_sale_cart_recovery', raise_if_not_found=False)
@@ -0,0 +1,93 @@
odoo.define('website_sale.tour_shop_cart_recovery', function (require) {
'use strict';

var base = require('web_editor.base');
var localStorage = require('web.local_storage');
var rpc = require('web.rpc');
var tour = require('web_tour.tour');

var orderIdKey = 'website_sale.tour_shop_cart_recovery.orderId';
var recoveryLinkKey = 'website_sale.tour_shop_cart_recovery.recoveryLink';

tour.register('shop_cart_recovery', {
test: true,
url: '/shop?search=Acoustic Bloc Screens',
wait_for: base.ready(),
content: "select Acoustic Bloc Screens",
trigger: '.oe_product_cart a:containsExact("Acoustic Bloc Screens")',
content: "click add to cart",
trigger: '#product_details #add_to_cart',
content: "check product is in cart, get cart id, logout, go to login",
trigger: '"Acoustic Bloc Screens")',
run: function () {
'model': 'website',
'method': 'sale_get_order',
'args': [[$('html').data('website-id')]],
}).then(function (data) {
var orderId = parseInt(data.match(/sale\.order\((\d+),\)/)[1]);
localStorage.setItem(orderIdKey, orderId);
window.location.href = "/web/session/logout?redirect=/web/login";
content: "login as admin and go to the SO (backend)",
trigger: '.oe_login_form',
run: function () {
var orderId = localStorage.getItem(orderIdKey);
var url = "/web#action=sale.action_orders&view_type=form&id=" + orderId;
var $loginForm = $('.oe_login_form');
content: "click action",
trigger: '.btn:containsExact("Action")',
content: "click Send a Cart Recovery Email",
trigger: 'a:containsExact("Send a Cart Recovery Email")',
content: "click Send email",
trigger: '.btn[name="action_send_mail"]',
content: "check the mail is sent, grab the recovery link, and logout",
trigger: '.o_thread_message_content a:containsExact("Resume order")',
run: function () {
var link = $('.o_thread_message_content a:containsExact("Resume order")').attr('href');
localStorage.setItem(recoveryLinkKey, link);
window.location.href = "/web/session/logout?redirect=/";
content: "go to the recovery link",
trigger: 'a[href="/web/login"]',
run: function () {
window.location.href = localStorage.getItem(recoveryLinkKey);
content: "check the page is working, click on restore",
extra_trigger: 'p:contains("This is your current cart")',
trigger: 'p:contains("restore") a:contains("Click here")',
content: "check product is in restored cart",
trigger: '"Acoustic Bloc Screens")',
run: function () {},
@@ -1,5 +1,6 @@
from . import test_customize
from . import test_sale_process
from . import test_website_sale_cart_recovery
from . import test_website_sale_mail
from . import test_website_sale_pricelist
from . import test_website_sale_product_attribute_value_config
@@ -0,0 +1,13 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo.tests import tagged
from odoo.tests.common import HttpCase

@tagged('post_install', '-at_install')
class TestWebsiteSaleCartRecovery(HttpCase):

def test_01_shop_cart_recovery_tour(self):
"""The goal of this test is to make sure cart recovery works."""
self.browser_js("/", "['web_tour.tour'].run('shop_cart_recovery')", "['web_tour.tour'].tours.shop_cart_recovery.ready", login="portal")
@@ -46,6 +46,7 @@
<template id="assets_common" name="tour" inherit_id="web.assets_common">
<xpath expr="." position="inside">
<script type="text/javascript" src="/website_sale/static/src/js/website_sale_tour_shop.js"></script>
<script type="text/javascript" src="/website_sale/static/src/js/website_sale_tour_shop_cart_recovery.js"></script>
<script type="text/javascript" src="/website_sale/static/src/js/website_sale_tour_shop_mail.js"></script>

0 comments on commit 9fe3d26

Please sign in to comment.