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