Skip to content

Commit

Permalink
Merge pull request #48 from vtex-apps/fix-price-int
Browse files Browse the repository at this point in the history
Fix price being sent as integer instead of float
  • Loading branch information
Breno Calazans authored Mar 17, 2021
2 parents 830de80 + db24f74 commit f67ea40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Property `price` being sent as `integer` in `addToCart` event when using the block `add-to-cart-button`.

## [2.9.0] - 2021-01-18
### Added
Expand Down
33 changes: 17 additions & 16 deletions react/modules/enhancedEcommerceEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
ProductOrder,
Impression,
CartItem,
AddToCartData,
RemoveToCartData,
} from '../typings/events'
import { AnalyticsEcommerceProduct } from '../typings/gtm'

Expand Down Expand Up @@ -46,9 +48,7 @@ export function sendEnhancedEcommerceEvents(e: PixelMessage) {

case 'vtex:productClick': {
const { productName, brand, categories, sku } = e.data.product
const list = e.data.list
? { actionField: { list: e.data.list } }
: {}
const list = e.data.list ? { actionField: { list: e.data.list } } : {}

let price

Expand Down Expand Up @@ -83,17 +83,18 @@ export function sendEnhancedEcommerceEvents(e: PixelMessage) {
}

case 'vtex:addToCart': {
const { items } = e.data
const { items } = e.data as AddToCartData

push({
ecommerce: {
add: {
products: items.map((sku: any) => ({
products: items.map(sku => ({
brand: sku.brand,
category: sku.category,
id: sku.skuId,
name: sku.name,
price: `${sku.price}`,
price:
sku.priceIsInt === true ? `${sku.price / 100}` : `${sku.price}`,
quantity: sku.quantity,
variant: sku.variant,
})),
Expand All @@ -107,18 +108,19 @@ export function sendEnhancedEcommerceEvents(e: PixelMessage) {
}

case 'vtex:removeFromCart': {
const { items } = e.data
const { items } = e.data as RemoveToCartData

push({
ecommerce: {
currencyCode: e.data.currency,
remove: {
products: items.map((sku: any) => ({
products: items.map(sku => ({
brand: sku.brand,
id: sku.skuId,
category: sku.category,
name: sku.name,
price: `${sku.price}`,
price:
sku.priceIsInt === true ? `${sku.price / 100}` : `${sku.price}`,
quantity: sku.quantity,
variant: sku.variant,
})),
Expand Down Expand Up @@ -212,9 +214,9 @@ export function sendEnhancedEcommerceEvents(e: PixelMessage) {
event: 'promoView',
ecommerce: {
promoView: {
promotions: promotions
}
}
promotions,
},
},
})
break
}
Expand All @@ -226,9 +228,9 @@ export function sendEnhancedEcommerceEvents(e: PixelMessage) {
event: 'promotionClick',
ecommerce: {
promoClick: {
promotions: promotions
}
}
promotions,
},
},
})
break
}
Expand All @@ -239,7 +241,6 @@ export function sendEnhancedEcommerceEvents(e: PixelMessage) {
}
}


function getPurchaseObjectData(order: Order) {
return {
affiliation: order.transactionAffiliation,
Expand Down
1 change: 1 addition & 0 deletions react/typings/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ interface CartItem {
name: string
skuName: string
price: number
priceIsInt?: boolean
sellingPrice: number
productId: string
productRefId: string
Expand Down

0 comments on commit f67ea40

Please sign in to comment.