Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions functions/ecom.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,22 @@ const app = {
"default": false,
"title": "Frete grátis"
},
"product_ids": {
"title": "Lista de produtos selecionados",
"description": "Se preenchido, a regra de envio estará disponível apenas se pelo menos um destes produtos estiver no carrinho",
"type": "array",
"items": {
"type": "string",
"pattern": "^[a-f0-9]{24}$",
"title": "ID do produto"
}
},
"all_product_ids": {
"type": "boolean",
"title": "Checar todos os produtos",
"description": "Se ativo, a regra será disponibilizada apenas se todos os itens do carrinho estiverem na lista de produtos selecionados",
"default": false
},
Comment on lines +322 to +337
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esse trem vai ser pouco usado, deveria estar no final da config da regra

Comment on lines +332 to +337
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisa mesmo dessa segunda opção aqui? Quer dizer, tem cenário pra ambos os casos? Com algum produto na lista e com todos os produtos na lista?

"discount": {
"title": "Desconto",
"type": "object",
Expand Down
8 changes: 8 additions & 0 deletions functions/routes/ecom/modules/calculate-shipping.js
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,18 @@ exports.post = async ({ appSdk }, req, res) => {
if (Array.isArray(appData.shipping_rules)) {
for (let i = 0; i < appData.shipping_rules.length; i++) {
const rule = appData.shipping_rules[i]
let hasProduct
if (Array.isArray(rule.product_ids) && rule.product_ids.length) {
const isAllProducts = rule.all_product_ids
hasProduct = isAllProducts
? params.items.every(item => rule.product_ids.indexOf(item.product_id) > -1)
: params.items.some(item => rule.product_ids.indexOf(item.product_id) > -1)
}
if (
rule &&
(!rule.service_code || rule.service_code === coProduto) &&
checkZipCode(rule) &&
(!rule.product_ids || hasProduct) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(!rule.product_ids || hasProduct) &&
(!rule.product_ids || !rule.product_ids.length || hasProduct) &&

!(rule.min_amount > params.subtotal)
) {
// valid shipping rule
Expand Down