Skip to content

Commit

Permalink
Merge pull request #24 from davisski/issue/23
Browse files Browse the repository at this point in the history
#23 - Now pushing product id to cart.
  • Loading branch information
davisski committed Aug 1, 2022
2 parents 84c4bd5 + e50a24e commit 51dbad3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/ProductDisplay.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ app.component("product-display", {
methods: {
addToCart() {
if (this.variants[this.selectedVariant].quantity > 0) {
this.$emit("add-to-cart");
this.$emit("add-to-cart", this.variants[this.selectedVariant].id);
}
},
updateSelected(sock) {
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<body>
<div id="app">
<div class="nav-bar"></div>
<div class="cart">Cart ({{ cart }})</div>
<product-display @add-to-cart="updateCart()"></product-display>
<div class="cart">Cart ({{ cart.length }})</div>
<product-display @add-to-cart="updateCart"></product-display>
</div>

<!-- Import Js -->
Expand Down
6 changes: 3 additions & 3 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const app = Vue.createApp({
data() {
return {
cart: 0,
cart: [],
};
},
methods: {
updateCart() {
this.cart += 1;
updateCart(id) {
this.cart.push(id);
},
},
});

0 comments on commit 51dbad3

Please sign in to comment.