The changes concern the following modules: - sale - sale_product_configurator - website_sale - website_sale_product_configurator When optional products are enabled and a user adds an item to the cart, the modal popup does not allow further modifications to the main product based on its template. If the user wants to change the color or the material, they have to close the popup, modify the product and open it back up. The same is applied when Add to Cart is active, and the user cannot configure the product at all after clicking the add to cart button. This change will make it possible to change the product variants without having to close the modal, and configure the product when using the "Add to cart" button when it's enabled. The added configuration step is needed for some cases like the following: 1. When adding a product that had variants directly from the /shop page before, the first variant was added by default and configuring it was impossible without explicitly going on the product's page and configuring it from there. This behaviour made no sense, and it's the reason the "optional products modal" (which should no longer be called that) is opened when the product is not configured even if there are no optional products. 2. When going through the product's page, and there are optional products enabled for the product getting configured, then it's nice but not necessary to be able to configure the product further while choosing and configuring the optional products. This doesn't add an extra step in any case, it just makes it possible to still configure your product in the modal. 3. If there are no optional products, the configuration made on the product's page is taken into account and the product is directly added to the cart without opening the modal, which is the same behaviour as previously. Only one modal is shown, depending on the situation: - For the website flow, if the product is not configured and has variants or has optional products (or both), a popup shows that allows for configuration + choosing and configuring optional products. - For the sales flow, there was already a configuration popup, so the optional products modal is only shown when there are optional products and replaces the first instead. Some tests were adapted to function with the new product configuration modal: - The steps checking for the text mentioned above are removed - Triggers were adapted to the modal for products that were previously added to cart with their default variant - Various other small adjustments task-2541663 closes odoo/odoo#73086 Signed-off-by: Romain Derie <rdeodoo@users.noreply.github.com>
36 lines
2.1 KiB
Python
36 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class VariantController(http.Controller):
|
|
@http.route(['/sale/get_combination_info'], type='json', auth="user", methods=['POST'])
|
|
def get_combination_info(self, product_template_id, product_id, combination, add_qty, pricelist_id, **kw):
|
|
combination = request.env['product.template.attribute.value'].browse(combination)
|
|
pricelist = self._get_pricelist(pricelist_id)
|
|
ProductTemplate = request.env['product.template']
|
|
if 'context' in kw:
|
|
ProductTemplate = ProductTemplate.with_context(**kw.get('context'))
|
|
product_template = ProductTemplate.browse(int(product_template_id))
|
|
res = product_template._get_combination_info(combination, int(product_id or 0), int(add_qty or 1), pricelist)
|
|
if 'parent_combination' in kw:
|
|
parent_combination = request.env['product.template.attribute.value'].browse(kw.get('parent_combination'))
|
|
if not combination.exists() and product_id:
|
|
product = request.env['product.product'].browse(int(product_id))
|
|
if product.exists():
|
|
combination = product.product_template_attribute_value_ids
|
|
res.update({
|
|
'is_combination_possible': product_template._is_combination_possible(combination=combination, parent_combination=parent_combination),
|
|
'parent_exclusions': product_template._get_parent_attribute_exclusions(parent_combination=parent_combination)
|
|
})
|
|
return res
|
|
|
|
@http.route(['/sale/create_product_variant'], type='json', auth="user", methods=['POST'])
|
|
def create_product_variant(self, product_template_id, product_template_attribute_value_ids, **kwargs):
|
|
return request.env['product.template'].browse(int(product_template_id)).create_product_variant(product_template_attribute_value_ids)
|
|
|
|
def _get_pricelist(self, pricelist_id, pricelist_fallback=False):
|
|
return request.env['product.pricelist'].browse(int(pricelist_id or 0))
|