Commit 20743c4ebb8f24d6197f3190a42c77f71865ceb6
1 parent
e5e827a8
Basket
Showing
3 changed files
with
33 additions
and
11 deletions
Show diff stats
controllers/BasketController.php
... | ... | @@ -28,7 +28,7 @@ |
28 | 28 | ]; |
29 | 29 | return $result; |
30 | 30 | } |
31 | - | |
31 | + | |
32 | 32 | public function actionAdd(int $variant_id, int $count) |
33 | 33 | { |
34 | 34 | $response = \Yii::$app->response; |
... | ... | @@ -45,7 +45,7 @@ |
45 | 45 | ]; |
46 | 46 | return $result; |
47 | 47 | } |
48 | - | |
48 | + | |
49 | 49 | public function actionSet(int $variant_id, int $count) |
50 | 50 | { |
51 | 51 | $response = \Yii::$app->response; |
... | ... | @@ -62,7 +62,7 @@ |
62 | 62 | ]; |
63 | 63 | return $result; |
64 | 64 | } |
65 | - | |
65 | + | |
66 | 66 | public function actionRemove(int $variant_id) |
67 | 67 | { |
68 | 68 | return $this->actionSet($variant_id, 0); | ... | ... |
web/js/artbox_basket.js
... | ... | @@ -11,6 +11,9 @@ var ArtboxBasket = (function () { |
11 | 11 | }; |
12 | 12 | this._settings = {}; |
13 | 13 | this._settings = ArtboxBasket.mergeObjects(this._defaults, settings); |
14 | + if (settings['language'] !== undefined) { | |
15 | + this._language = settings['language']; | |
16 | + } | |
14 | 17 | this.init(true, true); |
15 | 18 | } |
16 | 19 | Object.defineProperty(ArtboxBasket.prototype, "items", { |
... | ... | @@ -43,7 +46,7 @@ var ArtboxBasket = (function () { |
43 | 46 | configurable: true |
44 | 47 | }); |
45 | 48 | ArtboxBasket.prototype.init = function (update_modal, update_cart) { |
46 | - $.get('/' + this.language + '/' + this._settings['url'], function (data) { | |
49 | + $.get(this.getLanguagePath() + this._settings['url'], function (data) { | |
47 | 50 | this._items = data.basket; |
48 | 51 | if (update_modal) { |
49 | 52 | this.updateModal(data.modal, false); |
... | ... | @@ -56,7 +59,7 @@ var ArtboxBasket = (function () { |
56 | 59 | }.bind(this)); |
57 | 60 | }; |
58 | 61 | ArtboxBasket.prototype.add = function (variant_id, count) { |
59 | - return $.post('/' + this.language + '/' + this._settings['url'] + '/add?variant_id=' + variant_id + '&count=' + count, function (data) { | |
62 | + return $.post(this.getLanguagePath() + this._settings['url'] + '/add?variant_id=' + variant_id + '&count=' + count, function (data) { | |
60 | 63 | this._items = data.basket; |
61 | 64 | this.updateModal(data.modal, data.cart, true); |
62 | 65 | }.bind(this), 'json').fail(function (xhr, status, error) { |
... | ... | @@ -64,7 +67,7 @@ var ArtboxBasket = (function () { |
64 | 67 | }); |
65 | 68 | }; |
66 | 69 | ArtboxBasket.prototype.set = function (variant_id, count) { |
67 | - return $.post('/' + this.language + '/' + this._settings['url'] + '/set?variant_id=' + variant_id + '&count=' + count, function (data) { | |
70 | + return $.post(this.getLanguagePath() + this._settings['url'] + '/set?variant_id=' + variant_id + '&count=' + count, function (data) { | |
68 | 71 | this._items = data.basket; |
69 | 72 | this.updateModal(data.modal, data.cart, true); |
70 | 73 | }.bind(this), 'json').fail(function (xhr, status, error) { |
... | ... | @@ -72,7 +75,7 @@ var ArtboxBasket = (function () { |
72 | 75 | }); |
73 | 76 | }; |
74 | 77 | ArtboxBasket.prototype.remove = function (variant_id) { |
75 | - return $.post('/' + this.language + '/' + this._settings['url'] + '/remove?variant_id=' + variant_id, function (data) { | |
78 | + return $.post(this.getLanguagePath() + this._settings['url'] + '/remove?variant_id=' + variant_id, function (data) { | |
76 | 79 | this._items = data.basket; |
77 | 80 | this.updateModal(data.modal, data.cart, true); |
78 | 81 | }.bind(this), 'json').fail(function (xhr, status, error) { |
... | ... | @@ -126,5 +129,13 @@ var ArtboxBasket = (function () { |
126 | 129 | } |
127 | 130 | return obj; |
128 | 131 | }; |
132 | + ArtboxBasket.prototype.getLanguagePath = function () { | |
133 | + if (this.language) { | |
134 | + return '/' + this.language + '/'; | |
135 | + } | |
136 | + else { | |
137 | + return '/'; | |
138 | + } | |
139 | + }; | |
129 | 140 | return ArtboxBasket; |
130 | 141 | }()); | ... | ... |
web/js/artbox_basket.ts
... | ... | @@ -34,11 +34,14 @@ class ArtboxBasket { |
34 | 34 | |
35 | 35 | constructor(settings: Object = {}) { |
36 | 36 | this._settings = ArtboxBasket.mergeObjects(this._defaults, settings); |
37 | + if (settings['language'] !== undefined) { | |
38 | + this._language = settings['language']; | |
39 | + } | |
37 | 40 | this.init(true, true); |
38 | 41 | } |
39 | 42 | |
40 | 43 | public init(update_modal, update_cart) { |
41 | - $.get('/' + this.language + '/' + this._settings['url'], function (data) { | |
44 | + $.get(this.getLanguagePath() + this._settings['url'], function (data) { | |
42 | 45 | this._items = data.basket; |
43 | 46 | if (update_modal) { |
44 | 47 | this.updateModal(data.modal, false); |
... | ... | @@ -52,7 +55,7 @@ class ArtboxBasket { |
52 | 55 | } |
53 | 56 | |
54 | 57 | public add(variant_id, count): JQueryPromise<JQueryXHR> { |
55 | - return $.post('/' + this.language + '/' + this._settings['url'] + '/add?variant_id=' + variant_id + '&count=' + count, function (data) { | |
58 | + return $.post(this.getLanguagePath() + this._settings['url'] + '/add?variant_id=' + variant_id + '&count=' + count, function (data) { | |
56 | 59 | this._items = data.basket; |
57 | 60 | this.updateModal(data.modal, data.cart, true); |
58 | 61 | }.bind(this), 'json').fail(function (xhr, status, error) { |
... | ... | @@ -61,7 +64,7 @@ class ArtboxBasket { |
61 | 64 | } |
62 | 65 | |
63 | 66 | public set(variant_id, count): JQueryPromise<JQueryXHR> { |
64 | - return $.post('/' + this.language + '/' + this._settings['url'] + '/set?variant_id=' + variant_id + '&count=' + count, function (data) { | |
67 | + return $.post(this.getLanguagePath() + this._settings['url'] + '/set?variant_id=' + variant_id + '&count=' + count, function (data) { | |
65 | 68 | this._items = data.basket; |
66 | 69 | this.updateModal(data.modal, data.cart, true); |
67 | 70 | }.bind(this), 'json').fail(function (xhr, status, error) { |
... | ... | @@ -70,7 +73,7 @@ class ArtboxBasket { |
70 | 73 | } |
71 | 74 | |
72 | 75 | public remove(variant_id): JQueryPromise<JQueryXHR> { |
73 | - return $.post('/' + this.language + '/' + this._settings['url'] + '/remove?variant_id=' + variant_id, function (data) { | |
76 | + return $.post(this.getLanguagePath() + this._settings['url'] + '/remove?variant_id=' + variant_id, function (data) { | |
74 | 77 | this._items = data.basket; |
75 | 78 | this.updateModal(data.modal, data.cart, true); |
76 | 79 | }.bind(this), 'json').fail(function (xhr, status, error) { |
... | ... | @@ -126,4 +129,12 @@ class ArtboxBasket { |
126 | 129 | } |
127 | 130 | return obj; |
128 | 131 | } |
132 | + | |
133 | + private getLanguagePath(): string { | |
134 | + if (this.language) { | |
135 | + return '/' + this.language + '/'; | |
136 | + } else { | |
137 | + return '/'; | |
138 | + } | |
139 | + } | |
129 | 140 | } |
130 | 141 | \ No newline at end of file | ... | ... |