|
@@ -230,14 +230,17 @@ const getGQL = url =>
|
|
|
//{_id1: {good, count},
|
|
|
//_id2: {good, count}}
|
|
|
const orderGoods = Object.entries(cart)
|
|
|
- .map(([_id, {}]) => ({good: {_id}, count}))
|
|
|
+ .map(([_id, {good, count}]) => ({good: {_id}, count}))
|
|
|
|
|
|
- await dispatch(actionPromise('order', gql(`
|
|
|
+ let result = await dispatch(actionPromise('order', gql(`
|
|
|
mutation newOrder($order:OrderInput){
|
|
|
OrderUpsert(order:$order)
|
|
|
- { _id total }
|
|
|
+ { _id total}
|
|
|
}
|
|
|
`, {order: {orderGoods}})))
|
|
|
+ if (result?._id) {
|
|
|
+ dispatch(actionCartClear())
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
|
|
@@ -390,7 +393,6 @@ function createForm(parent, type, callback) {
|
|
|
const createCartPage = (parent) => {
|
|
|
parent.innerHTML = '';
|
|
|
const {cart} = store.getState();
|
|
|
- console.log(cart);
|
|
|
|
|
|
const clearBtn = document.createElement('button');
|
|
|
clearBtn.innerText = "ОЧИСТИТЬ КОРЗИНУ";
|
|
@@ -402,17 +404,15 @@ const createCartPage = (parent) => {
|
|
|
store.dispatch(actionCartClear());
|
|
|
}
|
|
|
for(const item in cart) {
|
|
|
- console.log(cart[item])
|
|
|
const {good} = cart[item];
|
|
|
const {count, good: {_id: id, name: name, price: price, images: [{url}]}} = cart[item];
|
|
|
- console.log(count, id, name, price, url);
|
|
|
const card = document.createElement('div');
|
|
|
card.innerHTML = `
|
|
|
<div>
|
|
|
<p>${name}</p>
|
|
|
<img src="${backURL}/${url}">
|
|
|
<p>${count}</p>
|
|
|
- <p>${price}</p>
|
|
|
+ <p>${price} грн</p>
|
|
|
</div>
|
|
|
`;
|
|
|
|
|
@@ -514,12 +514,12 @@ store.subscribe(() => {
|
|
|
const card = document.createElement('div')
|
|
|
card.innerHTML = `<h2>${name}</h2>
|
|
|
<img src="${backURL}/${images[0].url}" />
|
|
|
- <strong>${price}</strong>
|
|
|
+ <strong>${price} грн</strong>
|
|
|
<br>
|
|
|
<a href="#/good/${_id}">Перейти на страницу товара</a>
|
|
|
`
|
|
|
const btnCart = document.createElement('button')
|
|
|
- btnCart.innerText = 'Добавить товар'
|
|
|
+ btnCart.innerText = 'Добавить в корзину'
|
|
|
btnCart.onclick = () => {
|
|
|
store.dispatch(actionCartAdd(good))
|
|
|
}
|
|
@@ -536,13 +536,20 @@ store.subscribe(() => {
|
|
|
const [,route, _id] = location.hash.split('/');
|
|
|
if (goodById?.payload && route === 'good') {
|
|
|
main.innerHTML = '';
|
|
|
- const {_id, name, images, price, description} = goodById.payload;
|
|
|
+ const good = goodById.payload;
|
|
|
+ const {_id, name, images, price, description} = good
|
|
|
const card = document.createElement('div');
|
|
|
card.innerHTML = `<h2>${name}</h2>
|
|
|
<img src="${backURL}/${images[0].url}" />
|
|
|
- <strong>${price}</strong>
|
|
|
+ <strong>${price} грн</strong>
|
|
|
<h2>${description}</h2>
|
|
|
`;
|
|
|
+ const btnCart = document.createElement('button')
|
|
|
+ btnCart.innerText = 'Добавить в корзину'
|
|
|
+ btnCart.onclick = () => {
|
|
|
+ store.dispatch(actionCartAdd(good))
|
|
|
+ }
|
|
|
+ card.append(btnCart)
|
|
|
main.append(card);
|
|
|
}
|
|
|
}
|
|
@@ -591,10 +598,10 @@ store.subscribe(() => {
|
|
|
const card = document.createElement('div')
|
|
|
card.innerHTML = `<h2>${name}</h2>
|
|
|
<img src="${backURL}/${images[0].url}" />
|
|
|
- <strong>Куплено ${count} по ${price} грн. Итого:${total}</strong>
|
|
|
+ <strong>Куплено ${count} по ${price} грн. Итого: ${total} грн</strong>
|
|
|
<br>
|
|
|
<a href="#/good/${_id}">Перейти на страницу товара</a>
|
|
|
- `
|
|
|
+ `
|
|
|
main.append(card)
|
|
|
}
|
|
|
}
|