Skip to content

Instantly share code, notes, and snippets.

@john-raymon
Last active June 3, 2019 00:32
Show Gist options
  • Select an option

  • Save john-raymon/71b86e594d963c21bb5b4f7187aeb4bb to your computer and use it in GitHub Desktop.

Select an option

Save john-raymon/71b86e594d963c21bb5b4f7187aeb4bb to your computer and use it in GitHub Desktop.
ComponentDidMount App Commerce.js Demo
componentDidMount() {
const {
commerce
} = this.props
if (commerce !== undefined && typeof commerce !== 'undefined') {
// invoke commerce products method to get all products
commerce.Products.list(
(resp) => {
//Success
this.setState({
products: resp.data
})
},
(error) => {
// handle error properly in real-world
}
);
window.addEventListener("Commercejs.Cart.Ready", function (e) {
// invoke commerce cart method to retrieve cart in session=
commerce.Cart.retrieve((resp) => {
if (!resp.error) {
return this.setState({
cart: resp
})
});
}
}.bind(this))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment