[FIX] website_sale: open configurator with only no variants attributes

Before this commit, the product configurator dialog was not shown when
adding to the cart, a product with only no variant attribute values,
using the buy button on the '/shop' page.

Now, if the product has configurable attributes (custom attribute, no
variant, and dynamic attribute can now be selected), the product
configurator dialog is shown.

opw-3736469

closes odoo/odoo#157737

Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Valentin Chevalier
2024-03-15 17:29:54 +00:00
committed by Victor Feyens
parent 43c0f6ea11
commit 436c1c666b
6 changed files with 175 additions and 4 deletions
@@ -22,7 +22,7 @@ class WebsiteSaleProductConfiguratorController(Controller):
already_configured = bool(combination)
if not force_dialog and not has_optional_products and (
product.product_variant_count <= 1 or already_configured
not product.has_configurable_attributes or already_configured
):
# The modal is not shown if there are no optional products and
# the main product either has no variants or is already configured
@@ -0,0 +1,29 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import tourUtils from "@website_sale/js/tours/tour_utils";
registry.category("web_tour.tours").add('tour_configurator_quick_add_only_no_dynamic_attributes', {
test: true,
url: '/shop',
steps: () => [
...tourUtils.searchProduct("Short (TEST)"),
{
content: "open configurator",
trigger: '.oe_product:has(a:contains("Short (TEST)")) div.o_wsale_product_btn a',
},
{
content: "select M dynamic attribute",
trigger: '.oe_advanced_configurator_modal label:contains("M dynamic") input',
},
{
content: "Go through the modal window of the product configurator",
extra_trigger: '.oe_advanced_configurator_modal strong:contains("Short (TEST) (M dynamic)")',
trigger: 'button span:contains(Proceed to Checkout)',
},
tourUtils.assertCartContains({
productName: 'Short (TEST) (M dynamic)',
backend: false,
}),
]
});
@@ -0,0 +1,29 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import tourUtils from "@website_sale/js/tours/tour_utils";
registry.category("web_tour.tours").add('tour_configurator_quick_add_only_no_variant_attributes', {
test: true,
url: '/shop',
steps: () => [
...tourUtils.searchProduct("Short (TEST)"),
{
content: "open configurator",
trigger: '.oe_product:has(a:contains("Short (TEST)")) div.o_wsale_product_btn a',
},
{
content: "select M dynamic attribute",
trigger: '.oe_advanced_configurator_modal label:contains("M never") input',
},
{
content: "Go through the modal window of the product configurator",
trigger: 'button span:contains(Continue Shopping)',
},
{
content: "check that the novariants/custom attributes are displayed.",
trigger: '.toast-body span.text-muted.small:contains("Never attribute size: M never")',
isCheck: true,
},
]
});
@@ -0,0 +1,29 @@
/** @odoo-module **/
import { registry } from "@web/core/registry";
import tourUtils from "@website_sale/js/tours/tour_utils";
registry.category("web_tour.tours").add('tour_configurator_quick_add_single_custom_attribute', {
test: true,
url: '/shop',
steps: () => [
...tourUtils.searchProduct("Short (TEST)"),
{
content: "open configurator",
trigger: '.oe_product:has(a:contains("Short (TEST)")) div.o_wsale_product_btn a',
},
{
trigger: 'input.variant_custom_value',
run: 'text TEST',
},
{
content: "Go through the modal window of the product configurator",
trigger: 'button span:contains(Continue Shopping)',
},
{
content: "check that the novariants/custom attributes are displayed.",
trigger: '.toast-body span.text-muted.small:contains("Always attribute size: Yes never custom: TEST")',
isCheck: true,
},
]
});
@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.fields import Command
from odoo.tests import tagged
from odoo.addons.base.tests.common import HttpCaseWithUserDemo, HttpCaseWithUserPortal
from odoo.addons.sale_product_configurator.tests.common import TestProductConfiguratorCommon
from odoo.addons.base.tests.common import HttpCaseWithUserPortal, HttpCaseWithUserDemo
@tagged('post_install', '-at_install')
@@ -146,3 +147,86 @@ class TestWebsiteSaleProductConfigurator(TestProductConfiguratorCommon, HttpCase
new_sale_order = self.env['sale.order'].search([]) - old_sale_order
new_order_line = new_sale_order.order_line
self.assertEqual(new_order_line.name, 'Short (TEST) (M always, M dynamic)\n\nNever attribute size: M never\nNever attribute size custom: Yes never custom: TEST')
def test_03_only_no_variant_attributes(self):
""" Test that the configurator dialog is opened when a product with only no variant
attributes is added from the /shop page.
"""
self.env.ref('website_sale.products_add_to_cart').active = True # Enable quick add button
no_variant_attribute = self.env['product.attribute'].create({
'name': 'Never attribute size',
'display_type': 'radio',
'create_variant': 'no_variant',
'value_ids': [
Command.create({'name': 'S never'}),
Command.create({'name': 'M never'}),
]
})
self.env['product.template'].create({
'name': 'Short (TEST)',
'website_published': True,
'attribute_line_ids': [
Command.create({
'attribute_id': no_variant_attribute.id,
'value_ids': [Command.set(no_variant_attribute.value_ids.ids)],
})
],
})
self.start_tour("/shop", 'tour_configurator_quick_add_only_no_variant_attributes')
def test_04_only_dynamic_attributes(self):
""" Test that the configurator dialog is opened when a product with only dynamic
attributes is added from the /shop page.
"""
self.env.ref('website_sale.products_add_to_cart').active = True # Enable quick add button
dynamic_attribute = self.env['product.attribute'].create({
'name': 'Dynamic attribute size',
'display_type': 'radio',
'create_variant': 'dynamic',
'value_ids': [
Command.create({'name': 'S dynamic'}),
Command.create({'name': 'M dynamic'}),
]
})
self.env['product.template'].create({
'name': 'Short (TEST)',
'website_published': True,
'attribute_line_ids': [
Command.create({
'attribute_id': dynamic_attribute.id,
'value_ids': [Command.set(dynamic_attribute.value_ids.ids)],
})
],
})
self.start_tour("/shop", 'tour_configurator_quick_add_only_no_dynamic_attributes')
def test_05_single_custom_attribute(self):
""" Test that the configurator dialog is opened when a product with a single custom
attributes is added from the /shop page.
"""
self.env.ref('website_sale.products_add_to_cart').active = True # Enable quick add button
attribute = self.env['product.attribute'].create({
'name': 'Always attribute size',
'display_type': 'radio',
'create_variant': 'always',
'value_ids': [
Command.create({
'name': 'Yes never custom',
'is_custom': True,
}),
]
})
self.env['product.template'].create({
'name': 'Short (TEST)',
'website_published': True,
'attribute_line_ids': [
Command.create({
'attribute_id': attribute.id,
'value_ids': [Command.set(attribute.value_ids.ids)],
})
],
})
self.start_tour("/shop", 'tour_configurator_quick_add_single_custom_attribute')
@@ -77,7 +77,7 @@
<t t-if="product and not combination">
<t t-set="combination" t-value="product_template._get_first_possible_combination()"/>
</t>
<t t-if="combination and not already_configured" t-call="website_sale.variants">
<t t-if="not already_configured" t-call="website_sale.variants">
<t t-set="ul_class" t-valuef="flex-column" />
<t t-set="product" t-value="product_template"/>
</t>