diff --git a/emails/ecommerce/makeorder/it/html.pug b/emails/ecommerce/makeorder/it/html.pug
index b6b1649..0e6351b 100755
--- a/emails/ecommerce/makeorder/it/html.pug
+++ b/emails/ecommerce/makeorder/it/html.pug
@@ -44,6 +44,7 @@ html
- var img = product.order.product.img
- var price = product.order.price
- var after_price = product.order.after_price
+ - var gasordine = product.order.gasordine.name
- var qty = product.order.quantity
- var qtypreordered = product.order.quantitypreordered
- index = index + 1
@@ -61,6 +62,10 @@ html
td(class="column", valign="top")
table(cellpadding="0", cellspacing="0", summary="", border="0")
+ if (qtypreordereded > 0)
+ tr
+ td(class="sectionContent", valign="top")
+ p Gas Ordine: #{gasordine}
tr
td(class="sectionContentTitle boldhigh", valign="top")
p #{descr}
diff --git a/emails/ecommerce/order_confirmed/it/html.pug b/emails/ecommerce/order_confirmed/it/html.pug
index 2a1f0ae..57bfa16 100755
--- a/emails/ecommerce/order_confirmed/it/html.pug
+++ b/emails/ecommerce/order_confirmed/it/html.pug
@@ -44,6 +44,7 @@ html
- var img = product.order.product.img
- var price = product.order.product.price
- var after_price = product.order.product.after_price
+ - var gasordine = product.order.gasordine.name
- var qty = product.order.product.quantity
- var qtypreordered = product.order.quantitypreordered
- index = index + 1
@@ -61,6 +62,10 @@ html
td(class="column", valign="top")
table(cellpadding="0", cellspacing="0", summary="", border="0")
+ if (qtypreordereded > 0)
+ tr
+ td(class="sectionContent", valign="top")
+ p Gas Ordine: #{gasordine}
tr
td(class="sectionContentTitle boldhigh", valign="top")
p #{descr}
diff --git a/src/server/models/order.js b/src/server/models/order.js
index 7738984..3e8d3e0 100755
--- a/src/server/models/order.js
+++ b/src/server/models/order.js
@@ -178,6 +178,11 @@ module.exports.findAllIdApp = async function (idapp) {
as: 'gasordine'
}
},
+ {
+ $match: {
+ 'gasordine.active': true
+ }
+ },
{
$lookup: {
from: 'scontisticas',
@@ -369,6 +374,11 @@ module.exports.getTotalOrderById = async function (id) {
as: 'gasordine'
}
},
+ {
+ $match: {
+ 'gasordine.active': true
+ }
+ },
{
$lookup: {
from: 'scontisticas',
diff --git a/src/server/models/product.js b/src/server/models/product.js
index bee858c..70a4ba9 100755
--- a/src/server/models/product.js
+++ b/src/server/models/product.js
@@ -100,6 +100,7 @@ const productSchema = new Schema({
minBuyQty: { // quantità minima acquistabile
type: Number,
default: 1,
+ required: true,
},
stockQty: { // in magazzino
type: Number,
@@ -175,7 +176,7 @@ module.exports.getFieldsForSearch = function () {
return [
{ field: 'name', type: tools.FieldType.string },
{ field: 'description', type: tools.FieldType.string },
-]
+ ]
};
module.exports.executeQueryTable = function (idapp, params) {
@@ -251,6 +252,34 @@ module.exports.findAllIdApp = async function (idapp, code, id) {
as: 'gasordines'
}
},
+ {
+ $unwind: {
+ path: '$gasordines',
+ preserveNullAndEmptyArrays: true,
+ },
+ },
+ {
+ $match: {
+ $or: [
+ { 'gasordines.active': true }, // Include documents where gasordines.active is true
+ { 'gasordines': { $exists: false } } // Include documents where gasordines array doesn't exist
+ ]
+ }
+ },
+ {
+ $group: {
+ _id: '$_id',
+ gasordines: { $push: '$gasordines' },
+ originalFields: { $first: '$$ROOT' } // Preserve all existing fields
+ }
+ },
+ {
+ $replaceRoot: {
+ newRoot: {
+ $mergeObjects: ['$originalFields', { gasordines: '$gasordines' }]
+ }
+ }
+ },
{
$unwind: {
path: '$producer',
@@ -438,10 +467,10 @@ module.exports.getProductByID = function (id, callback) {
}
module.exports.updateProductInOrder = async function (order) {
-
+
if (order.product)
order.product = await Product.getProductById(order.product._id);
-
+
return order;
}
@@ -467,6 +496,7 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod) {
let objtoset = {
idapp,
img: 'upload/products/' + prod.code + '.jpg',
+ minBuyQty: 1,
}
if (prod.producer_name) {
@@ -552,5 +582,5 @@ module.exports.singlerecconvert_AfterImport = async function (idapp, prod) {
} catch (e) {
console.error('Err', e);
}
-
+
}
\ No newline at end of file
diff --git a/src/server/modules/Cart.js b/src/server/modules/Cart.js
index f1337ab..44a811f 100755
--- a/src/server/modules/Cart.js
+++ b/src/server/modules/Cart.js
@@ -58,10 +58,25 @@ class Cart {
async addqty(itemorder) {
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
if (!!myitem) {
+ let step = 1;
if (this.isAvailableByOrder(myitem.order)) {
- myitem.order.quantity += 1;
+ if (myitem.order.quantity === 0)
+ step = myitem.order.minBuyQty
+ else if (myitem.order.quantity >= 10)
+ step = 2
+ else if (myitem.order.quantity >= 20)
+ step = 5
+
+ myitem.order.quantity += step;
} else {
- myitem.order.quantitypreordered += myitem.order.product.minBuyQty;
+ if (myitem.order.quantitypreordered === 0)
+ step = myitem.order.minBuyQty
+ else if (myitem.order.quantitypreordered >= 10)
+ step = 2
+ else if (myitem.order.quantitypreordered >= 20)
+ step = 5
+
+ myitem.order.quantitypreordered += step;
}
this.updatetotals();
@@ -75,7 +90,7 @@ class Cart {
const myitem = this.items.find((rec) => rec.order._id.toString() === itemorder._id)
if (!!myitem) {
if (myitem.order.quantitypreordered > 0) {
- myitem.order.quantitypreordered -= myitem.order.product.minBuyQty;
+ myitem.order.quantitypreordered -= myitem.order.product.minBuyQty | 1;
} else {
if (myitem.order.quantity > 0) {
myitem.order.quantity--;