@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | class Select extends \Ui\ActiveForm\Input { |
15 | 15 | |
16 | - public function draw() { |
|
16 | + public function draw() { |
|
17 | 17 | $inputName = $this->colName(); |
18 | 18 | $inputLabel = $this->colLabel(); |
19 | 19 | $inputParams = $this->colParams; |
@@ -25,41 +25,41 @@ discard block |
||
25 | 25 | ]; |
26 | 26 | $modelName = ''; |
27 | 27 | switch ($inputParams['source']) { |
28 | - case 'model': |
|
28 | + case 'model': |
|
29 | 29 | $modelName = $inputParams['model']; |
30 | 30 | break; |
31 | - case 'relation': |
|
31 | + case 'relation': |
|
32 | 32 | if ($this->activeForm->modelName) { |
33 | - $itemModelName = $this->activeForm->modelName; |
|
34 | - $relation = $itemModelName::getRelation($inputParams['relation']); |
|
35 | - if ($relation['model'] && class_exists($relation['model'])) { |
|
33 | + $itemModelName = $this->activeForm->modelName; |
|
34 | + $relation = $itemModelName::getRelation($inputParams['relation']); |
|
35 | + if ($relation['model'] && class_exists($relation['model'])) { |
|
36 | 36 | $modelName = $relation['model']; |
37 | - } |
|
37 | + } |
|
38 | 38 | } |
39 | 39 | } |
40 | 40 | if (!empty($modelName)) { |
41 | - $inputOptions['createBtn'] = [ |
|
42 | - 'text' => 'Создать элемент', |
|
43 | - 'onclick' => 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
|
44 | - . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this))' |
|
45 | - ]; |
|
41 | + $inputOptions['createBtn'] = [ |
|
42 | + 'text' => 'Создать элемент', |
|
43 | + 'onclick' => 'inji.Ui.forms.popUp(\'' . addslashes($modelName) . '\',{},function(elem){' |
|
44 | + . 'return function(data,modal){inji.Ui.forms.submitAjax($(elem).closest(\'form\')[0], {notSave: true});}}(this))' |
|
45 | + ]; |
|
46 | 46 | } |
47 | 47 | if (!empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]) && |
48 | 48 | is_array($inputOptions['values'][$this->activeForm->model->{$this->colName}]) && |
49 | 49 | !empty($inputOptions['values'][$this->activeForm->model->{$this->colName}]['input'])) { |
50 | - $aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name']; |
|
51 | - $inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol; |
|
50 | + $aditionalCol = $inputOptions['values'][$this->activeForm->model->{$this->colName}]['input']['name']; |
|
51 | + $inputOptions['aditionalValue'] = $this->activeForm->model->$aditionalCol; |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | $preset = $this->preset(); |
55 | 55 | |
56 | 56 | if ($preset !== null) { |
57 | - $inputOptions['disabled'] = true; |
|
58 | - $this->form->input('hidden', $inputName, '', $inputOptions); |
|
59 | - return true; |
|
57 | + $inputOptions['disabled'] = true; |
|
58 | + $this->form->input('hidden', $inputName, '', $inputOptions); |
|
59 | + return true; |
|
60 | 60 | } |
61 | 61 | $this->form->input('select', $inputName, $inputLabel, $inputOptions); |
62 | 62 | return true; |
63 | - } |
|
63 | + } |
|
64 | 64 | |
65 | 65 | } |
@@ -168,12 +168,12 @@ |
||
168 | 168 | <li><a href ='' onclick='inji.Ui.dataManagers.get(this).rowSelection("inverse");return false;'>Инвертировать</a></li> |
169 | 169 | <li role="separator" class="divider"></li> |
170 | 170 | <?php |
171 | - foreach ($actions as $action => $actionParams) { |
|
172 | - if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
|
173 | - echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
174 | - } |
|
175 | - } |
|
176 | - ?> |
|
171 | + foreach ($actions as $action => $actionParams) { |
|
172 | + if (class_exists($actionParams['className']) && $actionParams['className']::$groupAction) { |
|
173 | + echo "<li><a role='button' href ='#' onclick='inji.Ui.dataManagers.get(this).groupAction(\"" . str_replace('\\', '\\\\', $action) . "\");return false;'>{$actionParams['className']::$name}</a></li>"; |
|
174 | + } |
|
175 | + } |
|
176 | + ?> |
|
177 | 177 | </ul> |
178 | 178 | </div> |
179 | 179 | <?php |
@@ -6,12 +6,12 @@ discard block |
||
6 | 6 | <?php |
7 | 7 | $socials = Users\Social::getList(['where' => ['active', 1]]); |
8 | 8 | if ($socials) { |
9 | - ?> |
|
9 | + ?> |
|
10 | 10 | <div class="form-group"> |
11 | 11 | <label>Регистрация через соц.сети</label><br /> |
12 | 12 | <?php |
13 | 13 | foreach (Users\Social::getList(['where' => ['active', 1]]) as $social) { |
14 | - echo "<a href = '/users/social/auth/{$social->code}'>{$social->name()}</a> "; |
|
14 | + echo "<a href = '/users/social/auth/{$social->code}'>{$social->name()}</a> "; |
|
15 | 15 | } |
16 | 16 | ?> |
17 | 17 | </div> |
@@ -41,15 +41,15 @@ discard block |
||
41 | 41 | <div class ='row'> |
42 | 42 | <div class="col-sm-6"> |
43 | 43 | <?php |
44 | - if (!empty(App::$cur->users->config['invites'])) { |
|
44 | + if (!empty(App::$cur->users->config['invites'])) { |
|
45 | 45 | ?> |
46 | 46 | <div class ='form-group'> |
47 | 47 | <label><?= !empty(App::$cur->users->config['invitesName']) ? App::$cur->users->config['invitesName'] : 'Код приглашения'; ?></label> |
48 | 48 | <input type ='text' name ='invite_code' class ='form-control' value ="<?= (isset($_POST['invite_code']) ? $_POST['invite_code'] : ((!empty($_COOKIE['invite_code']) ? $_COOKIE['invite_code'] : ((!empty($_GET['invite_code']) ? $_GET['invite_code'] : ''))))); ?>" /> |
49 | 49 | </div> |
50 | 50 | <?php |
51 | - } |
|
52 | - ?> |
|
51 | + } |
|
52 | + ?> |
|
53 | 53 | </div> |
54 | 54 | </div> |
55 | 55 | <div class ='form-group'> |
@@ -10,172 +10,172 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class Ecommerce extends Module { |
12 | 12 | |
13 | - public function init() { |
|
13 | + public function init() { |
|
14 | 14 | App::$primary->view->customAsset('js', '/moduleAsset/Ecommerce/js/cart.js'); |
15 | - } |
|
15 | + } |
|
16 | 16 | |
17 | - public function getPayTypeHandlers($forSelect = false) { |
|
17 | + public function getPayTypeHandlers($forSelect = false) { |
|
18 | 18 | if (!$forSelect) { |
19 | - return $this->getSnippets('payTypeHandler'); |
|
19 | + return $this->getSnippets('payTypeHandler'); |
|
20 | 20 | } |
21 | 21 | $handlers = ['' => 'Не выбрано']; |
22 | 22 | foreach ($this->getSnippets('payTypeHandler') as $key => $handler) { |
23 | - if (empty($handler)) { |
|
23 | + if (empty($handler)) { |
|
24 | 24 | continue; |
25 | - } |
|
26 | - $handlers[$key] = $handler['name']; |
|
25 | + } |
|
26 | + $handlers[$key] = $handler['name']; |
|
27 | 27 | } |
28 | 28 | return $handlers; |
29 | - } |
|
29 | + } |
|
30 | 30 | |
31 | - public function cartPayRecive($data) { |
|
31 | + public function cartPayRecive($data) { |
|
32 | 32 | $cart = Ecommerce\Cart::get($data['pay']->data); |
33 | 33 | if ($cart) { |
34 | - $payed = true; |
|
35 | - foreach ($cart->pays as $pay) { |
|
34 | + $payed = true; |
|
35 | + foreach ($cart->pays as $pay) { |
|
36 | 36 | if ($pay->pay_status_id != 2) { |
37 | - $payed = false; |
|
38 | - break; |
|
37 | + $payed = false; |
|
38 | + break; |
|
39 | 39 | } |
40 | - } |
|
41 | - $cart->payed = $payed; |
|
42 | - $cart->save(); |
|
40 | + } |
|
41 | + $cart->payed = $payed; |
|
42 | + $cart->save(); |
|
43 | + } |
|
43 | 44 | } |
44 | - } |
|
45 | 45 | |
46 | - public function parseFields($data, $cart) { |
|
46 | + public function parseFields($data, $cart) { |
|
47 | 47 | $fields = \Ecommerce\UserAdds\Field::getList(); |
48 | 48 | $name = ''; |
49 | 49 | foreach ($fields as $field) { |
50 | - if ($field->save && !empty($data[$field->id])) { |
|
50 | + if ($field->save && !empty($data[$field->id])) { |
|
51 | 51 | $name .= htmlspecialchars($data[$field->id]) . ' '; |
52 | - } |
|
52 | + } |
|
53 | 53 | } |
54 | 54 | $name = trim($name); |
55 | 55 | |
56 | 56 | $userAdds = Ecommerce\UserAdds::get([['user_id', $cart->user->id], ['name', $name]]); |
57 | 57 | if (!$userAdds) { |
58 | - $userAdds = new Ecommerce\UserAdds(); |
|
59 | - $userAdds->user_id = $cart->user->id; |
|
60 | - $userAdds->name = $name; |
|
61 | - $userAdds->save(); |
|
62 | - foreach ($fields as $field) { |
|
58 | + $userAdds = new Ecommerce\UserAdds(); |
|
59 | + $userAdds->user_id = $cart->user->id; |
|
60 | + $userAdds->name = $name; |
|
61 | + $userAdds->save(); |
|
62 | + foreach ($fields as $field) { |
|
63 | 63 | if (!$field->save) { |
64 | - continue; |
|
64 | + continue; |
|
65 | 65 | } |
66 | 66 | $userAddsValue = new Ecommerce\UserAdds\Value(); |
67 | 67 | $userAddsValue->value = htmlspecialchars($data[$field->id]); |
68 | 68 | $userAddsValue->useradds_field_id = $field->id; |
69 | 69 | $userAddsValue->useradds_id = $userAdds->id; |
70 | 70 | $userAddsValue->save(); |
71 | - } |
|
71 | + } |
|
72 | 72 | } |
73 | 73 | $user = \Users\User::get($cart->user_id); |
74 | 74 | foreach ($fields as $field) { |
75 | - $info = new \Ecommerce\Cart\Info(); |
|
76 | - $info->name = $field->name; |
|
77 | - $info->value = htmlspecialchars($data[$field->id]); |
|
78 | - $info->useradds_field_id = $field->id; |
|
79 | - $info->cart_id = $cart->id; |
|
80 | - $info->save(); |
|
81 | - $relations = []; |
|
82 | - if ($field->userfield) { |
|
75 | + $info = new \Ecommerce\Cart\Info(); |
|
76 | + $info->name = $field->name; |
|
77 | + $info->value = htmlspecialchars($data[$field->id]); |
|
78 | + $info->useradds_field_id = $field->id; |
|
79 | + $info->cart_id = $cart->id; |
|
80 | + $info->save(); |
|
81 | + $relations = []; |
|
82 | + if ($field->userfield) { |
|
83 | 83 | if (strpos($field->userfield, ':')) { |
84 | - $path = explode(':', $field->userfield); |
|
85 | - if (!$user->{$path[0]}->{$path[1]}) { |
|
84 | + $path = explode(':', $field->userfield); |
|
85 | + if (!$user->{$path[0]}->{$path[1]}) { |
|
86 | 86 | $user->{$path[0]}->{$path[1]} = $info->value; |
87 | 87 | $relations[$path[0]] = $path[0]; |
88 | - } |
|
88 | + } |
|
89 | 89 | } else { |
90 | - if (!$user->{$field->userfield}) { |
|
90 | + if (!$user->{$field->userfield}) { |
|
91 | 91 | $user->{$field->userfield} = $info->value; |
92 | - } |
|
92 | + } |
|
93 | 93 | } |
94 | - } |
|
95 | - foreach ($relations as $rel) { |
|
94 | + } |
|
95 | + foreach ($relations as $rel) { |
|
96 | 96 | $user->$rel->save(); |
97 | - } |
|
98 | - $user->save(); |
|
97 | + } |
|
98 | + $user->save(); |
|
99 | 99 | } |
100 | 100 | return $userAdds; |
101 | - } |
|
101 | + } |
|
102 | 102 | |
103 | - public function parseDeliveryFields($data, $cart, $fields) { |
|
103 | + public function parseDeliveryFields($data, $cart, $fields) { |
|
104 | 104 | $name = ''; |
105 | 105 | foreach ($fields as $field) { |
106 | - if ($field->save && !empty($data[$field->id])) { |
|
106 | + if ($field->save && !empty($data[$field->id])) { |
|
107 | 107 | $name .= htmlspecialchars($data[$field->id]) . ' '; |
108 | - } |
|
108 | + } |
|
109 | 109 | } |
110 | 110 | $name = trim($name); |
111 | 111 | |
112 | 112 | $save = Ecommerce\Delivery\Save::get([['user_id', $cart->user->id], ['name', $name]]); |
113 | 113 | if (!$save) { |
114 | - $save = new Ecommerce\Delivery\Save(); |
|
115 | - $save->user_id = $cart->user->id; |
|
116 | - $save->name = $name; |
|
117 | - $save->save(); |
|
118 | - foreach ($fields as $field) { |
|
114 | + $save = new Ecommerce\Delivery\Save(); |
|
115 | + $save->user_id = $cart->user->id; |
|
116 | + $save->name = $name; |
|
117 | + $save->save(); |
|
118 | + foreach ($fields as $field) { |
|
119 | 119 | if (!$field->save) { |
120 | - continue; |
|
120 | + continue; |
|
121 | 121 | } |
122 | 122 | $saveValue = new Ecommerce\Delivery\Value(); |
123 | 123 | $saveValue->value = htmlspecialchars($data[$field->id]); |
124 | 124 | $saveValue->delivery_field_id = $field->id; |
125 | 125 | $saveValue->delivery_save_id = $save->id; |
126 | 126 | $saveValue->save(); |
127 | - } |
|
127 | + } |
|
128 | 128 | } |
129 | 129 | $user = \Users\User::get($cart->user_id); |
130 | 130 | foreach ($fields as $field) { |
131 | - $info = new \Ecommerce\Cart\DeliveryInfo(); |
|
132 | - $info->name = $field->name; |
|
133 | - $info->value = htmlspecialchars($data[$field->id]); |
|
134 | - $info->delivery_field_id = $field->id; |
|
135 | - $info->cart_id = $cart->id; |
|
136 | - $info->save(); |
|
137 | - $relations = []; |
|
138 | - if ($field->userfield) { |
|
131 | + $info = new \Ecommerce\Cart\DeliveryInfo(); |
|
132 | + $info->name = $field->name; |
|
133 | + $info->value = htmlspecialchars($data[$field->id]); |
|
134 | + $info->delivery_field_id = $field->id; |
|
135 | + $info->cart_id = $cart->id; |
|
136 | + $info->save(); |
|
137 | + $relations = []; |
|
138 | + if ($field->userfield) { |
|
139 | 139 | if (strpos($field->userfield, ':')) { |
140 | - $path = explode(':', $field->userfield); |
|
141 | - if (!$user->{$path[0]}->{$path[1]}) { |
|
140 | + $path = explode(':', $field->userfield); |
|
141 | + if (!$user->{$path[0]}->{$path[1]}) { |
|
142 | 142 | $user->{$path[0]}->{$path[1]} = $info->value; |
143 | 143 | $relations[$path[0]] = $path[0]; |
144 | - } |
|
144 | + } |
|
145 | 145 | } else { |
146 | - if (!$user->{$field->userfield}) { |
|
146 | + if (!$user->{$field->userfield}) { |
|
147 | 147 | $user->{$field->userfield} = $info->value; |
148 | - } |
|
148 | + } |
|
149 | 149 | } |
150 | - } |
|
151 | - foreach ($relations as $rel) { |
|
150 | + } |
|
151 | + foreach ($relations as $rel) { |
|
152 | 152 | $user->$rel->save(); |
153 | - } |
|
154 | - $user->save(); |
|
153 | + } |
|
154 | + $user->save(); |
|
155 | 155 | } |
156 | 156 | return $save; |
157 | - } |
|
157 | + } |
|
158 | 158 | |
159 | - public function getCurCart($create = true) { |
|
159 | + public function getCurCart($create = true) { |
|
160 | 160 | $cart = false; |
161 | 161 | if (!empty($_SESSION['cart']['cart_id'])) { |
162 | - $cart = Ecommerce\Cart::get((int) $_SESSION['cart']['cart_id']); |
|
162 | + $cart = Ecommerce\Cart::get((int) $_SESSION['cart']['cart_id']); |
|
163 | 163 | } |
164 | 164 | if (!$cart && $create) { |
165 | - $cart = new Ecommerce\Cart(); |
|
166 | - $cart->cart_status_id = 1; |
|
167 | - $cart->user_id = Users\User::$cur->id; |
|
168 | - $userCard = \Ecommerce\Card\Item::get(\Users\User::$cur->id, 'user_id'); |
|
169 | - if ($userCard) { |
|
165 | + $cart = new Ecommerce\Cart(); |
|
166 | + $cart->cart_status_id = 1; |
|
167 | + $cart->user_id = Users\User::$cur->id; |
|
168 | + $userCard = \Ecommerce\Card\Item::get(\Users\User::$cur->id, 'user_id'); |
|
169 | + if ($userCard) { |
|
170 | 170 | $cart->card_item_id = $userCard->id; |
171 | - } |
|
172 | - $cart->save(); |
|
173 | - $_SESSION['cart']['cart_id'] = $cart->id; |
|
171 | + } |
|
172 | + $cart->save(); |
|
173 | + $_SESSION['cart']['cart_id'] = $cart->id; |
|
174 | 174 | } |
175 | 175 | return $cart; |
176 | - } |
|
176 | + } |
|
177 | 177 | |
178 | - public function parseOptions($options = []) { |
|
178 | + public function parseOptions($options = []) { |
|
179 | 179 | $selectOptions = [ |
180 | 180 | 'where' => !empty($options['where']) ? $options['where'] : [], |
181 | 181 | 'distinct' => false, |
@@ -186,29 +186,29 @@ discard block |
||
186 | 186 | 'limit' => !empty($options['count']) ? (int) $options['count'] : 0, |
187 | 187 | ]; |
188 | 188 | if (!empty($options['sort']) && is_array($options['sort'])) { |
189 | - foreach ($options['sort'] as $col => $direction) { |
|
189 | + foreach ($options['sort'] as $col => $direction) { |
|
190 | 190 | switch ($col) { |
191 | - case 'price': |
|
191 | + case 'price': |
|
192 | 192 | $selectOptions['order'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', strtolower($direction) == 'desc' ? 'desc' : 'asc']; |
193 | 193 | break; |
194 | - case 'name': |
|
194 | + case 'name': |
|
195 | 195 | $selectOptions['order'][] = ['name', strtolower($direction) == 'desc' ? 'desc' : 'asc']; |
196 | 196 | break; |
197 | - case 'sales': |
|
197 | + case 'sales': |
|
198 | 198 | $selectOptions['order'][] = ['sales', strtolower($direction) == 'desc' ? 'desc' : 'asc']; |
199 | 199 | break; |
200 | - case 'weight': |
|
200 | + case 'weight': |
|
201 | 201 | $selectOptions['order'][] = ['weight', strtolower($direction) == 'desc' ? 'desc' : 'asc']; |
202 | 202 | break; |
203 | - case 'new': |
|
203 | + case 'new': |
|
204 | 204 | $selectOptions['order'][] = ['date_create', strtolower($direction) == 'desc' ? 'desc' : 'asc']; |
205 | 205 | break; |
206 | 206 | } |
207 | - } |
|
207 | + } |
|
208 | 208 | } |
209 | 209 | $selectOptions['where'][] = ['deleted', 0]; |
210 | 210 | if (empty($this->config['view_empty_image'])) { |
211 | - $selectOptions['where'][] = ['image_file_id', 0, '!=']; |
|
211 | + $selectOptions['where'][] = ['image_file_id', 0, '!=']; |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | $selectOptions['join'][] = [Ecommerce\Item\Offer::table(), Ecommerce\Item::index() . ' = ' . Ecommerce\Item\Offer::colPrefix() . Ecommerce\Item::index(), 'inner']; |
@@ -232,111 +232,111 @@ discard block |
||
232 | 232 | |
233 | 233 | |
234 | 234 | if (!empty($this->config['view_filter'])) { |
235 | - if (!empty($this->config['view_filter']['options'])) { |
|
235 | + if (!empty($this->config['view_filter']['options'])) { |
|
236 | 236 | foreach ($this->config['view_filter']['options'] as $optionId => $optionValue) { |
237 | - $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' . |
|
238 | - 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' . |
|
239 | - 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value = "' . (int) $optionValue . '"', |
|
240 | - 'inner', 'option' . $optionId]; |
|
237 | + $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' . |
|
238 | + 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' . |
|
239 | + 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value = "' . (int) $optionValue . '"', |
|
240 | + 'inner', 'option' . $optionId]; |
|
241 | + } |
|
241 | 242 | } |
242 | - } |
|
243 | 243 | } |
244 | 244 | //filters |
245 | 245 | if (!empty($options['filters'])) { |
246 | - foreach ($options['filters'] as $col => $filter) { |
|
246 | + foreach ($options['filters'] as $col => $filter) { |
|
247 | 247 | switch ($col) { |
248 | - case 'price': |
|
248 | + case 'price': |
|
249 | 249 | if (!empty($filter['min'])) { |
250 | - $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (float) $filter['min'], '>=']; |
|
250 | + $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (float) $filter['min'], '>=']; |
|
251 | 251 | } |
252 | 252 | if (!empty($filter['max'])) { |
253 | - $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (float) $filter['max'], '<=']; |
|
253 | + $selectOptions['where'][] = [Ecommerce\Item\Offer\Price::colPrefix() . 'price', (float) $filter['max'], '<=']; |
|
254 | 254 | } |
255 | 255 | break; |
256 | - case 'options': |
|
256 | + case 'options': |
|
257 | 257 | foreach ($filter as $optionId => $optionValue) { |
258 | - $optionId = (int) $optionId; |
|
259 | - if (is_array($optionValue)) { |
|
258 | + $optionId = (int) $optionId; |
|
259 | + if (is_array($optionValue)) { |
|
260 | 260 | $optionValueArr = []; |
261 | 261 | foreach ($optionValue as $val) { |
262 | - $optionValueArr[] = \App::$cur->db->connection->pdo->quote($val); |
|
262 | + $optionValueArr[] = \App::$cur->db->connection->pdo->quote($val); |
|
263 | 263 | } |
264 | 264 | $qstr = 'IN (' . implode(',', $optionValueArr) . ')'; |
265 | - } else { |
|
265 | + } else { |
|
266 | 266 | $qstr = '= ' . \App::$cur->db->connection->pdo->quote($optionValue); |
267 | - } |
|
268 | - $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' . |
|
269 | - 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' . |
|
270 | - 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value ' . $qstr . '', |
|
271 | - 'inner', 'option' . $optionId]; |
|
267 | + } |
|
268 | + $selectOptions['join'][] = [Ecommerce\Item\Param::table(), Ecommerce\Item::index() . ' = ' . 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item::index() . ' AND ' . |
|
269 | + 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . Ecommerce\Item\Option::index() . ' = "' . (int) $optionId . '" AND ' . |
|
270 | + 'option' . $optionId . '.' . Ecommerce\Item\Param::colPrefix() . 'value ' . $qstr . '', |
|
271 | + 'inner', 'option' . $optionId]; |
|
272 | 272 | } |
273 | 273 | break; |
274 | - case 'offerOptions': |
|
274 | + case 'offerOptions': |
|
275 | 275 | //$selectOptions['join'][] = [Ecommerce\Item\Offer::table(), Ecommerce\Item::index() . ' = offer.' . Ecommerce\Item\Offer::colPrefix() . Ecommerce\Item::index(), 'left', 'offer']; |
276 | 276 | foreach ($filter as $optionId => $optionValue) { |
277 | - $optionId = (int) $optionId; |
|
278 | - if (is_array($optionValue)) { |
|
277 | + $optionId = (int) $optionId; |
|
278 | + if (is_array($optionValue)) { |
|
279 | 279 | $optionValueArr = []; |
280 | 280 | foreach ($optionValue as $val) { |
281 | - $optionValueArr[] = \App::$cur->db->connection->pdo->quote($val); |
|
281 | + $optionValueArr[] = \App::$cur->db->connection->pdo->quote($val); |
|
282 | 282 | } |
283 | 283 | $qstr = 'IN (' . implode(',', $optionValueArr) . ')'; |
284 | - } else { |
|
284 | + } else { |
|
285 | 285 | $qstr = '= ' . \App::$cur->db->connection->pdo->quote($optionValue); |
286 | - } |
|
287 | - $selectOptions['join'][] = [Ecommerce\Item\Offer\Param::table(), Ecommerce\Item\Offer::index() . ' = ' . 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer::index() . ' AND ' . |
|
288 | - 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer\Option::index() . ' = "' . (int) $optionId . '" AND ' . |
|
289 | - 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . 'value ' . $qstr, |
|
290 | - 'inner', 'offerOption' . $optionId]; |
|
286 | + } |
|
287 | + $selectOptions['join'][] = [Ecommerce\Item\Offer\Param::table(), Ecommerce\Item\Offer::index() . ' = ' . 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer::index() . ' AND ' . |
|
288 | + 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . Ecommerce\Item\Offer\Option::index() . ' = "' . (int) $optionId . '" AND ' . |
|
289 | + 'offerOption' . $optionId . '.' . Ecommerce\Item\Offer\Param::colPrefix() . 'value ' . $qstr, |
|
290 | + 'inner', 'offerOption' . $optionId]; |
|
291 | 291 | } |
292 | 292 | break; |
293 | 293 | } |
294 | - } |
|
294 | + } |
|
295 | 295 | } |
296 | 296 | //parents |
297 | 297 | if (!empty($options['parent']) && strpos($options['parent'], ',') !== false) { |
298 | - $first = true; |
|
299 | - $where = []; |
|
300 | - foreach (explode(',', $options['parent']) as $categoryId) { |
|
298 | + $first = true; |
|
299 | + $where = []; |
|
300 | + foreach (explode(',', $options['parent']) as $categoryId) { |
|
301 | 301 | if (!$categoryId) { |
302 | - continue; |
|
302 | + continue; |
|
303 | 303 | } |
304 | 304 | $category = \Ecommerce\Category::get($categoryId); |
305 | 305 | $where[] = ['tree_path', $category->tree_path . (int) $categoryId . '/%', 'LIKE', $first ? 'AND' : 'OR']; |
306 | 306 | $first = false; |
307 | - } |
|
308 | - $selectOptions['where'][] = $where; |
|
307 | + } |
|
308 | + $selectOptions['where'][] = $where; |
|
309 | 309 | } elseif (!empty($options['parent'])) { |
310 | - $category = \Ecommerce\Category::get($options['parent']); |
|
311 | - $selectOptions['where'][] = ['tree_path', $category->tree_path . (int) $options['parent'] . '/%', 'LIKE']; |
|
310 | + $category = \Ecommerce\Category::get($options['parent']); |
|
311 | + $selectOptions['where'][] = ['tree_path', $category->tree_path . (int) $options['parent'] . '/%', 'LIKE']; |
|
312 | 312 | } |
313 | 313 | |
314 | 314 | //search |
315 | 315 | if (!empty($options['search'])) { |
316 | - $searchStr = preg_replace('![^A-zА-я0-9 ]!iSu', ' ', $options['search']); |
|
317 | - $searchArr = []; |
|
318 | - foreach (explode(' ', $searchStr) as $part) { |
|
316 | + $searchStr = preg_replace('![^A-zА-я0-9 ]!iSu', ' ', $options['search']); |
|
317 | + $searchArr = []; |
|
318 | + foreach (explode(' ', $searchStr) as $part) { |
|
319 | 319 | $part = trim($part); |
320 | 320 | if ($part && strlen($part) > 2) { |
321 | - $searchArr[] = ['search_index', '%' . $part . '%', 'LIKE']; |
|
321 | + $searchArr[] = ['search_index', '%' . $part . '%', 'LIKE']; |
|
322 | + } |
|
322 | 323 | } |
323 | - } |
|
324 | - if (!empty($searchArr)) { |
|
324 | + if (!empty($searchArr)) { |
|
325 | 325 | $selectOptions['where'][] = $searchArr; |
326 | - } |
|
326 | + } |
|
327 | 327 | } |
328 | 328 | if (empty($this->config['view_empty_warehouse'])) { |
329 | - $warehouseIds = []; |
|
330 | - if (class_exists('Geography\City\Data')) { |
|
329 | + $warehouseIds = []; |
|
330 | + if (class_exists('Geography\City\Data')) { |
|
331 | 331 | $warehouses = \Geography\City\Data::get([['code', 'warehouses'], ['city_id', \Geography\City::$cur->id]]); |
332 | 332 | if ($warehouses && $warehouses->data) { |
333 | - foreach (explode(',', $warehouses->data) as $id) { |
|
333 | + foreach (explode(',', $warehouses->data) as $id) { |
|
334 | 334 | $warehouseIds[$id] = $id; |
335 | - } |
|
335 | + } |
|
336 | + } |
|
336 | 337 | } |
337 | - } |
|
338 | - $selectOptions['where'][] = [ |
|
339 | - '( |
|
338 | + $selectOptions['where'][] = [ |
|
339 | + '( |
|
340 | 340 | (SELECT COALESCE(sum(`' . \Ecommerce\Item\Offer\Warehouse::colPrefix() . 'count`),0) |
341 | 341 | FROM ' . \App::$cur->db->table_prefix . \Ecommerce\Item\Offer\Warehouse::table() . ' iciw |
342 | 342 | WHERE iciw.' . \Ecommerce\Item\Offer\Warehouse::colPrefix() . \Ecommerce\Item\Offer::index() . ' = ' . \Ecommerce\Item\Offer::index() . ' |
@@ -351,28 +351,28 @@ discard block |
||
351 | 351 | ) |
352 | 352 | WHERE iewb.' . \Ecommerce\Warehouse\Block::colPrefix() . \Ecommerce\Item\Offer::index() . ' = ' . \Ecommerce\Item\Offer::index() . ') |
353 | 353 | )', |
354 | - 0, |
|
355 | - '>' |
|
356 | - ]; |
|
354 | + 0, |
|
355 | + '>' |
|
356 | + ]; |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | $selectOptions['group'] = Ecommerce\Item::index(); |
360 | 360 | |
361 | 361 | return $selectOptions; |
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Getting items params with params |
|
366 | - * |
|
367 | - * @param array $params |
|
368 | - * @return array |
|
369 | - */ |
|
370 | - public function getItemsParams($params = []) { |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Getting items params with params |
|
366 | + * |
|
367 | + * @param array $params |
|
368 | + * @return array |
|
369 | + */ |
|
370 | + public function getItemsParams($params = []) { |
|
371 | 371 | $selectOptions = $this->parseOptions($params); |
372 | 372 | |
373 | 373 | $items = Ecommerce\Item::getList($selectOptions); |
374 | 374 | if (!$items) { |
375 | - return []; |
|
375 | + return []; |
|
376 | 376 | } |
377 | 377 | $items = Ecommerce\Item\Param::getList([ |
378 | 378 | 'where' => ['item_id', array_keys($items), 'IN'], |
@@ -380,58 +380,58 @@ discard block |
||
380 | 380 | 'distinct' => \Ecommerce\Item\Option::index() |
381 | 381 | ]); |
382 | 382 | return $items; |
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Getting items with params |
|
387 | - * |
|
388 | - * @param array $params |
|
389 | - * @return array |
|
390 | - */ |
|
391 | - public function getItems($params = []) { |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Getting items with params |
|
387 | + * |
|
388 | + * @param array $params |
|
389 | + * @return array |
|
390 | + */ |
|
391 | + public function getItems($params = []) { |
|
392 | 392 | $selectOptions = $this->parseOptions($params); |
393 | 393 | $items = Ecommerce\Item::getList($selectOptions); |
394 | 394 | return $items; |
395 | - } |
|
396 | - |
|
397 | - /** |
|
398 | - * Return count of items with params |
|
399 | - * |
|
400 | - * @param array $params |
|
401 | - * @return int |
|
402 | - */ |
|
403 | - public function getItemsCount($params = []) { |
|
395 | + } |
|
396 | + |
|
397 | + /** |
|
398 | + * Return count of items with params |
|
399 | + * |
|
400 | + * @param array $params |
|
401 | + * @return int |
|
402 | + */ |
|
403 | + public function getItemsCount($params = []) { |
|
404 | 404 | $selectOptions = $this->parseOptions($params); |
405 | 405 | $selectOptions['distinct'] = \Ecommerce\Item::index(); |
406 | 406 | $counts = Ecommerce\Item::getCount($selectOptions); |
407 | 407 | if (is_array($counts)) { |
408 | - $sum = 0; |
|
409 | - foreach ($counts as $count) { |
|
408 | + $sum = 0; |
|
409 | + foreach ($counts as $count) { |
|
410 | 410 | $sum +=$count['count']; |
411 | - } |
|
412 | - return $sum; |
|
411 | + } |
|
412 | + return $sum; |
|
413 | 413 | } |
414 | 414 | return $counts; |
415 | - } |
|
415 | + } |
|
416 | 416 | |
417 | - public function viewsCategoryList($inherit = true) { |
|
417 | + public function viewsCategoryList($inherit = true) { |
|
418 | 418 | $return = []; |
419 | 419 | if ($inherit) { |
420 | - $return['inherit'] = 'Как у родителя'; |
|
420 | + $return['inherit'] = 'Как у родителя'; |
|
421 | 421 | } |
422 | 422 | $return['itemList'] = 'Список товаров'; |
423 | 423 | $conf = App::$primary->view->template->config; |
424 | 424 | if (!empty($conf['files']['modules']['Ecommerce'])) { |
425 | - foreach ($conf['files']['modules']['Ecommerce'] as $file) { |
|
425 | + foreach ($conf['files']['modules']['Ecommerce'] as $file) { |
|
426 | 426 | if ($file['type'] == 'Category') { |
427 | - $return[$file['file']] = $file['name']; |
|
427 | + $return[$file['file']] = $file['name']; |
|
428 | + } |
|
428 | 429 | } |
429 | - } |
|
430 | 430 | } |
431 | 431 | return $return; |
432 | - } |
|
432 | + } |
|
433 | 433 | |
434 | - public function templatesCategoryList() { |
|
434 | + public function templatesCategoryList() { |
|
435 | 435 | $return = [ |
436 | 436 | 'inherit' => 'Как у родителя', |
437 | 437 | 'current' => 'Текущая тема' |
@@ -440,107 +440,107 @@ discard block |
||
440 | 440 | $conf = App::$primary->view->template->config; |
441 | 441 | |
442 | 442 | if (!empty($conf['files']['aditionTemplateFiels'])) { |
443 | - foreach ($conf['files']['aditionTemplateFiels'] as $file) { |
|
443 | + foreach ($conf['files']['aditionTemplateFiels'] as $file) { |
|
444 | 444 | $return[$file['file']] = '- ' . $file['name']; |
445 | - } |
|
445 | + } |
|
446 | 446 | } |
447 | 447 | return $return; |
448 | - } |
|
448 | + } |
|
449 | 449 | |
450 | - public function cartStatusDetector($event) { |
|
450 | + public function cartStatusDetector($event) { |
|
451 | 451 | $cart = $event['eventObject']; |
452 | 452 | if (!empty($cart->_changedParams['cart_cart_status_id'])) { |
453 | - $cart->date_status = date('Y-m-d H:i:s'); |
|
454 | - $event = new Ecommerce\Cart\Event(['cart_id' => $cart->id, 'user_id' => \Users\User::$cur->id, 'cart_event_type_id' => 5, 'info' => $cart->cart_status_id]); |
|
455 | - $event->save(); |
|
453 | + $cart->date_status = date('Y-m-d H:i:s'); |
|
454 | + $event = new Ecommerce\Cart\Event(['cart_id' => $cart->id, 'user_id' => \Users\User::$cur->id, 'cart_event_type_id' => 5, 'info' => $cart->cart_status_id]); |
|
455 | + $event->save(); |
|
456 | 456 | |
457 | - $prev_status_id = $cart->_changedParams['cart_cart_status_id']; |
|
458 | - $now_status_id = $cart->cart_status_id; |
|
457 | + $prev_status_id = $cart->_changedParams['cart_cart_status_id']; |
|
458 | + $now_status_id = $cart->cart_status_id; |
|
459 | 459 | |
460 | - $status = Ecommerce\Cart\Status::getList(['where' => ['id', implode(',', [$prev_status_id, $now_status_id]), 'IN']]); |
|
460 | + $status = Ecommerce\Cart\Status::getList(['where' => ['id', implode(',', [$prev_status_id, $now_status_id]), 'IN']]); |
|
461 | 461 | |
462 | - $prefix = isset(App::$cur->ecommerce->config['orderPrefix']) ? $config = App::$cur->ecommerce->config['orderPrefix'] : ''; |
|
463 | - \App::$cur->users->AddUserActivity($cart->user_id, 3, "Статус вашего заказа номер {$prefix}{$cart->id} изменился с {$status[$prev_status_id]->name} на {$status[$now_status_id]->name}"); |
|
462 | + $prefix = isset(App::$cur->ecommerce->config['orderPrefix']) ? $config = App::$cur->ecommerce->config['orderPrefix'] : ''; |
|
463 | + \App::$cur->users->AddUserActivity($cart->user_id, 3, "Статус вашего заказа номер {$prefix}{$cart->id} изменился с {$status[$prev_status_id]->name} на {$status[$now_status_id]->name}"); |
|
464 | 464 | |
465 | - if ($cart->cart_status_id == 5) { |
|
465 | + if ($cart->cart_status_id == 5) { |
|
466 | 466 | Inji::$inst->event('ecommerceCartClosed', $cart); |
467 | - } |
|
467 | + } |
|
468 | 468 | } |
469 | 469 | return $cart; |
470 | - } |
|
470 | + } |
|
471 | 471 | |
472 | - public function cardTrigger($event) { |
|
472 | + public function cardTrigger($event) { |
|
473 | 473 | $cart = $event['eventObject']; |
474 | 474 | if ($cart->card) { |
475 | - $sum = 0; |
|
476 | - foreach ($cart->cartItems as $cartItem) { |
|
475 | + $sum = 0; |
|
476 | + foreach ($cart->cartItems as $cartItem) { |
|
477 | 477 | $sum += $cartItem->final_price * $cartItem->count; |
478 | - } |
|
479 | - $cardItemHistory = new Ecommerce\Card\Item\History(); |
|
480 | - $cardItemHistory->amount = $sum; |
|
481 | - $cardItemHistory->card_item_id = $cart->card_item_id; |
|
482 | - $cardItemHistory->save(); |
|
483 | - $cart->card->sum += $sum; |
|
484 | - $cart->card->save(); |
|
478 | + } |
|
479 | + $cardItemHistory = new Ecommerce\Card\Item\History(); |
|
480 | + $cardItemHistory->amount = $sum; |
|
481 | + $cardItemHistory->card_item_id = $cart->card_item_id; |
|
482 | + $cardItemHistory->save(); |
|
483 | + $cart->card->sum += $sum; |
|
484 | + $cart->card->save(); |
|
485 | 485 | } |
486 | 486 | return $cart; |
487 | - } |
|
487 | + } |
|
488 | 488 | |
489 | - public function bonusTrigger($event) { |
|
489 | + public function bonusTrigger($event) { |
|
490 | 490 | $cart = $event['eventObject']; |
491 | 491 | foreach ($cart->cartItems as $cartItem) { |
492 | - foreach ($cartItem->price->offer->bonuses as $bonus) { |
|
492 | + foreach ($cartItem->price->offer->bonuses as $bonus) { |
|
493 | 493 | if ($bonus->limited && $bonus->left <= 0) { |
494 | - continue; |
|
494 | + continue; |
|
495 | 495 | } elseif ($bonus->limited && $bonus->left > 0) { |
496 | - $bonus->left -= 1; |
|
497 | - $bonus->save(); |
|
496 | + $bonus->left -= 1; |
|
497 | + $bonus->save(); |
|
498 | 498 | } |
499 | 499 | switch ($bonus->type) { |
500 | - case'currency': |
|
500 | + case'currency': |
|
501 | 501 | $currency = \Money\Currency::get($bonus->value); |
502 | 502 | $wallets = App::$cur->money->getUserWallets($cart->user->id); |
503 | 503 | $wallets[$currency->id]->diff($bonus->count, 'Бонус за покупку'); |
504 | 504 | break; |
505 | 505 | } |
506 | - } |
|
506 | + } |
|
507 | 507 | } |
508 | 508 | return $cart; |
509 | - } |
|
509 | + } |
|
510 | 510 | |
511 | - function sitemap() { |
|
511 | + function sitemap() { |
|
512 | 512 | $map = []; |
513 | 513 | $zeroItems = \Ecommerce\Item::getList(['where' => ['category_id', 0]]); |
514 | 514 | foreach ($zeroItems as $item) { |
515 | - $map[] = [ |
|
516 | - 'name' => $item->name, |
|
517 | - 'url' => [ |
|
518 | - 'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($item->getHref()) |
|
519 | - ], |
|
520 | - ]; |
|
515 | + $map[] = [ |
|
516 | + 'name' => $item->name, |
|
517 | + 'url' => [ |
|
518 | + 'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($item->getHref()) |
|
519 | + ], |
|
520 | + ]; |
|
521 | 521 | } |
522 | 522 | |
523 | 523 | $categorys = \Ecommerce\Category::getList(['where' => ['parent_id', 0]]); |
524 | 524 | $scan = function($category, $scan) { |
525 | - $map = []; |
|
525 | + $map = []; |
|
526 | 526 | |
527 | - foreach ($category->items as $item) { |
|
527 | + foreach ($category->items as $item) { |
|
528 | 528 | $map[] = [ |
529 | 529 | 'name' => $item->name, |
530 | 530 | 'url' => [ |
531 | 531 | 'loc' => (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . INJI_DOMAIN_NAME . ($item->getHref()) |
532 | 532 | ], |
533 | 533 | ]; |
534 | - } |
|
535 | - foreach ($category->catalogs as $child) { |
|
534 | + } |
|
535 | + foreach ($category->catalogs as $child) { |
|
536 | 536 | $map = array_merge($map, $scan($child, $scan)); |
537 | - } |
|
538 | - return $map; |
|
537 | + } |
|
538 | + return $map; |
|
539 | 539 | }; |
540 | 540 | foreach ($categorys as $category) { |
541 | - $map = array_merge($map, $scan($category, $scan)); |
|
541 | + $map = array_merge($map, $scan($category, $scan)); |
|
542 | 542 | } |
543 | 543 | return $map; |
544 | - } |
|
544 | + } |
|
545 | 545 | |
546 | 546 | } |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | $min = App::$cur->ecommerce->getItems(['sort' => ['price' => 'asc'], 'count' => 1, 'key' => false]); |
5 | 5 | $max = App::$cur->ecommerce->getItems(['sort' => ['price' => 'desc'], 'count' => 1, 'key' => false]); |
6 | 6 | if ($min && $min[0]->getPrice() && $max && $max[0]->getPrice()) { |
7 | - ?> |
|
7 | + ?> |
|
8 | 8 | <h4>Фильтр по цене</h4> |
9 | 9 | <div class="form-group"> |
10 | 10 | <div class="row"> |
@@ -15,28 +15,28 @@ discard block |
||
15 | 15 | <?php |
16 | 16 | } |
17 | 17 | foreach ($options as $option) { |
18 | - ?> |
|
18 | + ?> |
|
19 | 19 | <div class="filter"> |
20 | 20 | |
21 | 21 | <?php |
22 | 22 | switch ($option->type) { |
23 | - case 'radio': |
|
23 | + case 'radio': |
|
24 | 24 | echo "<label>{$option->name}</label>"; |
25 | 25 | foreach ($option->items as $item) { |
26 | - $this->widget('Ui\Form/' . $option->type, [ |
|
27 | - 'label' => $item->name, |
|
28 | - 'name' => "filters[options][{$option->id}]", |
|
29 | - !empty($_GET['filters']['options'][$option->id]) && $_GET['filters']['options'][$option->id] == $item->id ? 'checked' : false, |
|
30 | - 'options' => [ |
|
31 | - 'value' => $item->id, |
|
32 | - ] |
|
33 | - ]); |
|
26 | + $this->widget('Ui\Form/' . $option->type, [ |
|
27 | + 'label' => $item->name, |
|
28 | + 'name' => "filters[options][{$option->id}]", |
|
29 | + !empty($_GET['filters']['options'][$option->id]) && $_GET['filters']['options'][$option->id] == $item->id ? 'checked' : false, |
|
30 | + 'options' => [ |
|
31 | + 'value' => $item->id, |
|
32 | + ] |
|
33 | + ]); |
|
34 | 34 | } |
35 | 35 | break; |
36 | - case 'select': |
|
36 | + case 'select': |
|
37 | 37 | echo "<label>{$option->name}</label>"; |
38 | 38 | foreach ($option->items as $item) { |
39 | - ?> |
|
39 | + ?> |
|
40 | 40 | <div class="radio"> |
41 | 41 | <label> |
42 | 42 | <input type="checkbox" name = 'filters[options][<?= $option->id; ?>][]' value ="<?= $item->id; ?>" <?= !empty($_GET['filters']['options'][$option->id]) && in_array($item->id, $_GET['filters']['options'][$option->id]) ? 'checked' : ''; ?>> |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | <?php |
47 | 47 | } |
48 | 48 | break; |
49 | - default: |
|
49 | + default: |
|
50 | 50 | $this->widget('Ui\Form/' . ($option->type ? $option->type : 'text'), [ |
51 | 51 | 'label' => $option->name, |
52 | 52 | 'name' => "filters[options][{$option->id}]", |
@@ -13,82 +13,82 @@ discard block |
||
13 | 13 | |
14 | 14 | class Item extends \Model { |
15 | 15 | |
16 | - public static $categoryModel = 'Ecommerce\Category'; |
|
17 | - public static $objectName = 'Товар'; |
|
18 | - public static $labels = [ |
|
19 | - 'name' => 'Название', |
|
20 | - 'alias' => 'Алиас', |
|
21 | - 'category_id' => 'Раздел', |
|
22 | - 'description' => 'Описание', |
|
23 | - 'item_type_id' => 'Тип товара', |
|
24 | - 'image_file_id' => 'Изображение', |
|
25 | - 'best' => 'Лучшее предложение', |
|
26 | - 'options' => 'Параметры', |
|
27 | - 'offers' => 'Торговые предложения', |
|
28 | - 'widget' => 'Виджет для отображения в каталоге', |
|
29 | - 'view' => 'Шаблон для отображения полной информации', |
|
30 | - 'deleted' => 'Удален', |
|
31 | - 'imgs' => 'Фото' |
|
32 | - ]; |
|
33 | - public static $cols = [ |
|
34 | - //Основные параметры |
|
35 | - 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
36 | - 'image_file_id' => ['type' => 'image'], |
|
37 | - 'name' => ['type' => 'text'], |
|
38 | - 'alias' => ['type' => 'text'], |
|
39 | - 'description' => ['type' => 'html'], |
|
40 | - 'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
41 | - 'best' => ['type' => 'bool'], |
|
42 | - 'deleted' => ['type' => 'bool'], |
|
43 | - //Системные |
|
44 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
45 | - 'weight' => ['type' => 'number'], |
|
46 | - 'sales' => ['type' => 'number'], |
|
47 | - 'imported' => ['type' => 'text'], |
|
48 | - 'tree_path' => ['type' => 'text'], |
|
49 | - 'search_index' => ['type' => 'text'], |
|
50 | - 'date_create' => ['type' => 'dateTime'], |
|
51 | - 'widget' => ['type' => 'text'], |
|
52 | - 'view' => ['type' => 'text'], |
|
53 | - //Менеджеры |
|
54 | - 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
55 | - 'offers' => ['type' => 'dataManager', 'relation' => 'offers'], |
|
56 | - 'imgs' => ['type' => 'dataManager', 'relation' => 'images'], |
|
57 | - ]; |
|
58 | - public static $dataManagers = [ |
|
59 | - 'manager' => [ |
|
60 | - 'name' => 'Товары', |
|
61 | - 'cols' => [ |
|
62 | - 'name', |
|
63 | - 'imgs', |
|
64 | - 'category_id', |
|
65 | - 'item_type_id', |
|
66 | - 'best', |
|
67 | - 'deleted', |
|
68 | - 'options', |
|
69 | - 'offers', |
|
70 | - ], |
|
71 | - 'categorys' => [ |
|
72 | - 'model' => 'Ecommerce\Category', |
|
73 | - ], |
|
74 | - 'sortMode' => true |
|
75 | - ] |
|
76 | - ]; |
|
77 | - public static $forms = [ |
|
78 | - 'manager' => [ |
|
79 | - 'map' => [ |
|
80 | - ['name', 'alias'], |
|
81 | - ['category_id', 'item_type_id', 'deleted'], |
|
82 | - ['widget', 'view'], |
|
83 | - ['best', 'image_file_id'], |
|
84 | - ['description'], |
|
85 | - ['imgs'], |
|
86 | - ['options'], |
|
87 | - ['offers'], |
|
88 | - ] |
|
89 | - ]]; |
|
16 | + public static $categoryModel = 'Ecommerce\Category'; |
|
17 | + public static $objectName = 'Товар'; |
|
18 | + public static $labels = [ |
|
19 | + 'name' => 'Название', |
|
20 | + 'alias' => 'Алиас', |
|
21 | + 'category_id' => 'Раздел', |
|
22 | + 'description' => 'Описание', |
|
23 | + 'item_type_id' => 'Тип товара', |
|
24 | + 'image_file_id' => 'Изображение', |
|
25 | + 'best' => 'Лучшее предложение', |
|
26 | + 'options' => 'Параметры', |
|
27 | + 'offers' => 'Торговые предложения', |
|
28 | + 'widget' => 'Виджет для отображения в каталоге', |
|
29 | + 'view' => 'Шаблон для отображения полной информации', |
|
30 | + 'deleted' => 'Удален', |
|
31 | + 'imgs' => 'Фото' |
|
32 | + ]; |
|
33 | + public static $cols = [ |
|
34 | + //Основные параметры |
|
35 | + 'category_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'category'], |
|
36 | + 'image_file_id' => ['type' => 'image'], |
|
37 | + 'name' => ['type' => 'text'], |
|
38 | + 'alias' => ['type' => 'text'], |
|
39 | + 'description' => ['type' => 'html'], |
|
40 | + 'item_type_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'type'], |
|
41 | + 'best' => ['type' => 'bool'], |
|
42 | + 'deleted' => ['type' => 'bool'], |
|
43 | + //Системные |
|
44 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
45 | + 'weight' => ['type' => 'number'], |
|
46 | + 'sales' => ['type' => 'number'], |
|
47 | + 'imported' => ['type' => 'text'], |
|
48 | + 'tree_path' => ['type' => 'text'], |
|
49 | + 'search_index' => ['type' => 'text'], |
|
50 | + 'date_create' => ['type' => 'dateTime'], |
|
51 | + 'widget' => ['type' => 'text'], |
|
52 | + 'view' => ['type' => 'text'], |
|
53 | + //Менеджеры |
|
54 | + 'options' => ['type' => 'dataManager', 'relation' => 'options'], |
|
55 | + 'offers' => ['type' => 'dataManager', 'relation' => 'offers'], |
|
56 | + 'imgs' => ['type' => 'dataManager', 'relation' => 'images'], |
|
57 | + ]; |
|
58 | + public static $dataManagers = [ |
|
59 | + 'manager' => [ |
|
60 | + 'name' => 'Товары', |
|
61 | + 'cols' => [ |
|
62 | + 'name', |
|
63 | + 'imgs', |
|
64 | + 'category_id', |
|
65 | + 'item_type_id', |
|
66 | + 'best', |
|
67 | + 'deleted', |
|
68 | + 'options', |
|
69 | + 'offers', |
|
70 | + ], |
|
71 | + 'categorys' => [ |
|
72 | + 'model' => 'Ecommerce\Category', |
|
73 | + ], |
|
74 | + 'sortMode' => true |
|
75 | + ] |
|
76 | + ]; |
|
77 | + public static $forms = [ |
|
78 | + 'manager' => [ |
|
79 | + 'map' => [ |
|
80 | + ['name', 'alias'], |
|
81 | + ['category_id', 'item_type_id', 'deleted'], |
|
82 | + ['widget', 'view'], |
|
83 | + ['best', 'image_file_id'], |
|
84 | + ['description'], |
|
85 | + ['imgs'], |
|
86 | + ['options'], |
|
87 | + ['offers'], |
|
88 | + ] |
|
89 | + ]]; |
|
90 | 90 | |
91 | - public static function indexes() { |
|
91 | + public static function indexes() { |
|
92 | 92 | return [ |
93 | 93 | 'ecommerce_item_item_category_id' => [ |
94 | 94 | 'type' => 'INDEX', |
@@ -109,45 +109,45 @@ discard block |
||
109 | 109 | ] |
110 | 110 | ], |
111 | 111 | ]; |
112 | - } |
|
112 | + } |
|
113 | 113 | |
114 | - public function beforeSave() { |
|
114 | + public function beforeSave() { |
|
115 | 115 | |
116 | 116 | if ($this->id) { |
117 | - $this->search_index = $this->name . ' '; |
|
118 | - if ($this->category) { |
|
117 | + $this->search_index = $this->name . ' '; |
|
118 | + if ($this->category) { |
|
119 | 119 | $this->search_index .= $this->category->name . ' '; |
120 | - } |
|
121 | - if ($this->options) { |
|
120 | + } |
|
121 | + if ($this->options) { |
|
122 | 122 | foreach ($this->options as $option) { |
123 | - if ($option->item_option_searchable && $option->value) { |
|
123 | + if ($option->item_option_searchable && $option->value) { |
|
124 | 124 | if ($option->item_option_type != 'select') { |
125 | - $this->search_index .= $option->value . ' '; |
|
125 | + $this->search_index .= $option->value . ' '; |
|
126 | 126 | } elseif (!empty($option->option->items[$option->value])) { |
127 | - $option->option->items[$option->value]->value . ' '; |
|
127 | + $option->option->items[$option->value]->value . ' '; |
|
128 | + } |
|
128 | 129 | } |
129 | - } |
|
130 | 130 | } |
131 | - } |
|
132 | - if ($this->offers) { |
|
131 | + } |
|
132 | + if ($this->offers) { |
|
133 | 133 | foreach ($this->offers as $offer) { |
134 | - if ($offer->options) { |
|
134 | + if ($offer->options) { |
|
135 | 135 | foreach ($offer->options as $option) { |
136 | - if ($option->item_offer_option_searchable && $option->value) { |
|
136 | + if ($option->item_offer_option_searchable && $option->value) { |
|
137 | 137 | if ($option->item_offer_option_type != 'select') { |
138 | - $this->search_index .= $option->value . ' '; |
|
138 | + $this->search_index .= $option->value . ' '; |
|
139 | 139 | } elseif (!empty($option->option->items[$option->value])) { |
140 | - $option->option->items[$option->value]->value . ' '; |
|
140 | + $option->option->items[$option->value]->value . ' '; |
|
141 | + } |
|
141 | 142 | } |
142 | - } |
|
143 | 143 | } |
144 | - } |
|
144 | + } |
|
145 | 145 | } |
146 | - } |
|
146 | + } |
|
147 | + } |
|
147 | 148 | } |
148 | - } |
|
149 | 149 | |
150 | - public static function relations() { |
|
150 | + public static function relations() { |
|
151 | 151 | |
152 | 152 | return [ |
153 | 153 | 'category' => [ |
@@ -185,55 +185,55 @@ discard block |
||
185 | 185 | 'col' => 'user_id' |
186 | 186 | ] |
187 | 187 | ]; |
188 | - } |
|
188 | + } |
|
189 | 189 | |
190 | - public function getPrice() { |
|
190 | + public function getPrice() { |
|
191 | 191 | $offers = $this->offers(['key' => false]); |
192 | 192 | $curPrice = null; |
193 | 193 | |
194 | 194 | foreach ($offers[0]->prices as $price) { |
195 | - if (!$price->type) { |
|
195 | + if (!$price->type) { |
|
196 | 196 | $curPrice = $price; |
197 | - } elseif ( |
|
198 | - (!$price->type->roles && !$curPrice) || |
|
197 | + } elseif ( |
|
198 | + (!$price->type->roles && !$curPrice) || |
|
199 | 199 | ($price->type->roles && !$curPrice && strpos($price->type->roles, "|" . \Users\User::$cur->role_id . "|") !== false) |
200 | - ) { |
|
200 | + ) { |
|
201 | 201 | $curPrice = $price; |
202 | - } |
|
202 | + } |
|
203 | 203 | } |
204 | 204 | return $curPrice; |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - public function name() { |
|
207 | + public function name() { |
|
208 | 208 | if (!empty(\App::$primary->ecommerce->config['item_option_as_name'])) { |
209 | - $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]); |
|
210 | - if ($param && $param->value) { |
|
209 | + $param = Item\Param::get([['item_id', $this->id], ['item_option_id', \App::$primary->ecommerce->config['item_option_as_name']]]); |
|
210 | + if ($param && $param->value) { |
|
211 | 211 | return $param->value; |
212 | - } |
|
212 | + } |
|
213 | 213 | } |
214 | 214 | return $this->name; |
215 | - } |
|
215 | + } |
|
216 | 216 | |
217 | - public function beforeDelete() { |
|
217 | + public function beforeDelete() { |
|
218 | 218 | if ($this->id) { |
219 | - if ($this->options) { |
|
219 | + if ($this->options) { |
|
220 | 220 | foreach ($this->options as $option) { |
221 | - $option->delete(); |
|
221 | + $option->delete(); |
|
222 | + } |
|
222 | 223 | } |
223 | - } |
|
224 | - if ($this->offers) { |
|
224 | + if ($this->offers) { |
|
225 | 225 | foreach ($this->offers as $offer) { |
226 | - $offer->delete(); |
|
226 | + $offer->delete(); |
|
227 | + } |
|
227 | 228 | } |
228 | - } |
|
229 | - if ($this->image) { |
|
229 | + if ($this->image) { |
|
230 | 230 | $this->image->delete(); |
231 | - } |
|
231 | + } |
|
232 | + } |
|
232 | 233 | } |
233 | - } |
|
234 | 234 | |
235 | - public function getHref() { |
|
235 | + public function getHref() { |
|
236 | 236 | return "/ecommerce/view/{$this->pk()}"; |
237 | - } |
|
237 | + } |
|
238 | 238 | |
239 | 239 | } |
@@ -13,65 +13,65 @@ |
||
13 | 13 | |
14 | 14 | class Sums extends \Object { |
15 | 15 | |
16 | - public $sums = []; |
|
16 | + public $sums = []; |
|
17 | 17 | |
18 | - public function __construct($sums) { |
|
18 | + public function __construct($sums) { |
|
19 | 19 | $this->sums = $sums; |
20 | - } |
|
20 | + } |
|
21 | 21 | |
22 | - function plus(Sums $sums) { |
|
22 | + function plus(Sums $sums) { |
|
23 | 23 | $newSums = $this->sums; |
24 | 24 | foreach ($sums->sums as $currency_id => $sum) { |
25 | - $newSums[$currency_id] = isset($newSums[$currency_id]) ? $newSums[$currency_id] + $sum : $sum; |
|
25 | + $newSums[$currency_id] = isset($newSums[$currency_id]) ? $newSums[$currency_id] + $sum : $sum; |
|
26 | 26 | } |
27 | 27 | return new Sums($newSums); |
28 | - } |
|
28 | + } |
|
29 | 29 | |
30 | - function minus(Sums $sums) { |
|
30 | + function minus(Sums $sums) { |
|
31 | 31 | $newSums = $this->sums; |
32 | 32 | foreach ($sums->sums as $currency_id => $sum) { |
33 | - $newSums[$currency_id] = isset($newSums[$currency_id]) ? $newSums[$currency_id] - $sum : -$sum; |
|
33 | + $newSums[$currency_id] = isset($newSums[$currency_id]) ? $newSums[$currency_id] - $sum : -$sum; |
|
34 | 34 | } |
35 | 35 | return new Sums($newSums); |
36 | - } |
|
36 | + } |
|
37 | 37 | |
38 | 38 | //Equal, Less and Greater |
39 | - public function greater(Sums $sums) { |
|
39 | + public function greater(Sums $sums) { |
|
40 | 40 | if (count($this->sums) == count($sums->sums) && isset($sums->sums[key($this->sums)])) { |
41 | - return current($this->sums) > current($sums->sums); |
|
41 | + return current($this->sums) > current($sums->sums); |
|
42 | + } |
|
42 | 43 | } |
43 | - } |
|
44 | 44 | |
45 | - public function equal(Sums $sums) { |
|
45 | + public function equal(Sums $sums) { |
|
46 | 46 | if (count($this->sums) == count($sums->sums) && isset($sums->sums[key($this->sums)])) { |
47 | - return current($this->sums) == current($sums->sums); |
|
47 | + return current($this->sums) == current($sums->sums); |
|
48 | + } |
|
48 | 49 | } |
49 | - } |
|
50 | 50 | |
51 | - function __toString() { |
|
51 | + function __toString() { |
|
52 | 52 | $string = ''; |
53 | 53 | $first = true; |
54 | 54 | foreach ($this->sums as $currency_id => $sum) { |
55 | - if ($first) { |
|
55 | + if ($first) { |
|
56 | 56 | $first = false; |
57 | - } else { |
|
57 | + } else { |
|
58 | 58 | $string.= '<br />'; |
59 | - } |
|
60 | - $string.= '<span style="white-space:nowrap;">'; |
|
61 | - $string.= number_format($sum, 2, '.', ' '); |
|
62 | - if (\App::$cur->money) { |
|
59 | + } |
|
60 | + $string.= '<span style="white-space:nowrap;">'; |
|
61 | + $string.= number_format($sum, 2, '.', ' '); |
|
62 | + if (\App::$cur->money) { |
|
63 | 63 | $currency = \Money\Currency::get($currency_id); |
64 | 64 | if ($currency) { |
65 | - $string.= ' ' . $currency->acronym(); |
|
65 | + $string.= ' ' . $currency->acronym(); |
|
66 | 66 | } else { |
67 | - $string.= ' руб.'; |
|
67 | + $string.= ' руб.'; |
|
68 | 68 | } |
69 | - } else { |
|
69 | + } else { |
|
70 | 70 | $string.= ' руб.'; |
71 | - } |
|
72 | - $string.= '</span>'; |
|
71 | + } |
|
72 | + $string.= '</span>'; |
|
73 | 73 | } |
74 | 74 | return $string; |
75 | - } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | } |
@@ -10,145 +10,145 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class CartController extends Controller { |
12 | 12 | |
13 | - public function indexAction() { |
|
13 | + public function indexAction() { |
|
14 | 14 | $cart = ''; |
15 | 15 | $deliverys = \Ecommerce\Delivery::getList(['order' => ['weight', 'ASC']]); |
16 | 16 | $payTypes = \Ecommerce\PayType::getList(['order' => ['weight', 'ASC']]); |
17 | 17 | if (!empty($_SESSION['cart']['cart_id'])) { |
18 | - $cart = Ecommerce\Cart::get($_SESSION['cart']['cart_id']); |
|
19 | - if (!empty($_POST)) { |
|
18 | + $cart = Ecommerce\Cart::get($_SESSION['cart']['cart_id']); |
|
19 | + if (!empty($_POST)) { |
|
20 | 20 | $error = false; |
21 | 21 | if (!Users\User::$cur->id) { |
22 | - $user_id = $this->Users->registration($_POST, true); |
|
23 | - if (!$user_id) { |
|
22 | + $user_id = $this->Users->registration($_POST, true); |
|
23 | + if (!$user_id) { |
|
24 | 24 | $error = true; |
25 | - } else { |
|
25 | + } else { |
|
26 | 26 | $user = Users\User::get($user_id); |
27 | - } |
|
27 | + } |
|
28 | 28 | } else { |
29 | - $user = Users\User::$cur; |
|
29 | + $user = Users\User::$cur; |
|
30 | 30 | } |
31 | 31 | $ids = []; |
32 | 32 | if (!empty($_POST['cartItems'])) { |
33 | - foreach ($_POST['cartItems'] as $cartItemId => $cartItemCont) { |
|
33 | + foreach ($_POST['cartItems'] as $cartItemId => $cartItemCont) { |
|
34 | 34 | $cartItem = \Ecommerce\Cart\Item::get((int) $cartItemId); |
35 | 35 | if (!$cartItem) { |
36 | - continue; |
|
36 | + continue; |
|
37 | 37 | } |
38 | 38 | if ($cartItem->cart_id != $cart->id) { |
39 | - continue; |
|
39 | + continue; |
|
40 | 40 | } |
41 | 41 | $count = (float) $cartItemCont; |
42 | 42 | if ($count < 0.001) { |
43 | - $count = 1; |
|
43 | + $count = 1; |
|
44 | 44 | } |
45 | 45 | $cartItem->count = $count; |
46 | 46 | $cartItem->save(); |
47 | 47 | $ids[] = $cartItemId; |
48 | - } |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | foreach ($cart->cartItems as $cartItem) { |
51 | - if (!in_array($cartItem->id, $ids)) { |
|
51 | + if (!in_array($cartItem->id, $ids)) { |
|
52 | 52 | $cartItem->delete(); |
53 | - } |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | $cart = Ecommerce\Cart::get($cart->id); |
56 | 56 | if (!$cart->cartItems) { |
57 | - Tools::redirect('/ecommerce', 'Ваша корзина пуста'); |
|
57 | + Tools::redirect('/ecommerce', 'Ваша корзина пуста'); |
|
58 | 58 | } |
59 | 59 | if (empty($this->module->config['sell_over_warehouse'])) { |
60 | - foreach ($cart->cartItems as $cartitem) { |
|
60 | + foreach ($cart->cartItems as $cartitem) { |
|
61 | 61 | $warecount = $cartitem->price->offer->warehouseCount($cart->id); |
62 | 62 | if ($cartitem->count > $warecount) { |
63 | - $error = true; |
|
64 | - Msg::add('Вы заказали <b>' . $cartitem->item->name . '</b> больше чем есть на складе. на складе: <b>' . $warecount . '</b>', 'danger'); |
|
63 | + $error = true; |
|
64 | + Msg::add('Вы заказали <b>' . $cartitem->item->name . '</b> больше чем есть на складе. на складе: <b>' . $warecount . '</b>', 'danger'); |
|
65 | + } |
|
65 | 66 | } |
66 | - } |
|
67 | 67 | } |
68 | 68 | if ($deliverys && empty($deliverys[$_POST['delivery']])) { |
69 | - $error = 1; |
|
70 | - Msg::add('Выберите способ доставки'); |
|
69 | + $error = 1; |
|
70 | + Msg::add('Выберите способ доставки'); |
|
71 | 71 | } elseif ($deliverys && !empty($deliverys[$_POST['delivery']])) { |
72 | - $cart->delivery_id = $_POST['delivery']; |
|
73 | - foreach ($deliverys[$cart->delivery_id]->fields as $field) { |
|
72 | + $cart->delivery_id = $_POST['delivery']; |
|
73 | + foreach ($deliverys[$cart->delivery_id]->fields as $field) { |
|
74 | 74 | if (empty($_POST['deliveryFields'][$field->id]) && $field->required) { |
75 | - $error = 1; |
|
76 | - Msg::add('Вы не указали: ' . $field->name); |
|
75 | + $error = 1; |
|
76 | + Msg::add('Вы не указали: ' . $field->name); |
|
77 | + } |
|
77 | 78 | } |
78 | - } |
|
79 | 79 | } |
80 | 80 | if ($payTypes && (empty($_POST['payType']) || empty($payTypes[$_POST['payType']]))) { |
81 | - $error = 1; |
|
82 | - Msg::add('Выберите способ оплаты'); |
|
81 | + $error = 1; |
|
82 | + Msg::add('Выберите способ оплаты'); |
|
83 | 83 | } elseif ($payTypes && !empty($payTypes[$_POST['payType']])) { |
84 | - $payType = $payTypes[$_POST['payType']]; |
|
85 | - $cart->paytype_id = $payType->id; |
|
84 | + $payType = $payTypes[$_POST['payType']]; |
|
85 | + $cart->paytype_id = $payType->id; |
|
86 | 86 | } else { |
87 | - $payType = null; |
|
87 | + $payType = null; |
|
88 | 88 | } |
89 | 89 | foreach (\Ecommerce\UserAdds\Field::getList() as $field) { |
90 | - if (empty($_POST['userAdds']['fields'][$field->id]) && $field->required) { |
|
90 | + if (empty($_POST['userAdds']['fields'][$field->id]) && $field->required) { |
|
91 | 91 | $error = 1; |
92 | 92 | Msg::add('Вы не указали: ' . $field->name); |
93 | - } |
|
93 | + } |
|
94 | 94 | } |
95 | 95 | if (!empty($_POST['discounts']['card_item_id'])) { |
96 | - $userCard = \Ecommerce\Card\Item::get((int) $_POST['discounts']['card_item_id']); |
|
97 | - if (!$userCard) { |
|
96 | + $userCard = \Ecommerce\Card\Item::get((int) $_POST['discounts']['card_item_id']); |
|
97 | + if (!$userCard) { |
|
98 | 98 | $error = true; |
99 | 99 | Msg::add('Такой карты не существует'); |
100 | - } elseif ($userCard->user_id != $user->id) { |
|
100 | + } elseif ($userCard->user_id != $user->id) { |
|
101 | 101 | $error = true; |
102 | 102 | Msg::add('Это не ваша карта'); |
103 | - } else { |
|
103 | + } else { |
|
104 | 104 | $cart->card_item_id = $userCard->id; |
105 | - } |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | $cart->save(); |
108 | 108 | if (!$error && !empty($_POST['action']) && $_POST['action'] = 'order') { |
109 | - $cart->user_id = $user->user_id; |
|
110 | - $this->module->parseFields($_POST['userAdds']['fields'], $cart); |
|
111 | - if ($payTypes && !empty($payTypes[$cart->paytype_id]) && !empty($_POST['deliveryFields'])) { |
|
109 | + $cart->user_id = $user->user_id; |
|
110 | + $this->module->parseFields($_POST['userAdds']['fields'], $cart); |
|
111 | + if ($payTypes && !empty($payTypes[$cart->paytype_id]) && !empty($_POST['deliveryFields'])) { |
|
112 | 112 | $this->module->parseDeliveryFields($_POST['deliveryFields'], $cart, $deliverys[$cart->delivery_id]->fields); |
113 | - } |
|
114 | - $cart->cart_status_id = 2; |
|
115 | - $cart->comment = !empty($_POST['comment']) ? htmlspecialchars($_POST['comment']) : ''; |
|
116 | - $cart->date_status = date('Y-m-d H:i:s'); |
|
117 | - $cart->complete_data = date('Y-m-d H:i:s'); |
|
118 | - $cart->warehouse_block = 1; |
|
119 | - $cart->save(); |
|
113 | + } |
|
114 | + $cart->cart_status_id = 2; |
|
115 | + $cart->comment = !empty($_POST['comment']) ? htmlspecialchars($_POST['comment']) : ''; |
|
116 | + $cart->date_status = date('Y-m-d H:i:s'); |
|
117 | + $cart->complete_data = date('Y-m-d H:i:s'); |
|
118 | + $cart->warehouse_block = 1; |
|
119 | + $cart->save(); |
|
120 | 120 | |
121 | - $cart = \Ecommerce\Cart::get($cart->id); |
|
122 | - foreach ($cart->cartItems as $cartItem) { |
|
121 | + $cart = \Ecommerce\Cart::get($cart->id); |
|
122 | + foreach ($cart->cartItems as $cartItem) { |
|
123 | 123 | $cartItem->discount = $cartItem->discount(); |
124 | 124 | $cartItem->final_price = $cartItem->price->price - $cartItem->discount; |
125 | 125 | $cartItem->save(); |
126 | - } |
|
127 | - $cart = \Ecommerce\Cart::get($cart->id); |
|
128 | - if (!empty(\App::$cur->ecommerce->config['notify_mail'])) { |
|
126 | + } |
|
127 | + $cart = \Ecommerce\Cart::get($cart->id); |
|
128 | + if (!empty(\App::$cur->ecommerce->config['notify_mail'])) { |
|
129 | 129 | $text = 'Перейдите в админ панель чтобы просмотреть новый заказ <a href = "http://' . idn_to_utf8(INJI_DOMAIN_NAME) . '/admin/ecommerce/Cart">Админ панель</a>'; |
130 | 130 | $title = 'Новый заказ в интернет магазине на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
131 | 131 | \Tools::sendMail('noreply@' . INJI_DOMAIN_NAME, \App::$cur->ecommerce->config['notify_mail'], $title, $text); |
132 | - } |
|
133 | - if ($this->notifications) { |
|
132 | + } |
|
133 | + if ($this->notifications) { |
|
134 | 134 | $notification = new Notifications\Notification(); |
135 | 135 | $notification->name = 'Новый заказ в интернет магазине на сайте ' . idn_to_utf8(INJI_DOMAIN_NAME); |
136 | 136 | $notification->text = 'Перейдите в админ панель чтобы просмотреть новый заказ'; |
137 | 137 | $notification->chanel_id = $this->notifications->getChanel('Ecommerce-orders')->id; |
138 | 138 | $notification->save(); |
139 | - } |
|
140 | - $handlers = $this->ecommerce->getSnippets('payTypeHandler'); |
|
141 | - $redirect = ['/ecommerce/cart/success']; |
|
142 | - if ($payType && !empty($handlers[$payType->handler]['handler'])) { |
|
139 | + } |
|
140 | + $handlers = $this->ecommerce->getSnippets('payTypeHandler'); |
|
141 | + $redirect = ['/ecommerce/cart/success']; |
|
142 | + if ($payType && !empty($handlers[$payType->handler]['handler'])) { |
|
143 | 143 | $newRedirect = $handlers[$payType->handler]['handler']($cart); |
144 | 144 | if (!empty($newRedirect)) { |
145 | - $redirect = $newRedirect; |
|
145 | + $redirect = $newRedirect; |
|
146 | + } |
|
146 | 147 | } |
147 | - } |
|
148 | - unset($_SESSION['cart']['cart_id']); |
|
149 | - call_user_func_array(['Tools', 'redirect'], $redirect); |
|
148 | + unset($_SESSION['cart']['cart_id']); |
|
149 | + call_user_func_array(['Tools', 'redirect'], $redirect); |
|
150 | + } |
|
150 | 151 | } |
151 | - } |
|
152 | 152 | } |
153 | 153 | $this->view->setTitle('Корзина'); |
154 | 154 | $bread = []; |
@@ -161,12 +161,12 @@ discard block |
||
161 | 161 | 'href' => '/ecommerce/cart' |
162 | 162 | ]; |
163 | 163 | $this->view->page(['data' => compact('cart', 'items', 'deliverys', 'payTypes', 'packItem', 'bread')]); |
164 | - } |
|
164 | + } |
|
165 | 165 | |
166 | - public function orderDetailAction($id = 0) { |
|
166 | + public function orderDetailAction($id = 0) { |
|
167 | 167 | $cart = Ecommerce\Cart::get((int) $id); |
168 | 168 | if ($cart->user_id != Users\User::$cur->id) { |
169 | - $this->url->redirect('/', 'Это не ваша корзина'); |
|
169 | + $this->url->redirect('/', 'Это не ваша корзина'); |
|
170 | 170 | } |
171 | 171 | $bread[] = [ |
172 | 172 | 'text' => 'Каталог', |
@@ -182,54 +182,54 @@ discard block |
||
182 | 182 | ]; |
183 | 183 | $this->view->setTitle('Заказ №' . $cart->id); |
184 | 184 | $this->view->page(['data' => compact('cart', 'bread')]); |
185 | - } |
|
185 | + } |
|
186 | 186 | |
187 | - public function continueAction($id = 0) { |
|
187 | + public function continueAction($id = 0) { |
|
188 | 188 | $cart = \Ecommerce\Cart::get((int) $id); |
189 | 189 | if ($cart->user_id != Users\User::$cur->id) { |
190 | - Tools::redirect('/', 'Это не ваша корзина'); |
|
190 | + Tools::redirect('/', 'Это не ваша корзина'); |
|
191 | 191 | } |
192 | 192 | if ($cart->cart_status_id > 1) { |
193 | - Tools::redirect('/', 'Корзина уже оформлена'); |
|
193 | + Tools::redirect('/', 'Корзина уже оформлена'); |
|
194 | 194 | } |
195 | 195 | $_SESSION['cart']['cart_id'] = $cart->id; |
196 | 196 | Tools::redirect('/ecommerce/cart'); |
197 | - } |
|
197 | + } |
|
198 | 198 | |
199 | - public function deleteAction($id = 0) { |
|
199 | + public function deleteAction($id = 0) { |
|
200 | 200 | $cart = \Ecommerce\Cart::get((int) $id); |
201 | 201 | if ($cart->user_id != Users\User::$cur->id) { |
202 | - Tools::redirect('/', 'Это не ваша корзина'); |
|
202 | + Tools::redirect('/', 'Это не ваша корзина'); |
|
203 | 203 | } |
204 | 204 | if ($cart->cart_status_id > 1) { |
205 | - Tools::redirect('/', 'Корзина уже оформлена'); |
|
205 | + Tools::redirect('/', 'Корзина уже оформлена'); |
|
206 | 206 | } |
207 | 207 | if (!empty($_SESSION['cart']['cart_id']) && $_SESSION['cart']['cart_id'] == $cart->id) { |
208 | - unset($_SESSION['cart']['cart_id']); |
|
208 | + unset($_SESSION['cart']['cart_id']); |
|
209 | 209 | } |
210 | 210 | $cart->delete(); |
211 | 211 | Tools::redirect('/users/cabinet/ecommerceOrdersHistory', 'Корзина была удалена', 'success'); |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - public function refillAction($id = 0) { |
|
214 | + public function refillAction($id = 0) { |
|
215 | 215 | $cart = \Ecommerce\Cart::get((int) $id); |
216 | 216 | if ($cart->user_id != Users\User::$cur->id) { |
217 | - Tools::redirect('/', 'Это не ваша корзина'); |
|
217 | + Tools::redirect('/', 'Это не ваша корзина'); |
|
218 | 218 | } |
219 | 219 | if (!empty($_SESSION['cart']['cart_id'])) { |
220 | - unset($_SESSION['cart']['cart_id']); |
|
220 | + unset($_SESSION['cart']['cart_id']); |
|
221 | 221 | } |
222 | 222 | $newCart = $this->ecommerce->getCurCart(); |
223 | 223 | foreach ($cart->cartItems as $cartitem) { |
224 | - $newCart->addItem($cartitem->item_offer_price_id, $cartitem->count); |
|
224 | + $newCart->addItem($cartitem->item_offer_price_id, $cartitem->count); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | $newCart->save(); |
228 | 228 | |
229 | 229 | Tools::redirect('/ecommerce/cart/'); |
230 | - } |
|
230 | + } |
|
231 | 231 | |
232 | - public function successAction() { |
|
232 | + public function successAction() { |
|
233 | 233 | $bread = []; |
234 | 234 | $bread[] = [ |
235 | 235 | 'text' => 'Каталог', |
@@ -245,70 +245,70 @@ discard block |
||
245 | 245 | ]; |
246 | 246 | $this->view->setTitle('Заказ принят'); |
247 | 247 | $this->view->page(['data' => compact('bread')]); |
248 | - } |
|
248 | + } |
|
249 | 249 | |
250 | - public function addAction() { |
|
250 | + public function addAction() { |
|
251 | 251 | $result = new Server\Result(); |
252 | 252 | if (empty($_GET['itemOfferPriceId'])) { |
253 | - $result->success = false; |
|
254 | - $result->content = 'Произошла непредвиденная ошибка при добавлении товара'; |
|
255 | - $result->send(); |
|
253 | + $result->success = false; |
|
254 | + $result->content = 'Произошла непредвиденная ошибка при добавлении товара'; |
|
255 | + $result->send(); |
|
256 | 256 | } |
257 | 257 | $price = \Ecommerce\Item\Offer\Price::get((int) $_GET['itemOfferPriceId']); |
258 | 258 | if (!$price) { |
259 | - $result->success = false; |
|
260 | - $result->content = 'Такой цены не найдено'; |
|
261 | - $result->send(); |
|
259 | + $result->success = false; |
|
260 | + $result->content = 'Такой цены не найдено'; |
|
261 | + $result->send(); |
|
262 | 262 | } |
263 | 263 | $item = $price->offer->item; |
264 | 264 | |
265 | 265 | if (!$item) { |
266 | - $result->success = false; |
|
267 | - $result->content = 'Такого товара не существует'; |
|
268 | - $result->send(); |
|
266 | + $result->success = false; |
|
267 | + $result->content = 'Такого товара не существует'; |
|
268 | + $result->send(); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | $item->sales ++; |
272 | 272 | $item->save(); |
273 | 273 | |
274 | 274 | if (empty($_GET['count'])) |
275 | - $count = 1; |
|
275 | + $count = 1; |
|
276 | 276 | else |
277 | - $count = (float) $_GET['count']; |
|
277 | + $count = (float) $_GET['count']; |
|
278 | 278 | |
279 | 279 | $cart = $this->ecommerce->getCurCart(); |
280 | 280 | $stages = Ecommerce\Cart\Stage::getList(); |
281 | 281 | if (empty($this->module->config['sell_over_warehouse']) && $price->offer->warehouseCount() < $count) { |
282 | - $result->success = false; |
|
283 | - $result->content = 'На складе недостаточно товара! Доступно: ' . $price->offer->warehouseCount(); |
|
284 | - $result->send(); |
|
282 | + $result->success = false; |
|
283 | + $result->content = 'На складе недостаточно товара! Доступно: ' . $price->offer->warehouseCount(); |
|
284 | + $result->send(); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | $isset = false; |
288 | 288 | foreach ($cart->cartItems as $cartItem) { |
289 | - if ($cartItem->item_id == $item->id && $cartItem->item_offer_price_id == $price->id) { |
|
289 | + if ($cartItem->item_id == $item->id && $cartItem->item_offer_price_id == $price->id) { |
|
290 | 290 | $cartItem->count += $count; |
291 | 291 | $cartItem->save(); |
292 | 292 | $isset = true; |
293 | 293 | break; |
294 | - } |
|
294 | + } |
|
295 | 295 | } |
296 | 296 | if (!$isset) { |
297 | - $cart->addItem($price->id, $count); |
|
297 | + $cart->addItem($price->id, $count); |
|
298 | 298 | } |
299 | 299 | $cart->date_last_activ = date('Y-m-d H:i:s'); |
300 | 300 | $cart->calc(); |
301 | 301 | $result->successMsg = '<a href="/ecommerce/view/' . $item->id . '">' . $item->name() . ($price->offer->name() ? ' (' . $price->offer->name() . ')' : '') . '</a> добавлен <a href="/ecommerce/cart">в корзину покупок</a>!'; |
302 | 302 | $result->send(); |
303 | - } |
|
303 | + } |
|
304 | 304 | |
305 | - public function getcartAction() { |
|
305 | + public function getcartAction() { |
|
306 | 306 | $result = new Server\Result(); |
307 | 307 | ob_start(); |
308 | 308 | $this->view->widget('Ecommerce\cart'); |
309 | 309 | $result->content = ob_get_contents(); |
310 | 310 | ob_end_clean(); |
311 | 311 | $result->send(); |
312 | - } |
|
312 | + } |
|
313 | 313 | |
314 | 314 | } |
@@ -2,57 +2,57 @@ |
||
2 | 2 | <div class="col-md-4"> |
3 | 3 | <ul class="nav nav-pills nav-stacked"> |
4 | 4 | <?php |
5 | - $hiddenId = Tools::randomString(); |
|
6 | - foreach ($deliverys as $delivery) { |
|
5 | + $hiddenId = Tools::randomString(); |
|
6 | + foreach ($deliverys as $delivery) { |
|
7 | 7 | if ((!empty($_POST['delivery']) && $_POST['delivery'] == $delivery->id) || ($cart->delivery && $delivery->id == $cart->delivery->id)) { |
8 | - $checked = 'checked'; |
|
8 | + $checked = 'checked'; |
|
9 | 9 | } else { |
10 | - $checked = ''; |
|
10 | + $checked = ''; |
|
11 | 11 | } |
12 | 12 | echo '<li' . ($checked ? ' class="active"' : '') . '><a href = "#" onclick = "document.getElementById(\'' . $hiddenId . '\').value=\'' . $delivery->id . '\';inji.Ecommerce.Cart.calcSum();return false;">'; |
13 | 13 | echo $delivery->name; |
14 | 14 | echo '</a></li>'; |
15 | - } |
|
16 | - $form->input('hidden', "delivery", '', [ |
|
17 | - 'value' => $cart->delivery_id, |
|
18 | - 'attributes' => [ |
|
19 | - 'id' => $hiddenId |
|
20 | - ], |
|
21 | - ]); |
|
22 | - ?> |
|
15 | + } |
|
16 | + $form->input('hidden', "delivery", '', [ |
|
17 | + 'value' => $cart->delivery_id, |
|
18 | + 'attributes' => [ |
|
19 | + 'id' => $hiddenId |
|
20 | + ], |
|
21 | + ]); |
|
22 | + ?> |
|
23 | 23 | </ul> |
24 | 24 | </div> |
25 | 25 | <div class="col-md-8"> |
26 | 26 | <?php |
27 | 27 | if ($cart->delivery) { |
28 | - echo "<h4>Информация о доставке</h4>"; |
|
29 | - if ($cart->delivery->price_text || $cart->delivery->price) { |
|
28 | + echo "<h4>Информация о доставке</h4>"; |
|
29 | + if ($cart->delivery->price_text || $cart->delivery->price) { |
|
30 | 30 | echo "<div>Стоимость доставки: <b>" . ($cart->delivery->price_text ? $cart->delivery->price_text : ( $cart->delivery->price . ' ' . ($cart->delivery->currency ? $cart->delivery->currency->acronym() : 'руб.') )) . '</b></div>'; |
31 | - } |
|
32 | - if ((float) $cart->delivery->max_cart_price) { |
|
31 | + } |
|
32 | + if ((float) $cart->delivery->max_cart_price) { |
|
33 | 33 | echo '<div>При заказе товаров на сумму от ' . $cart->delivery->max_cart_price . ' руб - бесплатно</div>'; |
34 | - } |
|
35 | - echo $cart->delivery->info; |
|
36 | - if ($cart->delivery->fields) { |
|
34 | + } |
|
35 | + echo $cart->delivery->info; |
|
36 | + if ($cart->delivery->fields) { |
|
37 | 37 | echo '<hr />'; |
38 | 38 | foreach ($cart->delivery->fields as $field) { |
39 | - $options = ['required' => $field->required]; |
|
40 | - if ($field->type == 'radio') { |
|
39 | + $options = ['required' => $field->required]; |
|
40 | + if ($field->type == 'radio') { |
|
41 | 41 | $values = $field->fieldItems(['forSelect' => true]); |
42 | 42 | foreach ($values as $key => $value) { |
43 | - $options['value'] = $key; |
|
44 | - $form->input($field->type, "deliveryFields[{$field->id}]", $value, $options); |
|
43 | + $options['value'] = $key; |
|
44 | + $form->input($field->type, "deliveryFields[{$field->id}]", $value, $options); |
|
45 | 45 | } |
46 | - } else { |
|
46 | + } else { |
|
47 | 47 | if ($field->type == 'select') { |
48 | - $options['values'] = $field->fieldItems(['forSelect' => true]); |
|
48 | + $options['values'] = $field->fieldItems(['forSelect' => true]); |
|
49 | 49 | } |
50 | 50 | $form->input($field->type, "deliveryFields[{$field->id}]", $field->name, $options); |
51 | - } |
|
51 | + } |
|
52 | + } |
|
52 | 53 | } |
53 | - } |
|
54 | 54 | } else { |
55 | - echo "<h4>Выберите способ доставки</h4>"; |
|
55 | + echo "<h4>Выберите способ доставки</h4>"; |
|
56 | 56 | } |
57 | 57 | ?> |
58 | 58 | </div> |