From bdc1c85d8a7af7696228ddd1c439cce49bc8454a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vitor=20Rocha=20Gon=C3=A7alves?= <35348281+vitorrgg@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:01:29 -0300 Subject: [PATCH 1/2] adding to total_price the additional_price when there is one --- .../routes/ecom/modules/calculate-shipping.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/functions/routes/ecom/modules/calculate-shipping.js b/functions/routes/ecom/modules/calculate-shipping.js index 9834460..5092d80 100644 --- a/functions/routes/ecom/modules/calculate-shipping.js +++ b/functions/routes/ecom/modules/calculate-shipping.js @@ -282,6 +282,22 @@ exports.post = async ({ appSdk }, req, res) => { flags: ['correios-api'] } + // check for default configured additional/discount price + if (typeof config.additional_price === 'number' && config.additional_price) { + if (config.additional_price > 0) { + shippingLine.other_additionals = [{ + tag: 'additional_price', + label: 'Adicional padrão', + price: config.additional_price + }] + } else { + // negative additional price to apply discount + shippingLine.discount -= config.additional_price + } + // update total price + shippingLine.total_price += config.additional_price + } + // search for discount by shipping rule if (Array.isArray(appData.shipping_rules)) { for (let i = 0; i < appData.shipping_rules.length; i++) { From a07bbcf2479d135521defe4df6885889edf0d031 Mon Sep 17 00:00:00 2001 From: Matheus Reis <35343551+matheusgnreis@users.noreply.github.com> Date: Fri, 26 Jan 2024 15:13:42 -0300 Subject: [PATCH 2/2] chore(calculate-shipping): use appData instead config --- functions/routes/ecom/modules/calculate-shipping.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/functions/routes/ecom/modules/calculate-shipping.js b/functions/routes/ecom/modules/calculate-shipping.js index 5092d80..9073754 100644 --- a/functions/routes/ecom/modules/calculate-shipping.js +++ b/functions/routes/ecom/modules/calculate-shipping.js @@ -283,19 +283,19 @@ exports.post = async ({ appSdk }, req, res) => { } // check for default configured additional/discount price - if (typeof config.additional_price === 'number' && config.additional_price) { - if (config.additional_price > 0) { + if (typeof appData.additional_price === 'number' && appData.additional_price) { + if (appData.additional_price > 0) { shippingLine.other_additionals = [{ tag: 'additional_price', label: 'Adicional padrão', - price: config.additional_price + price: appData.additional_price }] } else { // negative additional price to apply discount - shippingLine.discount -= config.additional_price + shippingLine.discount -= appData.additional_price } // update total price - shippingLine.total_price += config.additional_price + shippingLine.total_price += appData.additional_price } // search for discount by shipping rule