fe7b6960
Yarik
Basket
|
1
2
3
4
5
6
|
class ArtboxBasket {
private _items;
get items() {
return this._items;
}
constructor() {
|
07a62660
Administrator
big commti
|
7
|
$.get('/basket/main', function (data) {
|
fe7b6960
Yarik
Basket
|
8
|
this._items = data.basket;
|
8ec69373
Yarik
Orders.
|
9
|
this.updateModal(data.modal, data.cart);
|
fe7b6960
Yarik
Basket
|
10
11
12
13
14
15
16
|
}.bind(this), 'json').fail(function() {
console.error('Basket cannot be init');
});
}
public add(product_variant_id, count) {
$.post('/basket/add?product_variant_id='+product_variant_id+'&count='+count, function (data) {
this._items = data.basket;
|
8ec69373
Yarik
Orders.
|
17
|
this.updateModal(data.modal, data.cart, true);
|
fe7b6960
Yarik
Basket
|
18
19
20
21
22
23
24
|
}.bind(this), 'json').fail(function (xhr, status, error) {
console.error(error);
});
}
public set(product_variant_id, count) {
$.post('/basket/set?product_variant_id='+product_variant_id+'&count='+count, function (data) {
this._items = data.basket;
|
8ec69373
Yarik
Orders.
|
25
|
this.updateModal(data.modal, data.cart);
|
fe7b6960
Yarik
Basket
|
26
27
28
29
|
}.bind(this), 'json').fail(function (xhr, status, error) {
console.error(error);
});
}
|
8ec69373
Yarik
Orders.
|
30
|
public updateModal(modal, cart_html, show = false)
|
fe7b6960
Yarik
Basket
|
31
32
33
|
{
var modalBox = $('#buyForm');
modalBox.html(modal);
|
e4159574
Yarik
Hide after deletion
|
34
35
36
|
if(this.count < 1) {
modalBox.modal('hide');
} else if(show) {
|
fe7b6960
Yarik
Basket
|
37
38
|
modalBox.modal('show');
}
|
8ec69373
Yarik
Orders.
|
39
|
this.updateCart(cart_html);
|
fe7b6960
Yarik
Basket
|
40
|
}
|
8ec69373
Yarik
Orders.
|
41
|
public updateCart(cart_html) {
|
fe7b6960
Yarik
Basket
|
42
|
var cart = $('#top-cart-content');
|
8ec69373
Yarik
Orders.
|
43
|
cart.html(cart_html);
|
fe7b6960
Yarik
Basket
|
44
45
46
47
48
49
50
51
52
|
}
get count(): number {
return Object.keys(this._items).length;
}
get sum(): number {
var sum = 0;
$.each(this._items, function(index, value) {
sum += value.price * value.count;
});
|
5181a91a
Administrator
big commti
|
53
|
return sum.toFixed(2);
|
fe7b6960
Yarik
Basket
|
54
55
|
}
}
|