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
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
</label>
<input-doc-number
id="credit-card-doc"
:is-company="isCompany"
:allow-both="true"
v-model="card.doc"
:required="isPayerDocRequired"
/>
Expand Down
36 changes: 20 additions & 16 deletions @ecomplus/storefront-components/src/js/InputDocNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,40 @@ export default {
type: [String, Number],
required: true
},
isCompany: Boolean
isCompany: Boolean,
allowBoth: Boolean
},

computed: {
placeholder () {
return countryCode === 'BR'
? this.isCompany
? 'CNPJ'
: 'CPF'
: i18n(i19docNumber)
if (countryCode === 'BR') {
if (this.allowBoth) return 'CPF / CNPJ'
return this.isCompany ? 'CNPJ' : 'CPF'
}
return i18n(i19docNumber)
},

pattern () {
if (countryCode === 'BR') {
if (this.isCompany) {
return '[\\d]{2}\\..{15}'
} else {
return '[\\d]{3}\\..{10}'
}
if (this.allowBoth) return '[\\d]{11}|[\\d]{14}'
if (this.isCompany) return '[\\d]{2}\\..{15}'
return '[\\d]{3}\\..{10}'
Comment on lines +40 to +42

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nem sei se precisa ficar mudando pattern

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Mas acho que não é problema também

}
return '[\\d]+{9,19}'
},

isInvalid () {
if (countryCode === 'BR') {
const docNumber = this.localValue.toString().replace(/D/g, '')
const docNumber = this.localValue.toString().replace(/\D/g, '')
if (this.allowBoth) {
if (docNumber.length === 11) return !validateCPF(this.localValue)
if (docNumber.length === 14) return !validateCNPJ(this.localValue)
return false
}
const docNumberLegacy = this.localValue.toString().replace(/D/g, '')
if (this.isCompany) {
if (docNumber.length === 14) {
return !validateCNPJ(this.localValue)
}
} else if (docNumber.length === 11) {
if (docNumberLegacy.length === 14) return !validateCNPJ(this.localValue)
} else if (docNumberLegacy.length === 11) {
return !validateCPF(this.localValue)
}
}
Expand All @@ -69,6 +72,7 @@ export default {
},

cleaveOptions () {
if (this.allowBoth) return { blocks: [30] }

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Aqui vai deixar a visualização ruim, mas funciona...

return countryCode === 'BR'
? this.isCompany
? { blocks: [2, 3, 3, 4, 2], delimiters: ['.', '.', '/', '-'] }
Expand Down
2 changes: 1 addition & 1 deletion @ecomplus/widget-tag-manager/src/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getProductData = item => {
const productData = {
name,
id: item.sku,
price: getPrice(item).toFixed(2)
price: parseFloat(getPrice(item).toFixed(2))
}
if (variants && variants.length) {
productData.variant = variants.join(' / ')
Expand Down
8 changes: 4 additions & 4 deletions @ecomplus/widget-tag-manager/src/lib/watch-app-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ export default dataLayer => {
const { amount } = order || window.storefrontApp
const actionField = {
id: orderId,
revenue: (
revenue: parseFloat((
(amount && amount.total) ||
(ecomCart.data && ecomCart.data.subtotal) ||
0
).toFixed(2)
).toFixed(2))
}
if (amount) {
if (amount.freight !== undefined) {
actionField.shipping = amount.freight.toFixed(2)
actionField.shipping = parseFloat(amount.freight.toFixed(2))
}
if (amount.tax !== undefined) {
actionField.tax = amount.tax.toFixed(2)
actionField.tax = parseFloat(amount.tax.toFixed(2))
}
}

Expand Down
Loading