Blame view

frontend/web/js/artbox_basket.js 2.83 KB
fe7b6960   Yarik   Basket
1
2
3
4
  var ArtboxBasket = (function () {
      function ArtboxBasket() {
          $.get('/basket', function (data) {
              this._items = data.basket;
a46c643b   Yarik   Link on top baske...
5
              this.updateModal(data.modal);
fe7b6960   Yarik   Basket
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
          }.bind(this), 'json').fail(function () {
              console.error('Basket cannot be init');
          });
      }
      Object.defineProperty(ArtboxBasket.prototype, "items", {
          get: function () {
              return this._items;
          },
          enumerable: true,
          configurable: true
      });
      ArtboxBasket.prototype.add = function (product_variant_id, count) {
          $.post('/basket/add?product_variant_id=' + product_variant_id + '&count=' + count, function (data) {
              this._items = data.basket;
              this.updateModal(data.modal, true);
          }.bind(this), 'json').fail(function (xhr, status, error) {
              console.error(error);
          });
      };
      ArtboxBasket.prototype.set = function (product_variant_id, count) {
          $.post('/basket/set?product_variant_id=' + product_variant_id + '&count=' + count, function (data) {
              this._items = data.basket;
              this.updateModal(data.modal);
          }.bind(this), 'json').fail(function (xhr, status, error) {
              console.error(error);
          });
      };
      ArtboxBasket.prototype.updateModal = function (modal, show) {
          if (show === void 0) { show = false; }
          var modalBox = $('#buyForm');
          modalBox.html(modal);
e4159574   Yarik   Hide after deletion
37
38
39
40
          if (this.count < 1) {
              modalBox.modal('hide');
          }
          else if (show) {
fe7b6960   Yarik   Basket
41
42
43
44
45
46
47
48
              modalBox.modal('show');
          }
          this.updateCart();
      };
      ArtboxBasket.prototype.updateCart = function () {
          var cart = $('#top-cart-content');
          var count = this.count;
          if (count > 0) {
d09f430f   Administrator   big commti
49
              $(cart).html('<div id="top-cart-info"><span class="in_the_cart">В корзине</span><span id="in_cart_col">' + count + ' товар' + ((count > 4) ? 'ов' : ((count > 1) ? 'а' : '')) + '</span><br/><span id="in_cart_sum">на ' + this.sum + ' </span><br/></div><div id="in_cart_a"><a class="btn" href="/order">оформить покупку</a></div>');
fe7b6960   Yarik   Basket
50
51
          }
          else {
53638a15   Yarik   Clear top cart af...
52
              $(cart).html('<p class="empty-cart">Корзина пуста</p>');
fe7b6960   Yarik   Basket
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
          }
      };
      Object.defineProperty(ArtboxBasket.prototype, "count", {
          get: function () {
              return Object.keys(this._items).length;
          },
          enumerable: true,
          configurable: true
      });
      Object.defineProperty(ArtboxBasket.prototype, "sum", {
          get: function () {
              var sum = 0;
              $.each(this._items, function (index, value) {
                  sum += value.price * value.count;
              });
              return sum;
          },
          enumerable: true,
          configurable: true
      });
      return ArtboxBasket;
d09f430f   Administrator   big commti
74
  })();
fe7b6960   Yarik   Basket
75
  //# sourceMappingURL=artbox_basket.js.map