-
Notifications
You must be signed in to change notification settings - Fork 1
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
New bucket #84
base: dev
Are you sure you want to change the base?
New bucket #84
Conversation
default: | ||
console.log(`Uncaught backend http-status: ${response.status}`); | ||
} | ||
let products = JSON.parse(localStorage.getItem('cart')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
src/model/bucketModel.js
Outdated
} | ||
let products = JSON.parse(localStorage.getItem('cart')); | ||
const total = products.reduce((a, b) => a + b.food_price * b.count, 0); | ||
this.eventBus.call('SHOW_CART', { total: total, products: products, addresses: {} }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ total, products, addresses: {} }
src/model/bucketModel.js
Outdated
console.log(`Uncaught backend http-status: ${response.status}`); | ||
} | ||
let products = JSON.parse(localStorage.getItem('cart')); | ||
products = products.filter((product) => { return product.id != productId; }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(product) => product.id !== productId
- давай уберем
products = products.filter
и сделаем
localStorage.setItem('cart', JSON.stringify(products.filter(.............)));
src/model/storeModel.js
Outdated
const response = await addProductToBucket(productId); | ||
addToCart (product) { | ||
product.count = 1; | ||
let productsJSON = localStorage.getItem('cart'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
src/model/storeModel.js
Outdated
if (productsJSON === null) { | ||
let products = []; | ||
products.push(product); | ||
localStorage.setItem('cart', JSON.stringify(products)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JSON.stringify([product])
и без лишних действий тогда
console.log(`Uncaught backend http-status: ${response.status}`); | ||
let products = JSON.parse(productsJSON); | ||
if(products.some(p => p.id === product.id)){ | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const + по линтеру траблы
src/model/storeModel.js
Outdated
} | ||
|
||
products.push(product); | ||
localStorage.setItem('cart', JSON.stringify(products)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
вместо того, что бы пушить в массив, можно сделать так JSON.stringify([...products, product])
No description provided.