Skip to content

[Shopping cart example] Use product instead of abbreviation #1104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/shopping-cart/components/Cart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<h2>Your Cart</h2>
<p v-show="!products.length"><i>Please add some products to cart.</i></p>
<ul>
<li v-for="p in products">
{{ p.title }} - {{ p.price | currency }} x {{ p.quantity }}
<li v-for="product in products">
{{ product.title }} - {{ product.price | currency }} x {{ product.quantity }}
</li>
</ul>
<p>Total: {{ total | currency }}</p>
Expand All @@ -23,8 +23,8 @@ export default {
checkoutStatus: 'checkoutStatus'
}),
total () {
return this.products.reduce((total, p) => {
return total + p.price * p.quantity
return this.products.reduce((total, product) => {
return total + product.price * product.quantity
}, 0)
}
},
Expand Down
8 changes: 4 additions & 4 deletions examples/shopping-cart/components/ProductList.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<template>
<ul>
<li v-for="p in products">
{{ p.title }} - {{ p.price | currency }}
<li v-for="product in products">
{{ product.title }} - {{ product.price | currency }}
<br>
<button
:disabled="!p.inventory"
@click="addToCart(p)">
:disabled="!product.inventory"
@click="addToCart(product)">
Add to cart
</button>
</li>
Expand Down
2 changes: 1 addition & 1 deletion examples/shopping-cart/store/getters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const cartProducts = state => {
return state.cart.added.map(({ id, quantity }) => {
const product = state.products.all.find(p => p.id === id)
const product = state.products.all.find(product => product.id === id)
return {
title: product.title,
price: product.price,
Expand Down
2 changes: 1 addition & 1 deletion examples/shopping-cart/store/modules/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const actions = {
const mutations = {
[types.ADD_TO_CART] (state, { id }) {
state.checkoutStatus = null
const record = state.added.find(p => p.id === id)
const record = state.added.find(product => product.id === id)
if (!record) {
state.added.push({
id,
Expand Down
2 changes: 1 addition & 1 deletion examples/shopping-cart/store/modules/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const mutations = {
},

[types.ADD_TO_CART] (state, { id }) {
state.all.find(p => p.id === id).inventory--
state.all.find(product => product.id === id).inventory--
}
}

Expand Down