Commit 2f93741fda24aeb74b63057435a1666e14ad3d68

Authored by Alexey Boroda
2 parents 3d655028 ad2227a5

Merge remote-tracking branch 'origin/master'

controllers/OrderController.php
... ... @@ -7,6 +7,7 @@
7 7 use common\models\User;
8 8 use phpDocumentor\Reflection\Types\Null_;
9 9 use Yii;
  10 + use yii\data\ArrayDataProvider;
10 11 use yii\helpers\ArrayHelper;
11 12 use yii\helpers\Json;
12 13 use yii\helpers\VarDumper;
... ... @@ -150,10 +151,10 @@
150 151  
151 152 public function actionAdd()
152 153 {
153   - if (!empty(\Yii::$app->request->post())) {
  154 + if (!empty( \Yii::$app->request->post() )) {
154 155 $id = \Yii::$app->request->post('OrderProduct')[ 'id' ];
155 156 $order_id = \Yii::$app->request->post('OrderProduct')[ 'order_id' ];
156   - if (!empty(\Yii::$app->request->post('OrderProduct')[ 'count' ])) {
  157 + if (!empty( \Yii::$app->request->post('OrderProduct')[ 'count' ] )) {
157 158 $count = \Yii::$app->request->post('OrderProduct')[ 'count' ];
158 159 } else {
159 160 $count = 1;
... ... @@ -173,7 +174,7 @@
173 174 )
174 175 ->one();
175 176  
176   - if (!empty($model)) {
  177 + if (!empty( $model )) {
177 178 $model->count += $count;
178 179 } else {
179 180 $model = new OrderProduct();
... ... @@ -218,7 +219,7 @@
218 219 if ($orderProduct->load($post)) {
219 220 $orderProduct->save();
220 221 $output = '';
221   - if (isset($posted[ 'count' ])) {
  222 + if (isset( $posted[ 'count' ] )) {
222 223 $output = Yii::$app->formatter->asDecimal($orderProduct->count, 0);
223 224 }
224 225 $out = Json::encode(
... ... @@ -267,20 +268,23 @@
267 268 }
268 269 }
269 270  
270   - public function actionPrint()
  271 + public function actionPrint($order_id)
271 272 {
272   - $orderId = Yii::$app->request->get("order_id");
273   - if (!empty($orderId)) {
274   - $order = $this->findModel($orderId);
275   - return $this->renderPartial(
276   - '@frontend/views/cabinet/order_print',
277   - [
278   - 'order' => $order,
279   - ]
280   - );
281   - } else {
282   - throw new NotFoundHttpException('The requested page does not exist.');
283   - }
  273 + $order = $this->findModel($order_id);
  274 + $dataProvider = new ArrayDataProvider(
  275 + [
  276 + 'allModels' => $order->products,
  277 + 'pagination' => false,
  278 + 'sort' => false,
  279 + ]
  280 + );
  281 + return $this->renderPartial(
  282 + 'print',
  283 + [
  284 + 'order' => $order,
  285 + 'dataProvider' => $dataProvider,
  286 + ]
  287 + );
284 288  
285 289 }
286 290  
... ... @@ -303,7 +307,7 @@
303 307 $orderProduct->save();
304 308 $orderProduct->order->totalRecount();
305 309 $output = '';
306   - if (isset($posted[ 'count' ])) {
  310 + if (isset( $posted[ 'count' ] )) {
307 311 $output = Yii::$app->formatter->asDecimal($orderProduct->count, 0);
308 312 }
309 313 $out = Json::encode(
... ... @@ -338,13 +342,13 @@
338 342 ]
339 343 );
340 344  
341   - if (empty($model->manager_id)) {
  345 + if (empty( $model->manager_id )) {
342 346 $model->manager_id = \Yii::$app->user->id;
343 347 }
344 348  
345 349 $headers = \Yii::$app->response->headers;
346 350 $headers->set('Access-Control-Allow-Origin', '*');
347   -
  351 +
348 352 if ($model->load(Yii::$app->request->post()) && $model->save()) {
349 353 $this->unblockOrder($model->id);
350 354 return $this->render(
... ... @@ -365,7 +369,7 @@
365 369 }
366 370 }
367 371  
368   - public function actionFindProduct($q = NULL, $id = NULL)
  372 + public function actionFindProduct($q = null, $id = null)
369 373 {
370 374 \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
371 375 $out = [
... ... @@ -424,7 +428,7 @@
424 428  
425 429 protected function findModel($id)
426 430 {
427   - if (( $model = Order::findOne($id) ) !== NULL) {
  431 + if (( $model = Order::findOne($id) ) !== null) {
428 432 return $model;
429 433 } else {
430 434 throw new NotFoundHttpException('The requested page does not exist.');
... ... @@ -445,9 +449,9 @@
445 449 if (!$model->published) {
446 450 $model->deleteUnpublished();
447 451 }
448   -// return $this->redirect('index');
  452 + // return $this->redirect('index');
449 453 }
450   -
  454 +
451 455 public function actionCloseOrder($id)
452 456 {
453 457 try {
... ... @@ -458,16 +462,16 @@
458 462 if ($model->edit_id == \Yii::$app->user->id) {
459 463 $this->unblockOrder($id);
460 464 }
461   -
  465 +
462 466 if (!$model->published) {
463 467 $model->deleteUnpublished();
464 468 }
465   - return $this->redirect('index');
  469 + return $this->redirect('index');
466 470 }
467 471  
468 472 public function actionBlockOrder()
469 473 {
470   - if (!empty(\Yii::$app->request->post())) {
  474 + if (!empty( \Yii::$app->request->post() )) {
471 475 \Yii::$app->response->format = Response::FORMAT_JSON;
472 476  
473 477 $model = $this->findModel(\Yii::$app->request->post('id'));
... ... @@ -484,7 +488,7 @@
484 488 if ($model->save()) {
485 489 return [
486 490 'time' => $date,
487   - 'user' => !empty($user) ? $user->username : '',
  491 + 'user' => !empty( $user ) ? $user->username : '',
488 492 ];
489 493 } else {
490 494 return [
... ...
helpers/CatalogFilterHelper.php
... ... @@ -320,14 +320,13 @@ class CatalogFilterHelper extends Object
320 320 */
321 321 private static function filterPrices(array $params, array &$filters)
322 322 {
323   - $filterP['nested']['path'] = 'variants';
  323 +
324 324 if (!empty( $params[ 'min' ] ) && $params[ 'min' ] > 0) {
325   - $filterP['nested']['query']['bool']['filter'][]['range']['variants.price']['gte'] = $params[ 'min' ];
  325 + $filters['bool']['filter'][]['range']['price']['gte'] = $params[ 'min' ];
326 326 }
327 327 if (!empty( $params[ 'max' ] ) && $params[ 'max' ] > 0) {
328   - $filterP['nested']['query']['bool']['filter'][]['range']['variants.price']['lte'] = $params[ 'max' ];
  328 + $filters['bool']['filter'][]['range']['price']['lte'] = $params[ 'max' ];
329 329 }
330   - $filters['bool']['must'][] = $filterP;
331 330  
332 331 }
333 332  
... ...
models/Order.php
... ... @@ -141,7 +141,10 @@
141 141 'required',
142 142 ],
143 143 [
144   - [ 'comment' ],
  144 + [
  145 + 'comment',
  146 + 'body',
  147 + ],
145 148 'string',
146 149 ],
147 150 [
... ... @@ -161,7 +164,6 @@
161 164 'deadline',
162 165 'name',
163 166 'numbercard',
164   - 'body',
165 167 'declaration',
166 168 'stock',
167 169 'consignment',
... ... @@ -183,7 +185,7 @@
183 185 public function afterFind()
184 186 {
185 187 parent::afterFind();
186   - $this->deadline = !empty($this->deadline) ? date('d.m.Y', $this->deadline) : '';
  188 + $this->deadline = !empty( $this->deadline ) ? date('d.m.Y', $this->deadline) : '';
187 189  
188 190 }
189 191  
... ... @@ -200,7 +202,7 @@
200 202  
201 203 protected function convertDate()
202 204 {
203   - if (!empty($this->deadline)) {
  205 + if (!empty( $this->deadline )) {
204 206 $date = new \DateTime();
205 207 $date->setTimestamp(strtotime($this->deadline));
206 208 $date->format("d.m.Y");
... ... @@ -289,8 +291,8 @@
289 291 */
290 292 public function getDeliveryString()
291 293 {
292   - if (!empty($this->orderDelivery)) {
293   - if (!empty($this->orderDelivery->parent)) {
  294 + if (!empty( $this->orderDelivery )) {
  295 + if (!empty( $this->orderDelivery->parent )) {
294 296 return $this->orderDelivery->parent->lang->title . ': ' . $this->orderDelivery->lang->title;
295 297 } else {
296 298 return $this->orderDelivery->lang->title;
... ... @@ -308,7 +310,7 @@
308 310 */
309 311 public function getWasted()
310 312 {
311   - if (empty($this->deadline)) {
  313 + if (empty( $this->deadline )) {
312 314 return false;
313 315 } else {
314 316 return time() > strtotime($this->deadline);
... ...
models/Product.php
... ... @@ -332,7 +332,21 @@
332 332 ]
333 333 );
334 334 }
335   -
  335 +
  336 +
  337 + public function getMaxPrice(){
  338 + $price = 0;
  339 + if (!empty( $this->enabledVariants )) {
  340 + foreach ( $this->enabledVariants as $variant){
  341 + if($variant->price > $price){
  342 + $price = $variant->price;
  343 + }
  344 + }
  345 + }
  346 + return $price;
  347 + }
  348 +
  349 +
336 350 /**
337 351 * Get random ProductVariant price or 0 if not exist
338 352 *
... ...
views/category/_form_language.php
1 1 <?php
2 2 use artweb\artbox\language\models\Language;
3 3 use artweb\artbox\ecommerce\models\CategoryLang;
  4 + use mihaildev\ckeditor\CKEditor;
4 5 use yii\web\View;
5 6 use yii\widgets\ActiveForm;
6 7  
... ... @@ -30,7 +31,11 @@
30 31 ->textInput([ 'maxlength' => true ]) ?>
31 32  
32 33 <?= $form->field($model_lang, '[' . $language->id . ']seo_text')
33   - ->textarea([ 'rows' => 6 ]) ?>
  34 + ->widget(CKEditor::className(), [
  35 + 'editorOptions' => [
  36 + 'preset' => 'standard',
  37 + ]
  38 + ]) ?>
34 39  
35 40 <?= $form->field($model_lang, '[' . $language->id . ']h1')
36 41 ->textInput([ 'maxlength' => true ]) ?>
37 42 \ No newline at end of file
... ...
views/order/print.php 0 → 100755
  1 +<?php
  2 +
  3 +use artweb\artbox\ecommerce\models\Order;
  4 +use artweb\artbox\ecommerce\models\OrderProduct;use yii\data\ArrayDataProvider;
  5 +use yii\grid\GridView;
  6 +use yii\helpers\ArrayHelper;use yii\web\View;
  7 +use yii\widgets\DetailView;
  8 +
  9 +/**
  10 + * @var View $this
  11 + * @var Order $order
  12 + * @var ArrayDataProvider $dataProvider
  13 + */
  14 +?>
  15 +<?php $this->beginPage(); ?>
  16 +<!DOCTYPE html>
  17 +<html>
  18 +<head>
  19 + <meta charset="utf-8">
  20 + <?php $this->head() ?>
  21 + <script>
  22 +// window.print();
  23 + </script>
  24 +</head>
  25 +<body>
  26 +<?php $this->beginBody(); ?>
  27 +<div>
  28 +<?php
  29 + echo DetailView::widget([
  30 + 'model' => $order,
  31 + 'attributes' => [
  32 + [
  33 + 'attribute' => 'manager.username',
  34 + 'label' => \Yii::t('app', 'Manager Username'),
  35 + ],
  36 + 'id',
  37 + 'created_at:date',
  38 + [
  39 + 'attribute' => 'user.username',
  40 + 'label' => \Yii::t('app', 'Client Username'),
  41 + ],
  42 + [
  43 + 'attribute' => 'email',
  44 + 'value' => $order->email?:(!empty($order->user)?$order->user->email:null),
  45 + ],
  46 + [
  47 + 'attribute' => 'phone',
  48 + 'value' => $order->phone?:(!empty($order->user)?$order->user->phone:null),
  49 + ],
  50 + [
  51 + 'attribute' => 'phone2',
  52 + 'value' => $order->phone2?:null,
  53 + ],
  54 + [
  55 + 'attribute' => 'numbercard',
  56 + 'value' => $order->numbercard?:null,
  57 + ],
  58 + [
  59 + 'attribute' => 'comment',
  60 + 'value' => $order->comment?:null,
  61 + ],
  62 + [
  63 + 'attribute' => 'delivery',
  64 + 'value' => $order->deliveryString?:null,
  65 + ],
  66 + [
  67 + 'attribute' => 'declaration',
  68 + 'value' => $order->declaration?:null,
  69 + ],
  70 + [
  71 + 'attribute' => 'stock',
  72 + 'value' => $order->stock?:null,
  73 + ],
  74 + [
  75 + 'attribute' => 'payment',
  76 + 'value' => $order->orderPayment?$order->orderPayment->lang->title:null,
  77 + ],
  78 + [
  79 + 'attribute' => 'insurance',
  80 + 'value' => $order->insurance?:null,
  81 + ],
  82 + [
  83 + 'attribute' => 'amount_imposed',
  84 + 'value' => $order->amount_imposed?:null,
  85 + ],
  86 + [
  87 + 'attribute' => 'shipping_by',
  88 + 'value' => $order->shipping_by?:null,
  89 + ],
  90 + [
  91 + 'attribute' => 'city',
  92 + 'value' => $order->city?:null,
  93 + ],
  94 + [
  95 + 'attribute' => 'adress',
  96 + 'value' => $order->adress?:null,
  97 + ],
  98 + [
  99 + 'attribute' => 'body',
  100 + 'value' => $order->body?:null,
  101 + ],
  102 + ],
  103 + ]);
  104 + ?>
  105 +</div>
  106 +<div>
  107 +<?php
  108 + if(!empty($order->products)) {
  109 + echo GridView::widget([
  110 + 'tableOptions' => [
  111 + 'cellspacing' => '10',
  112 + 'cellpadding' => '3',
  113 + ],
  114 + 'dataProvider' => $dataProvider,
  115 + 'columns' => [
  116 + [
  117 + 'class' => 'yii\grid\SerialColumn',
  118 + ],
  119 + 'sku',
  120 + [
  121 + 'attribute' => 'productVariant.product.brand.lang.title',
  122 + 'label' => \Yii::t('app', 'Brand'),
  123 + ],
  124 + [
  125 + 'attribute' => 'productVariant.product.fullName',
  126 + 'label' => \Yii::t('app', 'Fullname'),
  127 + ],
  128 + [
  129 + 'label' => \Yii::t('app', 'Properties'),
  130 + 'value' => function($model) {
  131 + /**
  132 + * @var OrderProduct $model
  133 + */
  134 + $value = '';
  135 + foreach ($model->productVariant->properties as $property) {
  136 + $value .= $property->lang->title.':'.implode(',', ArrayHelper::getColumn($property->customOptions, 'lang.value')).'<br />';
  137 + }
  138 + return $value;
  139 + },
  140 + 'format' => 'html',
  141 + ],
  142 + 'count',
  143 + 'price',
  144 + 'sum_cost',
  145 + 'booking',
  146 + ],
  147 + 'showOnEmpty' => false,
  148 + 'layout' => "{items}",
  149 + ]);
  150 +}
  151 + ?>
  152 +</div>
  153 +<div>
  154 +<div style="display: inline-block; padding-right: 10px"><strong><?php echo $order->getAttributeLabel('total').': '.\Yii::$app->formatter->asDecimal($order->total); ?> грн.</strong></div>
  155 +<div style="display: inline-block"><strong><?php echo $order->getAttributeLabel('delivery_cost').': '.\Yii::$app->formatter->asDecimal($order->delivery_cost); ?></strong></div>
  156 +</div>
  157 +<div style="border-bottom: 4px dotted #a1a1a1; width: 100%; margin: 20px 0"></div>
  158 +<div>
  159 +<?php
  160 +echo DetailView::widget([
  161 + 'model' => $order,
  162 + 'attributes' => [
  163 + 'id',
  164 + 'created_at:date',
  165 + [
  166 + 'attribute' => 'user.username',
  167 + 'label' => \Yii::t('app', 'Client Username'),
  168 + ],
  169 + [
  170 + 'attribute' => 'phone',
  171 + 'value' => $order->phone?:(!empty($order->user)?$order->user->phone:null),
  172 + ],
  173 + [
  174 + 'attribute' => 'city',
  175 + 'value' => $order->city?:null,
  176 + ],
  177 + [
  178 + 'attribute' => 'adress',
  179 + 'value' => $order->adress?:null,
  180 + ],
  181 + [
  182 + 'attribute' => 'comment',
  183 + 'value' => $order->comment?:null,
  184 + ],
  185 + [
  186 + 'attribute' => 'stock',
  187 + 'value' => $order->stock?:null,
  188 + ],
  189 + [
  190 + 'attribute' => 'insurance',
  191 + 'value' => $order->insurance?:null,
  192 + ],
  193 + [
  194 + 'attribute' => 'amount_imposed',
  195 + 'value' => $order->amount_imposed?:null,
  196 + ],
  197 + [
  198 + 'attribute' => 'shipping_by',
  199 + 'value' => $order->shipping_by?:null,
  200 + ],
  201 + ],
  202 +]);
  203 + ?>
  204 +</div>
  205 +<?php $this->endBody(); ?>
  206 +</body>
  207 +</html>
  208 +<?php $this->endPage(); ?>
0 209 \ No newline at end of file
... ...