Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(add-item): permit insert flags when is the same product #187

Merged
merged 5 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
13 changes: 13 additions & 0 deletions src/lib/check-flags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default (item, newItem) => {
// check flags
const itemFlags = item.flags ? item.flags : false
const newItemFlags = newItem.flags ? newItem.flags : false
matheusgnreis marked this conversation as resolved.
Show resolved Hide resolved
if (!itemFlags && !newItemFlags) {
return true
} else if (!itemFlags && newItemFlags || itemFlags && !newItemFlags) {
Copy link
Member

Choose a reason for hiding this comment

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

esses AND e OR aqui estão ambíguos, teria que ter um parênteses na segunda parte

Copy link
Member

Choose a reason for hiding this comment

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

E o StandardJS te mostraria isso antes de mim inclusive..

Copy link
Member Author

Choose a reason for hiding this comment

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

Ue, eu estou com isso instalado no meu vs code

Copy link
Member

Choose a reason for hiding this comment

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

Tem que instalar as dependências (sempre) do repositório também
Fez isso?

return false
} else {
return itemFlags.every(flag => newItemFlags.includes(flag))
Copy link
Member

Choose a reason for hiding this comment

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

Dá pra passar, mas (FYI) isso não vai funcionar se itemFlags for um array vazio ou se tiver menos flags que o do novo item

Copy link
Member

Choose a reason for hiding this comment

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

E cagou indentação aqui, o que me leva a crer que não tá usando o linter 😞 , nem testando...

}
}

6 changes: 5 additions & 1 deletion src/methods/add-item.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { randomObjectId } from '@ecomplus/utils'
import checkFlags from '../lib/check-flags'
import fixItemQuantity from './../lib/fix-item-quantity'
import fixItemFinalPrice from './../lib/fix-item-final-price'
import fixSubtotal from './../lib/fix-subtotal'
Expand Down Expand Up @@ -38,6 +39,8 @@ export default ({ data, save }, emitter, [newItem, canSave = true]) => {
return null
}

const check

Comment on lines +42 to +43
Copy link
Member

Choose a reason for hiding this comment

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

😐

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

isso é um erro de sintaxe, não compila 🙃

Copy link
Member Author

Choose a reason for hiding this comment

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

estava com outro instalado

Copy link
Member Author

Choose a reason for hiding this comment

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

É, sei de onde brotou isso nao, devo ter copiado errado. Testei no meu local, mas nao conseguia subir por nao ter permissão, então copiei e coloquei direto no github

Copy link
Member Author

Choose a reason for hiding this comment

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

Foi mal

let fixedItem
if (!newItem.kit_product) {
for (let i = 0; i < data.items.length; i++) {
Expand All @@ -46,7 +49,8 @@ export default ({ data, save }, emitter, [newItem, canSave = true]) => {
!item.kit_product &&
item.product_id === newItem.product_id &&
item.variation_id === newItem.variation_id &&
(!item.customizations || !item.customizations.length)
(!item.customizations || !item.customizations.length) &&
checkFlags(item, newItem)
) {
item.quantity += newItem.quantity
if (newItem.price) {
Expand Down