Skip to content

Commit

Permalink
Merge 36a0fa2 into a615252
Browse files Browse the repository at this point in the history
  • Loading branch information
italo-batista committed May 24, 2019
2 parents a615252 + 36a0fa2 commit 1033323
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 1 deletion.
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]
### Added
- Send cart events to Pixel Manager when updating quantity of product.

## [2.21.0] - 2019-05-21
### Fixed
Expand Down
3 changes: 2 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"vtex.store-components": "3.x",
"vtex.store-resources": "0.x",
"vtex.product-review-interfaces": "1.x",
"vtex.styleguide": "9.x"
"vtex.styleguide": "9.x",
"vtex.pixel-manager": "0.x"
}
}
9 changes: 9 additions & 0 deletions react/__mocks__/vtex.pixel-manager/PixelContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from 'react'

export function Pixel(Comp) {
return class extends React.Component {
render() {
return <Comp {...this.props} push={() => {}} subscribe={() => {}} />
}
}
}
29 changes: 29 additions & 0 deletions react/legacy/components/ProductQuantityStepper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { Component } from 'react'
import { path } from 'ramda'
import PropTypes from 'prop-types'
import { NumericStepper, withToast } from 'vtex.styleguide'
import { Pixel } from 'vtex.pixel-manager/PixelContext'
import { debounce } from 'lodash'
import { injectIntl, intlShape } from 'react-intl'
import { compose, graphql } from 'react-apollo'
Expand Down Expand Up @@ -29,6 +31,28 @@ class ProductQuantityStepper extends Component {
canIncrease: true,
}

pushPixelCartEvents = ({ isAdditionOfProd, product }) => {
const updatedProduct = {
id: path(['sku', 'itemId'], product),
name: path(['productName'], product),
skuName: path(['sku', 'name'], product),
price: path(['assemblyOptions', 'parentPrice'], product),
quantity: path(['quantity'], product),
}
if (isAdditionOfProd) {
this.props.push({
event: 'addToCart',
items: [updatedProduct],
})
} else {
// removal of product
this.props.push({
event: 'removeFromCart',
items: [updatedProduct],
})
}
}

componentDidUpdate = prevProps => {
const {
product: { quantity: prevQuantity },
Expand All @@ -39,6 +63,10 @@ class ProductQuantityStepper extends Component {
intl,
} = this.props
if (prevQuantity !== quantity) {
this.pushPixelCartEvents({
isAdditionOfProd: prevQuantity < quantity,
product: this.props.product,
})
const canIncrease = quantity === this.state.quantity
this.setState({ quantity, canIncrease })
if (!canIncrease) {
Expand Down Expand Up @@ -106,6 +134,7 @@ const withUpdateItemsMutation = graphql(UPDATE_ITEMS_MUTATION, {
})

export default compose(
Pixel,
injectIntl,
withToast,
withUpdateItemsMutation
Expand Down

0 comments on commit 1033323

Please sign in to comment.