Skip to content

задание к седьмому занятию - #5

Open
zaqw60 wants to merge 1 commit into
mainfrom
lesson-7.1
Open

задание к седьмому занятию#5
zaqw60 wants to merge 1 commit into
mainfrom
lesson-7.1

Conversation

@zaqw60

@zaqw60 zaqw60 commented Jun 10, 2021

Copy link
Copy Markdown
Owner

доделал таки подсчет корзины

Comment thread 8.06/index.html
],


Init() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не хватает параметра cart и соответственно передачи в него ссылки на корзину

Comment thread 8.06/index.html
this.catalogListBlock.addEventListener('click', event => this.addToCart(event))
},

addToCart(event) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Метод жутко перегружен различной императивной логикой. Нужно декомпозировать логику и сделать ее более декларативной, дабы повысить читабельность и масштабируемость кода.

Comment thread 8.06/index.html
const addProduct = this.items.find((item) => item.id_product == product);
if (this.cart.units.length == 0) {
addProduct.quantity = 1;
this.cart.units.push(addProduct);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не рекомендуется напрямую влиять на данные в другой сущности. Вместо этого, нужно вызывать метод добавления товара в корзину у самой корзины и передавать в него информацию о товаре

Comment thread 8.06/index.html
this.cart.units.forEach(unit => { totalPrice += unit.quantity * unit.price });
let total = 0;
this.cart.units.forEach(unit => { total += unit.quantity });
cart.init(total, totalPrice);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

корзина должна инициализироваться отдельно от каталога.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

обновлением состояния при добавлении товара должна заниматься корзина

Comment thread 8.06/index.html
Comment on lines +114 to +117
let totalPrice = 0;
this.cart.units.forEach(unit => { totalPrice += unit.quantity * unit.price });
let total = 0;
this.cart.units.forEach(unit => { total += unit.quantity });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

для подсчета нужны отдельные методы

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants