[WIP] nfu_ecommerce: add max_qty to Product Configurator

This commit is contained in:
Niels Göttsch 2025-02-14 11:39:18 +01:00 committed by madmooose
parent 1544065c45
commit 7743649824
4 changed files with 99 additions and 9 deletions

View file

@ -6,12 +6,18 @@
"category": "website",
"version": "16.0.1.2.0",
"depends": [
"sale_product_configurator",
"website_sale",
"nfu_sale_order_batch_packaging",
"website_decimal_quantity",
"nfu_product_bnn_attributes",
],
"data": ["views/product_template_views.xml", "views/templates.xml"],
"assets": {"web.assets_frontend": ["nfu_ecommerce/static/src/js/website_sale.js"]},
"assets": {
"web.assets_frontend": [
"nfu_ecommerce/static/src/js/website_sale.js",
"nfu_ecommerce/static/src/js/sale_product_configurator.js",
]
},
"license": "LGPL-3",
}

View file

@ -0,0 +1,37 @@
odoo.define("nfu_ecommerce.sale_product_configurator", function (require) {
"use strict";
var ProductConfiguratorMixin = require("sale_product_configurator.ProductConfiguratorMixin");
var publicWidget = require("web.public.widget");
publicWidget.registry.ProductConfigurator = publicWidget.Widget.extend(ProductConfiguratorMixin, {
selector: ".oe_website_sale",
events: _.extend({}, publicWidget.Widget.prototype.events, {
'change input[name="add_max_qty"]': "_onChangeAddMaxQty",
}),
/**
* @private
* @param {Event} ev
*/
_onChangeAddMaxQty: function (ev) {
var $input = $(ev.currentTarget);
var lineId = $input.data("line-id");
var productId = $input.data("product-id");
var addMaxQty = $input.val();
this._rpc({
route: "/shop/cart/update",
params: {
line_id: lineId,
product_id: productId,
add_max_qty: addMaxQty,
},
}).then(function (result) {
if (result) {
window.location.reload();
}
});
},
});
});

View file

@ -4,6 +4,11 @@ odoo.define("nfu_ecommerce.website_max_qty", function (require) {
var wSaleUtils = require("website_sale.utils");
var publicWidget = require("web.public.widget");
require("website_sale.website_sale");
/**
* ToDO att_submitForm methode overwrite
* see Cybros addon for example
*/
publicWidget.registry.WebsiteSale.include({
/**
* Adds the max qty to the POST request when adding a product to the cart.
@ -15,8 +20,8 @@ odoo.define("nfu_ecommerce.website_max_qty", function (require) {
productIDs.push($(elem).find("span[data-product-id]").data("product-id"));
});
$input.data("update_change", true);
var max_qty = parseFloat($input.closest("tr").find('input[name="max-qty"]').val(), 10);
var set_qty = parseFloat($input.closest("tr").find('input[name!="max-qty"]').val(), 10);
var max_qty = parseFloat($input.closest("tr").find('input[name="max-qty"]').val());
var set_qty = parseFloat($input.closest("tr").find('input[name!="max-qty"]').val());
if (max_qty < set_qty) {
max_qty = set_qty;
}
@ -30,7 +35,7 @@ odoo.define("nfu_ecommerce.website_max_qty", function (require) {
},
}).then(function (data) {
$input.data("update_change", false);
var check_value = parseFloat($input.val() || 0, 10);
var check_value = parseFloat($input.val() || 0);
if (isNaN(check_value)) {
check_value = 1;
}

View file

@ -2,18 +2,20 @@
<odoo>
<template id="products_open_packaging" inherit_id="website_sale.products">
<xpath expr="//aside[@id='products_grid_before']/div[1]/div[1]" position="before">
<xpath expr="//div[hasclass('products_attributes_filters')]" position="after">
<div class="mt-3">
<a t-att-href="keep('/shop',open_packagings = False if open_packagings else True)">
<h6 t-attf-class="o_packaging_collapse_title mb-3 {{_titleClasses}}"><b>
<span t-if="open_packagings">All Products</span>
<span t-else="">Open Packagings</span>
</b></h6>
</a>
</div>
</xpath>
</template>
<template id="o_wsale_offcanvas" name="Open Packagings" inherit_id="website_sale.o_wsale_offcanvas">
<xpath expr="//div[@id='o_wsale_offcanvas_content']/div[1]" position="before">
<xpath expr="//t[@t-call='website_sale.filter_products_price']" position="before">
<div class="position-relative o_wsale_offcanvas_title px-4 border-top">
<a t-att-href="keep('/shop',open_packagings = False if open_packagings else True)">
<h6 t-attf-class="o_packaging_collapse_title mb-3 pt-3 {{_titleClasses}}"><b>
@ -79,6 +81,35 @@
</xpath>
</template>
<template id="product_max_quantity_config">
<div class="css_quantity input-group">
<button
t-attf-href="#"
class="btn btn-primary float_left js_add_cart_json d-none d-md-inline-block"
aria-label="Remove one"
title="Remove one"
>
<i class="fa fa-minus"/>
</button>
<input
type="text"
class="js_quantity form-control quantity text-center"
style="max-width: 4rem"
data-min="1"
name="add_max_qty"
t-att-value="add_max_qty or 1"
/>
<button
t-attf-href="#"
class="btn btn-primary float_left js_add_cart_json d-none d-md-inline-block"
aria-label="Add one"
title="Add one"
>
<i class="fa fa-plus"/>
</button>
</div>
</template>
<template id="cart_lines_packaging" inherit_id="website_sale.cart_lines" name="Shopping Cart Lines">
<xpath expr="//td[hasclass('td-product_name')]" position="inside">
<div t-if="line.product_packaging_id and (line.product_packaging_id.qty != 1)">
@ -168,6 +199,17 @@
</xpath>
</template>
<template id="configure_optional_products" inherit_id="sale_product_configurator.configure_optional_products">
<xpath expr="//th[hasclass('td-qty')]" position="after">
<th class="text-center td-max-qty"><span class='label'>Max Quantity</span></th>
</xpath>
<xpath expr="//td[hasclass('td-qty')]" position="after">
<td class="text-center td-max-qty">
<t t-call='nfu_ecommerce.product_max_quantity_config'/>
</td>
</xpath>
</template>
<template id="cart_summary_packaging" inherit_id="website_sale.cart_summary" name="Cart right column">
<xpath expr="//td[hasclass('td-product_name')]" position="inside">
<div t-if="line.product_packaging_id and (line.product_packaging_id.qty != 1)">