Last active
June 3, 2019 00:32
-
-
Save john-raymon/71b86e594d963c21bb5b4f7187aeb4bb to your computer and use it in GitHub Desktop.
ComponentDidMount App Commerce.js Demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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