@@ -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> |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | } else { |
10 | 10 | $checked = ''; |
11 | 11 | } |
12 | - echo '<li' . ($checked ? ' class="active"' : '') . '><a href = "#" onclick = "document.getElementById(\'' . $hiddenId . '\').value=\'' . $delivery->id . '\';inji.Ecommerce.Cart.calcSum();return false;">'; |
|
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 | 15 | } |
@@ -27,10 +27,10 @@ discard block |
||
27 | 27 | if ($cart->delivery) { |
28 | 28 | echo "<h4>Информация о доставке</h4>"; |
29 | 29 | if ($cart->delivery->price_text || $cart->delivery->price) { |
30 | - echo "<div>Стоимость доставки: <b>" . ($cart->delivery->price_text ? $cart->delivery->price_text : ( $cart->delivery->price . ' ' . ($cart->delivery->currency ? $cart->delivery->currency->acronym() : 'руб.') )) . '</b></div>'; |
|
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 | 31 | } |
32 | 32 | if ((float) $cart->delivery->max_cart_price) { |
33 | - echo '<div>При заказе товаров на сумму от ' . $cart->delivery->max_cart_price . ' руб - бесплатно</div>'; |
|
33 | + echo '<div>При заказе товаров на сумму от '.$cart->delivery->max_cart_price.' руб - бесплатно</div>'; |
|
34 | 34 | } |
35 | 35 | echo $cart->delivery->info; |
36 | 36 | if ($cart->delivery->fields) { |
@@ -13,9 +13,9 @@ discard block |
||
13 | 13 | |
14 | 14 | class Cart extends \Model { |
15 | 15 | |
16 | - public static $objectName = 'Корзины'; |
|
16 | + public static $objectName = 'Корзины'; |
|
17 | 17 | |
18 | - public static function indexes() { |
|
18 | + public static function indexes() { |
|
19 | 19 | return [ |
20 | 20 | 'ecommerce_cartStatusBlock' => [ |
21 | 21 | 'type' => 'INDEX', |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | ] |
38 | 38 | ], |
39 | 39 | ]; |
40 | - } |
|
40 | + } |
|
41 | 41 | |
42 | - public static function relations() { |
|
42 | + public static function relations() { |
|
43 | 43 | return [ |
44 | 44 | 'user' => [ |
45 | 45 | 'model' => 'Users\User', |
@@ -97,279 +97,279 @@ discard block |
||
97 | 97 | 'model' => 'Ecommerce\Discount', |
98 | 98 | ] |
99 | 99 | ]; |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | - public function beforeDelete() { |
|
102 | + public function beforeDelete() { |
|
103 | 103 | foreach ($this->cartItems as $cartItem) { |
104 | - $cartItem->delete(); |
|
104 | + $cartItem->delete(); |
|
105 | 105 | } |
106 | 106 | foreach ($this->infos as $info) { |
107 | - $info->delete(); |
|
107 | + $info->delete(); |
|
108 | 108 | } |
109 | 109 | foreach ($this->extras as $extra) { |
110 | - $extra->delete(); |
|
110 | + $extra->delete(); |
|
111 | 111 | } |
112 | 112 | foreach ($this->events as $event) { |
113 | - $event->delete(); |
|
113 | + $event->delete(); |
|
114 | + } |
|
114 | 115 | } |
115 | - } |
|
116 | 116 | |
117 | - public static $labels = [ |
|
118 | - 'user_id' => 'Пользователь', |
|
119 | - 'cart_status_id' => 'Статус', |
|
120 | - 'delivery_id' => 'Доставка', |
|
121 | - 'comment' => 'Комментарий', |
|
122 | - 'bonus_used' => 'Выгодные рубли', |
|
123 | - 'complete_data' => 'Время заказа', |
|
124 | - 'info' => 'Информация', |
|
125 | - 'items' => 'Товары', |
|
126 | - 'paytype_id' => 'Способ оплаты', |
|
127 | - 'payed' => 'Оплачен', |
|
128 | - 'exported' => 'Выгружено', |
|
129 | - 'warehouse_block' => 'Блокировка товаров', |
|
130 | - 'extra' => 'Доп.', |
|
131 | - 'card_item_id' => 'Дисконтная карта', |
|
132 | - 'info' => 'Информация', |
|
133 | - 'contacts' => 'Информация', |
|
134 | - 'pay' => 'Счета', |
|
135 | - 'sums' => 'Суммы', |
|
136 | - 'deliveryInfo' => 'Для доставки', |
|
137 | - 'discount' => 'Скидки', |
|
138 | - ]; |
|
139 | - public static $cols = [ |
|
140 | - //Основные параметры |
|
141 | - 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
142 | - 'cart_status_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'status'], |
|
143 | - 'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'], |
|
144 | - 'paytype_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'payType'], |
|
145 | - 'card_item_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'card'], |
|
146 | - 'warehouse_block' => ['type' => 'bool'], |
|
147 | - 'payed' => ['type' => 'bool'], |
|
148 | - 'comment' => ['type' => 'textarea'], |
|
149 | - //Системные |
|
150 | - 'exported' => ['type' => 'bool'], |
|
151 | - 'complete_data' => ['type' => 'dateTime'], |
|
152 | - 'date_status' => ['type' => 'dateTime'], |
|
153 | - 'date_last_activ' => ['type' => 'dateTime'], |
|
154 | - 'date_create' => ['type' => 'dateTime'], |
|
155 | - //Виджеты |
|
156 | - 'sums' => [ |
|
157 | - 'type' => 'void', |
|
158 | - 'view' => [ |
|
159 | - 'type' => 'widget', |
|
160 | - 'widget' => 'Ecommerce\adminSums', |
|
161 | - ], |
|
162 | - ], |
|
163 | - 'contacts' => [ |
|
164 | - 'type' => 'void', |
|
165 | - 'view' => [ |
|
166 | - 'type' => 'widget', |
|
167 | - 'widget' => 'Ecommerce\admin/contacts', |
|
168 | - ], |
|
169 | - ], |
|
170 | - //Менеджеры |
|
171 | - 'extra' => ['type' => 'dataManager', 'relation' => 'extras'], |
|
172 | - 'pay' => ['type' => 'dataManager', 'relation' => 'pays'], |
|
173 | - 'items' => ['type' => 'dataManager', 'relation' => 'cartItems'], |
|
174 | - 'info' => ['type' => 'dataManager', 'relation' => 'infos'], |
|
175 | - 'deliveryInfo' => ['type' => 'dataManager', 'relation' => 'deliveryInfos'], |
|
176 | - 'discount' => ['type' => 'dataManager', 'relation' => 'discounts'], |
|
177 | - ]; |
|
178 | - public static $dataManagers = [ |
|
179 | - 'manager' => [ |
|
180 | - 'cols' => [ |
|
181 | - 'contacts', |
|
182 | - 'items', |
|
183 | - 'extra', |
|
184 | - 'discount', |
|
185 | - 'sums', |
|
186 | - 'cart_status_id', |
|
187 | - 'delivery_id', |
|
188 | - 'deliveryInfo', |
|
189 | - 'payed', |
|
190 | - 'pay', |
|
191 | - 'complete_data', |
|
192 | - ], |
|
193 | - 'sortable' => [ |
|
194 | - 'cart_status_id', |
|
195 | - 'delivery_id', |
|
196 | - 'payed', |
|
197 | - 'complete_data', |
|
198 | - ], |
|
199 | - 'filters' => [ |
|
200 | - 'cart_status_id', |
|
201 | - 'delivery_id', |
|
202 | - 'payed', |
|
203 | - 'complete_data', |
|
204 | - ], |
|
205 | - 'preSort' => [ |
|
206 | - 'complete_data' => 'desc' |
|
207 | - ], |
|
208 | - 'actions' => [ |
|
209 | - 'Ecommerce\CloseCartBtn', 'Open', 'Edit', 'Delete' |
|
210 | - ] |
|
211 | - ] |
|
212 | - ]; |
|
117 | + public static $labels = [ |
|
118 | + 'user_id' => 'Пользователь', |
|
119 | + 'cart_status_id' => 'Статус', |
|
120 | + 'delivery_id' => 'Доставка', |
|
121 | + 'comment' => 'Комментарий', |
|
122 | + 'bonus_used' => 'Выгодные рубли', |
|
123 | + 'complete_data' => 'Время заказа', |
|
124 | + 'info' => 'Информация', |
|
125 | + 'items' => 'Товары', |
|
126 | + 'paytype_id' => 'Способ оплаты', |
|
127 | + 'payed' => 'Оплачен', |
|
128 | + 'exported' => 'Выгружено', |
|
129 | + 'warehouse_block' => 'Блокировка товаров', |
|
130 | + 'extra' => 'Доп.', |
|
131 | + 'card_item_id' => 'Дисконтная карта', |
|
132 | + 'info' => 'Информация', |
|
133 | + 'contacts' => 'Информация', |
|
134 | + 'pay' => 'Счета', |
|
135 | + 'sums' => 'Суммы', |
|
136 | + 'deliveryInfo' => 'Для доставки', |
|
137 | + 'discount' => 'Скидки', |
|
138 | + ]; |
|
139 | + public static $cols = [ |
|
140 | + //Основные параметры |
|
141 | + 'user_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'user'], |
|
142 | + 'cart_status_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'status'], |
|
143 | + 'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'], |
|
144 | + 'paytype_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'payType'], |
|
145 | + 'card_item_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'card'], |
|
146 | + 'warehouse_block' => ['type' => 'bool'], |
|
147 | + 'payed' => ['type' => 'bool'], |
|
148 | + 'comment' => ['type' => 'textarea'], |
|
149 | + //Системные |
|
150 | + 'exported' => ['type' => 'bool'], |
|
151 | + 'complete_data' => ['type' => 'dateTime'], |
|
152 | + 'date_status' => ['type' => 'dateTime'], |
|
153 | + 'date_last_activ' => ['type' => 'dateTime'], |
|
154 | + 'date_create' => ['type' => 'dateTime'], |
|
155 | + //Виджеты |
|
156 | + 'sums' => [ |
|
157 | + 'type' => 'void', |
|
158 | + 'view' => [ |
|
159 | + 'type' => 'widget', |
|
160 | + 'widget' => 'Ecommerce\adminSums', |
|
161 | + ], |
|
162 | + ], |
|
163 | + 'contacts' => [ |
|
164 | + 'type' => 'void', |
|
165 | + 'view' => [ |
|
166 | + 'type' => 'widget', |
|
167 | + 'widget' => 'Ecommerce\admin/contacts', |
|
168 | + ], |
|
169 | + ], |
|
170 | + //Менеджеры |
|
171 | + 'extra' => ['type' => 'dataManager', 'relation' => 'extras'], |
|
172 | + 'pay' => ['type' => 'dataManager', 'relation' => 'pays'], |
|
173 | + 'items' => ['type' => 'dataManager', 'relation' => 'cartItems'], |
|
174 | + 'info' => ['type' => 'dataManager', 'relation' => 'infos'], |
|
175 | + 'deliveryInfo' => ['type' => 'dataManager', 'relation' => 'deliveryInfos'], |
|
176 | + 'discount' => ['type' => 'dataManager', 'relation' => 'discounts'], |
|
177 | + ]; |
|
178 | + public static $dataManagers = [ |
|
179 | + 'manager' => [ |
|
180 | + 'cols' => [ |
|
181 | + 'contacts', |
|
182 | + 'items', |
|
183 | + 'extra', |
|
184 | + 'discount', |
|
185 | + 'sums', |
|
186 | + 'cart_status_id', |
|
187 | + 'delivery_id', |
|
188 | + 'deliveryInfo', |
|
189 | + 'payed', |
|
190 | + 'pay', |
|
191 | + 'complete_data', |
|
192 | + ], |
|
193 | + 'sortable' => [ |
|
194 | + 'cart_status_id', |
|
195 | + 'delivery_id', |
|
196 | + 'payed', |
|
197 | + 'complete_data', |
|
198 | + ], |
|
199 | + 'filters' => [ |
|
200 | + 'cart_status_id', |
|
201 | + 'delivery_id', |
|
202 | + 'payed', |
|
203 | + 'complete_data', |
|
204 | + ], |
|
205 | + 'preSort' => [ |
|
206 | + 'complete_data' => 'desc' |
|
207 | + ], |
|
208 | + 'actions' => [ |
|
209 | + 'Ecommerce\CloseCartBtn', 'Open', 'Edit', 'Delete' |
|
210 | + ] |
|
211 | + ] |
|
212 | + ]; |
|
213 | 213 | |
214 | - public static function itemName($item) { |
|
214 | + public static function itemName($item) { |
|
215 | 215 | return $item->pk() . '. ' . $item->name(); |
216 | - } |
|
216 | + } |
|
217 | 217 | |
218 | - public static $forms = [ |
|
219 | - 'manager' => [ |
|
220 | - 'inputs' => [ |
|
221 | - 'userSearch' => [ |
|
222 | - 'type' => 'search', |
|
223 | - 'source' => 'relation', |
|
224 | - 'relation' => 'user', |
|
225 | - 'label' => 'Покупатель', |
|
226 | - 'cols' => [ |
|
227 | - 'info:first_name', |
|
228 | - 'info:last_name', |
|
229 | - 'info:middle_name', |
|
230 | - 'mail' |
|
231 | - ], |
|
232 | - 'col' => 'user_id', |
|
233 | - 'required' => true, |
|
234 | - 'showCol' => [ |
|
235 | - 'type' => 'staticMethod', |
|
236 | - 'class' => 'Ecommerce\Cart', |
|
237 | - 'method' => 'itemName', |
|
238 | - ], |
|
239 | - ], |
|
240 | - 'cardSearch' => [ |
|
241 | - 'type' => 'search', |
|
242 | - 'source' => 'relation', |
|
243 | - 'relation' => 'card', |
|
244 | - 'label' => 'Дисконтная карта', |
|
245 | - 'cols' => [ |
|
246 | - 'code', |
|
247 | - 'user:info:first_name', |
|
248 | - 'user:info:last_name', |
|
249 | - 'user:info:middle_name', |
|
250 | - 'user:mail' |
|
251 | - ], |
|
252 | - 'col' => 'card_item_id', |
|
253 | - ], |
|
254 | - ], |
|
255 | - 'map' => [ |
|
256 | - ['userSearch', 'cart_status_id'], |
|
257 | - ['paytype_id', 'delivery_id'], |
|
258 | - ['cardSearch', 'comment'], |
|
259 | - ['warehouse_block', 'complete_data'], |
|
260 | - ['payed'], |
|
261 | - ['items'], |
|
262 | - ['extra'], |
|
263 | - ['pay'], |
|
264 | - ['info'], |
|
265 | - ['deliveryInfo'] |
|
266 | - ] |
|
267 | - ], |
|
268 | - ]; |
|
218 | + public static $forms = [ |
|
219 | + 'manager' => [ |
|
220 | + 'inputs' => [ |
|
221 | + 'userSearch' => [ |
|
222 | + 'type' => 'search', |
|
223 | + 'source' => 'relation', |
|
224 | + 'relation' => 'user', |
|
225 | + 'label' => 'Покупатель', |
|
226 | + 'cols' => [ |
|
227 | + 'info:first_name', |
|
228 | + 'info:last_name', |
|
229 | + 'info:middle_name', |
|
230 | + 'mail' |
|
231 | + ], |
|
232 | + 'col' => 'user_id', |
|
233 | + 'required' => true, |
|
234 | + 'showCol' => [ |
|
235 | + 'type' => 'staticMethod', |
|
236 | + 'class' => 'Ecommerce\Cart', |
|
237 | + 'method' => 'itemName', |
|
238 | + ], |
|
239 | + ], |
|
240 | + 'cardSearch' => [ |
|
241 | + 'type' => 'search', |
|
242 | + 'source' => 'relation', |
|
243 | + 'relation' => 'card', |
|
244 | + 'label' => 'Дисконтная карта', |
|
245 | + 'cols' => [ |
|
246 | + 'code', |
|
247 | + 'user:info:first_name', |
|
248 | + 'user:info:last_name', |
|
249 | + 'user:info:middle_name', |
|
250 | + 'user:mail' |
|
251 | + ], |
|
252 | + 'col' => 'card_item_id', |
|
253 | + ], |
|
254 | + ], |
|
255 | + 'map' => [ |
|
256 | + ['userSearch', 'cart_status_id'], |
|
257 | + ['paytype_id', 'delivery_id'], |
|
258 | + ['cardSearch', 'comment'], |
|
259 | + ['warehouse_block', 'complete_data'], |
|
260 | + ['payed'], |
|
261 | + ['items'], |
|
262 | + ['extra'], |
|
263 | + ['pay'], |
|
264 | + ['info'], |
|
265 | + ['deliveryInfo'] |
|
266 | + ] |
|
267 | + ], |
|
268 | + ]; |
|
269 | 269 | |
270 | - public function checkStage() { |
|
270 | + public function checkStage() { |
|
271 | 271 | $sum = $this->itemsSum(); |
272 | 272 | $stages = Cart\Stage::getList(['order' => ['sum', 'asc']]); |
273 | 273 | $groups = []; |
274 | 274 | foreach ($stages as $stage) { |
275 | - if ($sum->greater(new \Money\Sums([$stage->currency_id => $stage->sum])) || $sum->equal(new \Money\Sums([$stage->currency_id => $stage->sum]))) { |
|
275 | + if ($sum->greater(new \Money\Sums([$stage->currency_id => $stage->sum])) || $sum->equal(new \Money\Sums([$stage->currency_id => $stage->sum]))) { |
|
276 | 276 | $groups[$stage->group] = $stage; |
277 | - } |
|
277 | + } |
|
278 | 278 | } |
279 | 279 | $discounts = Cart\Discount::getList(['where' => ['cart_id', $this->id]]); |
280 | 280 | foreach ($discounts as $discount) { |
281 | - if (!isset($groups[$discount->group]) && $discount->auto) { |
|
281 | + if (!isset($groups[$discount->group]) && $discount->auto) { |
|
282 | 282 | $discount->delete(); |
283 | - } |
|
284 | - if (isset($groups[$discount->group]) && $groups[$discount->group]->type == 'discount') { |
|
283 | + } |
|
284 | + if (isset($groups[$discount->group]) && $groups[$discount->group]->type == 'discount') { |
|
285 | 285 | $discount->discount_id = $groups[$discount->group]->value; |
286 | 286 | $discount->save(); |
287 | 287 | unset($groups[$discount->group]); |
288 | - } |
|
288 | + } |
|
289 | 289 | } |
290 | 290 | foreach ($groups as $group) { |
291 | - if ($group && $group->type == 'discount') { |
|
291 | + if ($group && $group->type == 'discount') { |
|
292 | 292 | $rel = $this->addRelation('discounts', $group->value); |
293 | 293 | $rel->auto = true; |
294 | 294 | $rel->group = 'discount'; |
295 | 295 | $rel->save(); |
296 | - } |
|
296 | + } |
|
297 | + } |
|
297 | 298 | } |
298 | - } |
|
299 | 299 | |
300 | - public function needDelivery() { |
|
300 | + public function needDelivery() { |
|
301 | 301 | foreach ($this->cartItems as $cartItem) { |
302 | - if ($cartItem->item->type && $cartItem->item->type->delivery) { |
|
302 | + if ($cartItem->item->type && $cartItem->item->type->delivery) { |
|
303 | 303 | return true; |
304 | - } |
|
304 | + } |
|
305 | 305 | } |
306 | 306 | return false; |
307 | - } |
|
307 | + } |
|
308 | 308 | |
309 | - public function deliverySum() { |
|
309 | + public function deliverySum() { |
|
310 | 310 | $sum = new \Money\Sums([]); |
311 | 311 | if ($this->delivery && $this->needDelivery()) { |
312 | - $sums = $this->itemsSum(); |
|
313 | - $deliveryPrice = new \Money\Sums([$this->delivery->currency_id => $this->delivery->max_cart_price]); |
|
314 | - if ($this->delivery->max_cart_price && $sums->greater($deliveryPrice) || $sums->equal($deliveryPrice)) { |
|
312 | + $sums = $this->itemsSum(); |
|
313 | + $deliveryPrice = new \Money\Sums([$this->delivery->currency_id => $this->delivery->max_cart_price]); |
|
314 | + if ($this->delivery->max_cart_price && $sums->greater($deliveryPrice) || $sums->equal($deliveryPrice)) { |
|
315 | 315 | $sum->sums = [$this->delivery->currency_id => 0]; |
316 | - } else if ($this->delivery->prices) { |
|
316 | + } else if ($this->delivery->prices) { |
|
317 | 317 | foreach ($this->delivery->prices(['order' => ['cart_price', 'asc']]) as $delPrice) { |
318 | - $deliveryPrice = new \Money\Sums([$delPrice->currency_id => $delPrice->cart_price]); |
|
319 | - if ($sums->greater($deliveryPrice) || $sums->equal($deliveryPrice)) { |
|
318 | + $deliveryPrice = new \Money\Sums([$delPrice->currency_id => $delPrice->cart_price]); |
|
319 | + if ($sums->greater($deliveryPrice) || $sums->equal($deliveryPrice)) { |
|
320 | 320 | $sum->sums = [$delPrice->currency_id => $delPrice->price]; |
321 | - } |
|
321 | + } |
|
322 | 322 | } |
323 | 323 | if (!$sum->sums) { |
324 | - $sum->sums = [$this->delivery->currency_id => $this->delivery->price]; |
|
324 | + $sum->sums = [$this->delivery->currency_id => $this->delivery->price]; |
|
325 | 325 | } |
326 | - } else { |
|
326 | + } else { |
|
327 | 327 | $sum->sums = [$this->delivery->currency_id => $this->delivery->price]; |
328 | - } |
|
328 | + } |
|
329 | 329 | } |
330 | 330 | return $sum; |
331 | - } |
|
331 | + } |
|
332 | 332 | |
333 | - public function hasDiscount() { |
|
333 | + public function hasDiscount() { |
|
334 | 334 | return (bool) $this->card || $this->discounts; |
335 | - } |
|
335 | + } |
|
336 | 336 | |
337 | - public function discountSum() { |
|
337 | + public function discountSum() { |
|
338 | 338 | $sums = []; |
339 | 339 | foreach ($this->cartItems as $cartItem) { |
340 | - $sums[$cartItem->price->currency_id] = isset($sums[$cartItem->price->currency_id]) ? $sums[$cartItem->price->currency_id] + $cartItem->discount() * $cartItem->count : $cartItem->discount() * $cartItem->count; |
|
340 | + $sums[$cartItem->price->currency_id] = isset($sums[$cartItem->price->currency_id]) ? $sums[$cartItem->price->currency_id] + $cartItem->discount() * $cartItem->count : $cartItem->discount() * $cartItem->count; |
|
341 | 341 | } |
342 | 342 | return new \Money\Sums($sums); |
343 | - } |
|
343 | + } |
|
344 | 344 | |
345 | - public function finalSum() { |
|
345 | + public function finalSum() { |
|
346 | 346 | $sums = $this->itemsSum(); |
347 | 347 | $sums = $sums->minus($this->discountSum()); |
348 | 348 | $sums = $sums->plus($this->deliverySum()); |
349 | 349 | return $sums; |
350 | - } |
|
350 | + } |
|
351 | 351 | |
352 | - public function itemsSum() { |
|
352 | + public function itemsSum() { |
|
353 | 353 | $cart = Cart::get($this->id); |
354 | 354 | $sums = []; |
355 | 355 | foreach ($cart->cartItems as $cartItem) { |
356 | - if (!$cartItem->price) { |
|
356 | + if (!$cartItem->price) { |
|
357 | 357 | continue; |
358 | - } |
|
359 | - $sums[$cartItem->price->currency_id] = isset($sums[$cartItem->price->currency_id]) ? $sums[$cartItem->price->currency_id] + $cartItem->price->price * $cartItem->count : $cartItem->price->price * $cartItem->count; |
|
358 | + } |
|
359 | + $sums[$cartItem->price->currency_id] = isset($sums[$cartItem->price->currency_id]) ? $sums[$cartItem->price->currency_id] + $cartItem->price->price * $cartItem->count : $cartItem->price->price * $cartItem->count; |
|
360 | 360 | } |
361 | 361 | return new \Money\Sums($sums); |
362 | - } |
|
362 | + } |
|
363 | 363 | |
364 | - public function addItem($offer_price_id, $count = 1, $final_price = 0) { |
|
364 | + public function addItem($offer_price_id, $count = 1, $final_price = 0) { |
|
365 | 365 | $price = Item\Offer\Price::get((int) $offer_price_id); |
366 | 366 | |
367 | 367 | if (!$price) { |
368 | - return false; |
|
368 | + return false; |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | if ($count <= 0) { |
372 | - $count = 1; |
|
372 | + $count = 1; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | $cartItem = new Cart\Item(); |
@@ -380,12 +380,12 @@ discard block |
||
380 | 380 | $cartItem->final_price = $final_price ? $final_price : $price->price; |
381 | 381 | $cartItem->save(); |
382 | 382 | return true; |
383 | - } |
|
383 | + } |
|
384 | 384 | |
385 | - public function calc($save = true) { |
|
385 | + public function calc($save = true) { |
|
386 | 386 | if ($save) { |
387 | - $this->save(); |
|
387 | + $this->save(); |
|
388 | + } |
|
388 | 389 | } |
389 | - } |
|
390 | 390 | |
391 | 391 | } |
@@ -212,7 +212,7 @@ |
||
212 | 212 | ]; |
213 | 213 | |
214 | 214 | public static function itemName($item) { |
215 | - return $item->pk() . '. ' . $item->name(); |
|
215 | + return $item->pk().'. '.$item->name(); |
|
216 | 216 | } |
217 | 217 | |
218 | 218 | public static $forms = [ |
@@ -13,62 +13,62 @@ discard block |
||
13 | 13 | |
14 | 14 | class Delivery extends \Model { |
15 | 15 | |
16 | - public static $objectName = 'Доставка'; |
|
17 | - public static $cols = [ |
|
18 | - //Основные параметры |
|
19 | - 'name' => ['type' => 'text'], |
|
20 | - 'price' => ['type' => 'decimal'], |
|
21 | - 'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'], |
|
22 | - 'price_text' => ['type' => 'textarea'], |
|
23 | - 'max_cart_price' => ['type' => 'decimal'], |
|
24 | - 'icon_file_id' => ['type' => 'image'], |
|
25 | - 'info' => ['type' => 'html'], |
|
26 | - //Системные |
|
27 | - 'weight' => ['type' => 'number'], |
|
28 | - 'date_create' => ['type' => 'dateTime'], |
|
29 | - //Менеджеры |
|
30 | - 'field' => ['type' => 'dataManager', 'relation' => 'fields'], |
|
31 | - 'priceChanger' => ['type' => 'dataManager', 'relation' => 'prices'] |
|
32 | - ]; |
|
33 | - public static $labels = [ |
|
34 | - 'name' => 'Название', |
|
35 | - 'price' => 'Стоимость', |
|
36 | - 'price_text' => 'Текстовое описание стоимости (отображается вместо цены)', |
|
37 | - 'max_cart_price' => 'Басплатно при', |
|
38 | - 'icon_file_id' => 'Иконка', |
|
39 | - 'currency_id' => 'Валюта', |
|
40 | - 'info' => 'Дополнительная информация', |
|
41 | - 'priceChanger' => 'Градация стоимости', |
|
42 | - 'field' => 'Поля', |
|
43 | - ]; |
|
44 | - public static $dataManagers = [ |
|
45 | - 'manager' => [ |
|
46 | - 'name' => 'Варианты доставки', |
|
47 | - 'cols' => [ |
|
48 | - 'name', |
|
49 | - 'price', |
|
50 | - 'currency_id', |
|
51 | - 'max_cart_price', |
|
52 | - 'field', |
|
53 | - 'priceChanger' |
|
54 | - ], |
|
55 | - 'sortMode' => true |
|
56 | - ], |
|
57 | - ]; |
|
58 | - public static $forms = [ |
|
59 | - 'manager' => [ |
|
60 | - 'map' => [ |
|
61 | - ['name',], |
|
62 | - ['max_cart_price', 'icon_file_id'], |
|
63 | - ['price', 'currency_id'], |
|
64 | - ['price_text'], |
|
65 | - ['info'], |
|
66 | - ['priceChanger'], |
|
67 | - ['field'] |
|
68 | - ] |
|
69 | - ]]; |
|
16 | + public static $objectName = 'Доставка'; |
|
17 | + public static $cols = [ |
|
18 | + //Основные параметры |
|
19 | + 'name' => ['type' => 'text'], |
|
20 | + 'price' => ['type' => 'decimal'], |
|
21 | + 'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'], |
|
22 | + 'price_text' => ['type' => 'textarea'], |
|
23 | + 'max_cart_price' => ['type' => 'decimal'], |
|
24 | + 'icon_file_id' => ['type' => 'image'], |
|
25 | + 'info' => ['type' => 'html'], |
|
26 | + //Системные |
|
27 | + 'weight' => ['type' => 'number'], |
|
28 | + 'date_create' => ['type' => 'dateTime'], |
|
29 | + //Менеджеры |
|
30 | + 'field' => ['type' => 'dataManager', 'relation' => 'fields'], |
|
31 | + 'priceChanger' => ['type' => 'dataManager', 'relation' => 'prices'] |
|
32 | + ]; |
|
33 | + public static $labels = [ |
|
34 | + 'name' => 'Название', |
|
35 | + 'price' => 'Стоимость', |
|
36 | + 'price_text' => 'Текстовое описание стоимости (отображается вместо цены)', |
|
37 | + 'max_cart_price' => 'Басплатно при', |
|
38 | + 'icon_file_id' => 'Иконка', |
|
39 | + 'currency_id' => 'Валюта', |
|
40 | + 'info' => 'Дополнительная информация', |
|
41 | + 'priceChanger' => 'Градация стоимости', |
|
42 | + 'field' => 'Поля', |
|
43 | + ]; |
|
44 | + public static $dataManagers = [ |
|
45 | + 'manager' => [ |
|
46 | + 'name' => 'Варианты доставки', |
|
47 | + 'cols' => [ |
|
48 | + 'name', |
|
49 | + 'price', |
|
50 | + 'currency_id', |
|
51 | + 'max_cart_price', |
|
52 | + 'field', |
|
53 | + 'priceChanger' |
|
54 | + ], |
|
55 | + 'sortMode' => true |
|
56 | + ], |
|
57 | + ]; |
|
58 | + public static $forms = [ |
|
59 | + 'manager' => [ |
|
60 | + 'map' => [ |
|
61 | + ['name',], |
|
62 | + ['max_cart_price', 'icon_file_id'], |
|
63 | + ['price', 'currency_id'], |
|
64 | + ['price_text'], |
|
65 | + ['info'], |
|
66 | + ['priceChanger'], |
|
67 | + ['field'] |
|
68 | + ] |
|
69 | + ]]; |
|
70 | 70 | |
71 | - public static function relations() { |
|
71 | + public static function relations() { |
|
72 | 72 | return [ |
73 | 73 | 'icon' => [ |
74 | 74 | 'model' => 'Files\File', |
@@ -89,6 +89,6 @@ discard block |
||
89 | 89 | 'col' => 'delivery_id' |
90 | 90 | ] |
91 | 91 | ]; |
92 | - } |
|
92 | + } |
|
93 | 93 | |
94 | 94 | } |
@@ -58,7 +58,7 @@ |
||
58 | 58 | public static $forms = [ |
59 | 59 | 'manager' => [ |
60 | 60 | 'map' => [ |
61 | - ['name',], |
|
61 | + ['name', ], |
|
62 | 62 | ['max_cart_price', 'icon_file_id'], |
63 | 63 | ['price', 'currency_id'], |
64 | 64 | ['price_text'], |
@@ -13,44 +13,44 @@ discard block |
||
13 | 13 | |
14 | 14 | class Field extends \Model { |
15 | 15 | |
16 | - public static $objectName = 'Поле доставки'; |
|
17 | - public static $cols = [ |
|
18 | - //Основные параметры |
|
19 | - 'name' => ['type' => 'text'], |
|
20 | - 'type' => ['type' => 'text'], |
|
21 | - 'userfield' => ['type' => 'text'], |
|
22 | - 'required' => ['type' => 'bool'], |
|
23 | - 'save' => ['type' => 'bool'], |
|
24 | - 'fieldItem'=>['type'=>'dataManager','relation'=>'fieldItems'], |
|
25 | - //Системные |
|
26 | - 'date_create' => ['type' => 'dateTime'], |
|
27 | - ]; |
|
28 | - public static $labels = [ |
|
29 | - 'name' => 'Название', |
|
30 | - 'type' => 'Тип', |
|
31 | - 'userfield' => 'Связь с данными пользователя', |
|
32 | - 'required' => 'Обязательно', |
|
33 | - 'save' => 'Сохраняется', |
|
34 | - 'fieldItem' => 'Значения для списка', |
|
35 | - ]; |
|
36 | - public static $dataManagers = [ |
|
37 | - 'manager' => [ |
|
38 | - 'cols' => [ |
|
39 | - 'name', 'type', 'userfield', 'required','fieldItem', 'save' |
|
40 | - ], |
|
41 | - ] |
|
42 | - ]; |
|
43 | - public static $forms = [ |
|
44 | - 'manager' => [ |
|
45 | - 'map' => [ |
|
46 | - ['name', 'type'], |
|
47 | - ['required', 'save'], |
|
48 | - [ 'userfield'] |
|
49 | - ] |
|
50 | - ] |
|
51 | - ]; |
|
16 | + public static $objectName = 'Поле доставки'; |
|
17 | + public static $cols = [ |
|
18 | + //Основные параметры |
|
19 | + 'name' => ['type' => 'text'], |
|
20 | + 'type' => ['type' => 'text'], |
|
21 | + 'userfield' => ['type' => 'text'], |
|
22 | + 'required' => ['type' => 'bool'], |
|
23 | + 'save' => ['type' => 'bool'], |
|
24 | + 'fieldItem'=>['type'=>'dataManager','relation'=>'fieldItems'], |
|
25 | + //Системные |
|
26 | + 'date_create' => ['type' => 'dateTime'], |
|
27 | + ]; |
|
28 | + public static $labels = [ |
|
29 | + 'name' => 'Название', |
|
30 | + 'type' => 'Тип', |
|
31 | + 'userfield' => 'Связь с данными пользователя', |
|
32 | + 'required' => 'Обязательно', |
|
33 | + 'save' => 'Сохраняется', |
|
34 | + 'fieldItem' => 'Значения для списка', |
|
35 | + ]; |
|
36 | + public static $dataManagers = [ |
|
37 | + 'manager' => [ |
|
38 | + 'cols' => [ |
|
39 | + 'name', 'type', 'userfield', 'required','fieldItem', 'save' |
|
40 | + ], |
|
41 | + ] |
|
42 | + ]; |
|
43 | + public static $forms = [ |
|
44 | + 'manager' => [ |
|
45 | + 'map' => [ |
|
46 | + ['name', 'type'], |
|
47 | + ['required', 'save'], |
|
48 | + [ 'userfield'] |
|
49 | + ] |
|
50 | + ] |
|
51 | + ]; |
|
52 | 52 | |
53 | - public static function relations() { |
|
53 | + public static function relations() { |
|
54 | 54 | return [ |
55 | 55 | 'fieldItems' => [ |
56 | 56 | 'model' => 'Ecommerce\Delivery\Field\Item', |
@@ -58,6 +58,6 @@ discard block |
||
58 | 58 | 'type' => 'many' |
59 | 59 | ], |
60 | 60 | ]; |
61 | - } |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | 'userfield' => ['type' => 'text'], |
22 | 22 | 'required' => ['type' => 'bool'], |
23 | 23 | 'save' => ['type' => 'bool'], |
24 | - 'fieldItem'=>['type'=>'dataManager','relation'=>'fieldItems'], |
|
24 | + 'fieldItem'=>['type'=>'dataManager', 'relation'=>'fieldItems'], |
|
25 | 25 | //Системные |
26 | 26 | 'date_create' => ['type' => 'dateTime'], |
27 | 27 | ]; |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | public static $dataManagers = [ |
37 | 37 | 'manager' => [ |
38 | 38 | 'cols' => [ |
39 | - 'name', 'type', 'userfield', 'required','fieldItem', 'save' |
|
39 | + 'name', 'type', 'userfield', 'required', 'fieldItem', 'save' |
|
40 | 40 | ], |
41 | 41 | ] |
42 | 42 | ]; |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | 'map' => [ |
46 | 46 | ['name', 'type'], |
47 | 47 | ['required', 'save'], |
48 | - [ 'userfield'] |
|
48 | + ['userfield'] |
|
49 | 49 | ] |
50 | 50 | ] |
51 | 51 | ]; |
@@ -13,31 +13,31 @@ discard block |
||
13 | 13 | |
14 | 14 | class DeliveryFieldLink extends \Model { |
15 | 15 | |
16 | - public static $labels = [ |
|
17 | - 'delivery_id' => 'Тип доставки', |
|
18 | - 'delivery_field_id' => 'Поле доставки' |
|
19 | - ]; |
|
20 | - public static $cols = [ |
|
21 | - 'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'], |
|
22 | - 'delivery_field_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'field'], |
|
23 | - 'weight' => ['type' => 'number'], |
|
24 | - 'date_create' => ['type' => 'dateTime'] |
|
25 | - ]; |
|
26 | - public static $dataManagers = [ |
|
27 | - 'manager' => [ |
|
28 | - 'name' => 'Поля для доставки', |
|
29 | - 'cols' => ['delivery_id', 'delivery_field_id', 'date_create'], |
|
30 | - ] |
|
31 | - ]; |
|
32 | - public static $forms = [ |
|
33 | - 'manager' => [ |
|
34 | - 'map' => [ |
|
35 | - ['delivery_id', 'delivery_field_id'], |
|
36 | - ] |
|
37 | - ] |
|
38 | - ]; |
|
16 | + public static $labels = [ |
|
17 | + 'delivery_id' => 'Тип доставки', |
|
18 | + 'delivery_field_id' => 'Поле доставки' |
|
19 | + ]; |
|
20 | + public static $cols = [ |
|
21 | + 'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'], |
|
22 | + 'delivery_field_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'field'], |
|
23 | + 'weight' => ['type' => 'number'], |
|
24 | + 'date_create' => ['type' => 'dateTime'] |
|
25 | + ]; |
|
26 | + public static $dataManagers = [ |
|
27 | + 'manager' => [ |
|
28 | + 'name' => 'Поля для доставки', |
|
29 | + 'cols' => ['delivery_id', 'delivery_field_id', 'date_create'], |
|
30 | + ] |
|
31 | + ]; |
|
32 | + public static $forms = [ |
|
33 | + 'manager' => [ |
|
34 | + 'map' => [ |
|
35 | + ['delivery_id', 'delivery_field_id'], |
|
36 | + ] |
|
37 | + ] |
|
38 | + ]; |
|
39 | 39 | |
40 | - public static function relations() { |
|
40 | + public static function relations() { |
|
41 | 41 | return [ |
42 | 42 | 'field' => [ |
43 | 43 | 'model' => 'Ecommerce\Delivery\Field', |
@@ -48,6 +48,6 @@ discard block |
||
48 | 48 | 'col' => 'delivery_id' |
49 | 49 | ], |
50 | 50 | ]; |
51 | - } |
|
51 | + } |
|
52 | 52 | |
53 | 53 | } |
@@ -13,35 +13,35 @@ discard block |
||
13 | 13 | |
14 | 14 | class Price extends \Model { |
15 | 15 | |
16 | - public static $labels = [ |
|
17 | - 'delivery_id' => 'Тип доставки', |
|
18 | - 'cart_price' => 'Сумма корзины', |
|
19 | - 'price' => 'Стоимость доставки', |
|
20 | - 'currency_id' => 'Валюта', |
|
21 | - ]; |
|
22 | - public static $cols = [ |
|
23 | - 'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'], |
|
24 | - 'cart_price' => ['type' => 'number'], |
|
25 | - 'price' => ['type' => 'number'], |
|
26 | - 'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'], |
|
27 | - 'date_create' => ['type' => 'dateTime'] |
|
28 | - ]; |
|
29 | - public static $dataManagers = [ |
|
30 | - 'manager' => [ |
|
31 | - 'name' => 'Цены для стоимости корзин', |
|
32 | - 'cols' => ['delivery_id', 'cart_price', 'price', 'currency_id'], |
|
33 | - ] |
|
34 | - ]; |
|
35 | - public static $forms = [ |
|
36 | - 'manager' => [ |
|
37 | - 'map' => [ |
|
38 | - ['delivery_id', 'currency_id'], |
|
39 | - ['cart_price', 'price'], |
|
40 | - ] |
|
41 | - ] |
|
42 | - ]; |
|
16 | + public static $labels = [ |
|
17 | + 'delivery_id' => 'Тип доставки', |
|
18 | + 'cart_price' => 'Сумма корзины', |
|
19 | + 'price' => 'Стоимость доставки', |
|
20 | + 'currency_id' => 'Валюта', |
|
21 | + ]; |
|
22 | + public static $cols = [ |
|
23 | + 'delivery_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'delivery'], |
|
24 | + 'cart_price' => ['type' => 'number'], |
|
25 | + 'price' => ['type' => 'number'], |
|
26 | + 'currency_id' => ['type' => 'select', 'source' => 'relation', 'relation' => 'currency'], |
|
27 | + 'date_create' => ['type' => 'dateTime'] |
|
28 | + ]; |
|
29 | + public static $dataManagers = [ |
|
30 | + 'manager' => [ |
|
31 | + 'name' => 'Цены для стоимости корзин', |
|
32 | + 'cols' => ['delivery_id', 'cart_price', 'price', 'currency_id'], |
|
33 | + ] |
|
34 | + ]; |
|
35 | + public static $forms = [ |
|
36 | + 'manager' => [ |
|
37 | + 'map' => [ |
|
38 | + ['delivery_id', 'currency_id'], |
|
39 | + ['cart_price', 'price'], |
|
40 | + ] |
|
41 | + ] |
|
42 | + ]; |
|
43 | 43 | |
44 | - public static function relations() { |
|
44 | + public static function relations() { |
|
45 | 45 | return [ |
46 | 46 | 'delivery' => [ |
47 | 47 | 'model' => 'Ecommerce\Delivery', |
@@ -52,6 +52,6 @@ discard block |
||
52 | 52 | 'col' => 'currency_id' |
53 | 53 | ], |
54 | 54 | ]; |
55 | - } |
|
55 | + } |
|
56 | 56 | |
57 | 57 | } |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | |
14 | 14 | class File extends \Exchange1c\Mode { |
15 | 15 | |
16 | - public function process() { |
|
16 | + public function process() { |
|
17 | 17 | $dir = $this->exchange->path; |
18 | 18 | \Tools::createDir($dir); |
19 | 19 | $file = new \Exchange1c\Exchange\File(); |
@@ -23,25 +23,25 @@ discard block |
||
23 | 23 | $file->save(); |
24 | 24 | |
25 | 25 | if (strpos($_GET['filename'], '/') !== false) { |
26 | - $subDir = substr($_GET['filename'], 0, strrpos($_GET['filename'], "/") + 1); |
|
27 | - \Tools::createDir($dir . '/' . $subDir); |
|
26 | + $subDir = substr($_GET['filename'], 0, strrpos($_GET['filename'], "/") + 1); |
|
27 | + \Tools::createDir($dir . '/' . $subDir); |
|
28 | 28 | } |
29 | 29 | $text = ''; |
30 | 30 | if (false === file_put_contents($dir . '/' . $_GET['filename'], file_get_contents("php://input"))) { |
31 | - $text = 'Fail on save file: ' . $_GET['filename']; |
|
32 | - $file->status = 'failure'; |
|
31 | + $text = 'Fail on save file: ' . $_GET['filename']; |
|
32 | + $file->status = 'failure'; |
|
33 | 33 | } else { |
34 | - $file->size = ceil(filesize($dir . '/' . $_GET['filename'])); |
|
35 | - $file->status = 'success'; |
|
34 | + $file->size = ceil(filesize($dir . '/' . $_GET['filename'])); |
|
35 | + $file->status = 'success'; |
|
36 | 36 | } |
37 | 37 | $file->save(); |
38 | 38 | if (strpos($_GET['filename'], '1cbitrix') !== false) { |
39 | - $data = new \SimpleXMLElement(file_get_contents($dir . '/' . $_GET['filename'])); |
|
40 | - $orders = new \Exchange1c\Parser\Orders($data); |
|
41 | - $orders->process(); |
|
39 | + $data = new \SimpleXMLElement(file_get_contents($dir . '/' . $_GET['filename'])); |
|
40 | + $orders = new \Exchange1c\Parser\Orders($data); |
|
41 | + $orders->process(); |
|
42 | 42 | } |
43 | 43 | \App::$cur->exchange1c->response($file->status, $text, false); |
44 | 44 | $this->end($file->status); |
45 | - } |
|
45 | + } |
|
46 | 46 | |
47 | 47 | } |
@@ -24,19 +24,19 @@ |
||
24 | 24 | |
25 | 25 | if (strpos($_GET['filename'], '/') !== false) { |
26 | 26 | $subDir = substr($_GET['filename'], 0, strrpos($_GET['filename'], "/") + 1); |
27 | - \Tools::createDir($dir . '/' . $subDir); |
|
27 | + \Tools::createDir($dir.'/'.$subDir); |
|
28 | 28 | } |
29 | 29 | $text = ''; |
30 | - if (false === file_put_contents($dir . '/' . $_GET['filename'], file_get_contents("php://input"))) { |
|
31 | - $text = 'Fail on save file: ' . $_GET['filename']; |
|
30 | + if (false === file_put_contents($dir.'/'.$_GET['filename'], file_get_contents("php://input"))) { |
|
31 | + $text = 'Fail on save file: '.$_GET['filename']; |
|
32 | 32 | $file->status = 'failure'; |
33 | 33 | } else { |
34 | - $file->size = ceil(filesize($dir . '/' . $_GET['filename'])); |
|
34 | + $file->size = ceil(filesize($dir.'/'.$_GET['filename'])); |
|
35 | 35 | $file->status = 'success'; |
36 | 36 | } |
37 | 37 | $file->save(); |
38 | 38 | if (strpos($_GET['filename'], '1cbitrix') !== false) { |
39 | - $data = new \SimpleXMLElement(file_get_contents($dir . '/' . $_GET['filename'])); |
|
39 | + $data = new \SimpleXMLElement(file_get_contents($dir.'/'.$_GET['filename'])); |
|
40 | 40 | $orders = new \Exchange1c\Parser\Orders($data); |
41 | 41 | $orders->process(); |
42 | 42 | } |
@@ -13,18 +13,18 @@ |
||
13 | 13 | |
14 | 14 | class File extends \Model { |
15 | 15 | |
16 | - public static $cols = [ |
|
17 | - 'name' => ['type' => 'text'], |
|
18 | - 'size' => ['type' => 'number'], |
|
19 | - 'status' => ['type' => 'text'], |
|
20 | - 'date_create' => ['type' => 'dateTime'], |
|
21 | - ]; |
|
22 | - public static $dataManagers = [ |
|
23 | - 'manager' => [ |
|
24 | - 'cols' => [ |
|
25 | - 'name', 'size', 'date_create' |
|
26 | - ], |
|
27 | - ] |
|
28 | - ]; |
|
16 | + public static $cols = [ |
|
17 | + 'name' => ['type' => 'text'], |
|
18 | + 'size' => ['type' => 'number'], |
|
19 | + 'status' => ['type' => 'text'], |
|
20 | + 'date_create' => ['type' => 'dateTime'], |
|
21 | + ]; |
|
22 | + public static $dataManagers = [ |
|
23 | + 'manager' => [ |
|
24 | + 'cols' => [ |
|
25 | + 'name', 'size', 'date_create' |
|
26 | + ], |
|
27 | + ] |
|
28 | + ]; |
|
29 | 29 | |
30 | 30 | } |
@@ -25,11 +25,11 @@ discard block |
||
25 | 25 | $dir = pathinfo($this->object->walker->migtarionLog->source, PATHINFO_DIRNAME); |
26 | 26 | $this->model->image_file_id = 0; |
27 | 27 | foreach ($value as $key => $imagePath) { |
28 | - if (!$imagePath || !file_exists($dir . '/' . $imagePath)) { |
|
28 | + if (!$imagePath || !file_exists($dir.'/'.$imagePath)) { |
|
29 | 29 | continue; |
30 | 30 | } |
31 | 31 | $notEq = true; |
32 | - $md5Cur = md5_file($dir . '/' . $imagePath); |
|
32 | + $md5Cur = md5_file($dir.'/'.$imagePath); |
|
33 | 33 | foreach ($this->model->images as $imageId => $image) { |
34 | 34 | $file = $image->file; |
35 | 35 | $md5File = ''; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | } |
48 | 48 | } |
49 | 49 | if ($notEq) { |
50 | - $file_id = \App::$primary->files->uploadFromUrl($dir . '/' . $imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']); |
|
50 | + $file_id = \App::$primary->files->uploadFromUrl($dir.'/'.$imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']); |
|
51 | 51 | $image = new \Ecommerce\Item\Image([ |
52 | 52 | 'item_id' => $this->model->pk(), |
53 | 53 | 'file_id' => $file_id |
@@ -13,65 +13,65 @@ |
||
13 | 13 | |
14 | 14 | class Images extends \Migrations\Parser { |
15 | 15 | |
16 | - public function parse() { |
|
16 | + public function parse() { |
|
17 | 17 | if (is_null($this->data)) { |
18 | - return; |
|
18 | + return; |
|
19 | 19 | } |
20 | 20 | $value = $this->data; |
21 | 21 | if (!is_array($value)) { |
22 | - $value = [$value]; |
|
22 | + $value = [$value]; |
|
23 | 23 | } |
24 | 24 | $ids = []; |
25 | 25 | $dir = pathinfo($this->object->walker->migtarionLog->source, PATHINFO_DIRNAME); |
26 | 26 | $this->model->image_file_id = 0; |
27 | 27 | foreach ($value as $key => $imagePath) { |
28 | - if (!$imagePath || !file_exists($dir . '/' . $imagePath)) { |
|
28 | + if (!$imagePath || !file_exists($dir . '/' . $imagePath)) { |
|
29 | 29 | continue; |
30 | - } |
|
31 | - $notEq = true; |
|
32 | - $md5Cur = md5_file($dir . '/' . $imagePath); |
|
33 | - foreach ($this->model->images as $imageId => $image) { |
|
30 | + } |
|
31 | + $notEq = true; |
|
32 | + $md5Cur = md5_file($dir . '/' . $imagePath); |
|
33 | + foreach ($this->model->images as $imageId => $image) { |
|
34 | 34 | if (!$image->file) { |
35 | - $image->delete(); |
|
36 | - continue; |
|
35 | + $image->delete(); |
|
36 | + continue; |
|
37 | 37 | } |
38 | 38 | $file = $image->file; |
39 | 39 | $md5File = ''; |
40 | 40 | if ($file->md5) { |
41 | - $md5File = $file->md5; |
|
41 | + $md5File = $file->md5; |
|
42 | 42 | } elseif (file_exists($file->getRealPath())) { |
43 | - $md5File = $file->md5 = md5_file($file->getRealPath()); |
|
44 | - $file->save(); |
|
43 | + $md5File = $file->md5 = md5_file($file->getRealPath()); |
|
44 | + $file->save(); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | if ($file && file_exists($file->getRealPath()) && $md5Cur == $md5File) { |
48 | - $notEq = false; |
|
49 | - $ids[] = $imageId; |
|
50 | - break; |
|
48 | + $notEq = false; |
|
49 | + $ids[] = $imageId; |
|
50 | + break; |
|
51 | + } |
|
51 | 52 | } |
52 | - } |
|
53 | - if ($notEq) { |
|
53 | + if ($notEq) { |
|
54 | 54 | $file_id = \App::$primary->files->uploadFromUrl($dir . '/' . $imagePath, ['accept_group' => 'image', 'upload_code' => 'MigrationUpload']); |
55 | 55 | if ($file_id) { |
56 | - $image = new \Ecommerce\Item\Image([ |
|
57 | - 'item_id' => $this->model->pk(), |
|
58 | - 'file_id' => $file_id |
|
59 | - ]); |
|
60 | - $image->save(); |
|
61 | - $ids[] = $image->id; |
|
56 | + $image = new \Ecommerce\Item\Image([ |
|
57 | + 'item_id' => $this->model->pk(), |
|
58 | + 'file_id' => $file_id |
|
59 | + ]); |
|
60 | + $image->save(); |
|
61 | + $ids[] = $image->id; |
|
62 | 62 | } |
63 | - } else { |
|
63 | + } else { |
|
64 | 64 | $image->weight = $key; |
65 | - } |
|
66 | - if ($image && !$this->model->image_file_id) { |
|
65 | + } |
|
66 | + if ($image && !$this->model->image_file_id) { |
|
67 | 67 | $this->model->image_file_id = $image->file_id; |
68 | - } |
|
68 | + } |
|
69 | 69 | } |
70 | 70 | foreach ($this->model->images as $imageId => $image) { |
71 | - if (!in_array($imageId, $ids)) { |
|
71 | + if (!in_array($imageId, $ids)) { |
|
72 | 72 | $image->delete(); |
73 | - } |
|
73 | + } |
|
74 | + } |
|
74 | 75 | } |
75 | - } |
|
76 | 76 | |
77 | 77 | } |