diff --git a/controllers/OrderController.php b/controllers/OrderController.php index 2b2a1d5..bb87173 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -4,7 +4,6 @@ use artweb\artbox\components\SmsSender; use artweb\artbox\ecommerce\models\OrderLabelHistory; - use artweb\artbox\ecommerce\models\OrderLog; use artweb\artbox\ecommerce\models\OrderSearch; use common\components\CreditHelper; use common\models\User; @@ -151,7 +150,24 @@ $productLogData = new ActiveDataProvider( [ - 'query' => $model->getProductLogs(), + 'query' => $model->getProducts() + ->with([ + 'logs' => function(ActiveQuery $query) { + $query->with('user'); + }, + 'productVariant' => function(ActiveQuery $query) { + $query->with([ + 'lang', + 'product' => function(ActiveQuery $query) { + $query->with([ + 'lang', + 'category.lang', + 'brand.lang', + ]); + } + ]); + }, + ]), ] ); @@ -175,17 +191,6 @@ return $this->redirect([ 'index' ]); } - // public function actionDeleteProduct($id) - // { - // $model = OrderProduct::findOne($id); - // $model->removed = true; - // $orderId = $model->order_id; - // if ($model->save()) { - // $model->order->totalRecount(); - // return $this->actionUpdate($orderId); - // } - // } - public function actionAdd() { if (!empty(\Yii::$app->request->post())) { @@ -285,26 +290,26 @@ ] ); - $dataProvider = new ActiveDataProvider( - [ - 'query' => $model->getProducts() - ->joinWith('productVariant'), - ] - ); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - $model->published = true; - $model->save(); - return $this->redirect([ 'index' ]); - } else { - return $this->render( - 'create', - [ - 'model' => $model, - 'dataProvider' => $dataProvider, - ] - ); - } + // $dataProvider = new ActiveDataProvider( + // [ + // 'query' => $model->getProducts() + // ->joinWith('productVariant'), + // ] + // ); + // + // if ($model->load(Yii::$app->request->post()) && $model->save()) { + // $model->published = true; + // $model->save(); + // return $this->redirect([ 'index' ]); + // } else { + // return $this->render( + // 'create', + // [ + // 'model' => $model, + // 'dataProvider' => $dataProvider, + // ] + // ); + // } } public function actionPrint($order_id) @@ -442,7 +447,7 @@ public function actionFindProduct($q = NULL, $id = NULL) { - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + \Yii::$app->response->format = Response::FORMAT_JSON; $out = [ 'results' => [ 'id' => '', @@ -450,13 +455,7 @@ ], ]; if (!is_null($q)) { - $result = ProductVariant::find()// ->select( - // [ - // 'id', - // 'sku', - // 'product_lang.title AS name' - // ] - // ) + $result = ProductVariant::find() ->joinWith('product.lang') ->where( [ @@ -491,7 +490,7 @@ $model->save(); $order = Order::findOne($order_id); $order->totalRecount(); - \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; + \Yii::$app->response->format = Response::FORMAT_JSON; return [ 'status' => 'success', 'id' => $id, @@ -521,7 +520,6 @@ if (!$model->published) { $model->deleteUnpublished(); } - // return $this->redirect('index'); } public function actionCloseOrder($id) diff --git a/models/OrderProduct.php b/models/OrderProduct.php index 8bd3dfa..15fe2a8 100755 --- a/models/OrderProduct.php +++ b/models/OrderProduct.php @@ -9,21 +9,22 @@ /** * Class OrderProduct * - * @property int $id - * @property int $order_id - * @property int $product_variant_id - * @property string $booking - * @property string $status - * @property boolean $return - * @property string $product_name - * @property string $name - * @property string $sku - * @property double $price - * @property int $count - * @property double $sum_cost - * @property Order $order - * @property boolean $removed - * @property ProductVariant $productVariant + * @property int $id + * @property int $order_id + * @property int $product_variant_id + * @property string $booking + * @property string $status + * @property boolean $return + * @property string $product_name + * @property string $name + * @property string $sku + * @property double $price + * @property int $count + * @property double $sum_cost + * @property Order $order + * @property boolean $removed + * @property OrderProductLog[] $logs + * @property ProductVariant $productVariant * @package artweb\artbox\ecommerce\models */ class OrderProduct extends ActiveRecord @@ -99,9 +100,16 @@ 'return' => Yii::t('app', 'Возврат'), 'sku' => Yii::t('app', 'Артикул'), 'price' => Yii::t('app', 'Цена'), + 'order_id' => Yii::t('app', 'Id заказа'), + 'product_variant_id' => Yii::t('app', 'Id товара'), + 'id' => Yii::t('app', 'Id'), + 'removed' => Yii::t('app', 'Удален'), ]; } + /** + * @return \yii\db\ActiveQuery + */ public function getOrder() { return $this->hasOne(Order::className(), [ 'id' => 'order_id' ]); @@ -114,4 +122,12 @@ { return $this->hasOne(ProductVariant::className(), [ 'id' => 'product_variant_id' ]); } + + /** + * @return \yii\db\ActiveQuery + */ + public function getLogs() + { + return $this->hasMany(OrderProductLog::className(), [ 'order_product_id' => 'id' ]); + } } \ No newline at end of file diff --git a/views/order/_log_product_item.php b/views/order/_log_product_item.php index 64720b3..d281e7a 100644 --- a/views/order/_log_product_item.php +++ b/views/order/_log_product_item.php @@ -1,44 +1,195 @@ +
+
+

История товара sku; ?>

+
+ +
+
+
- -
  • - - -
    - formatter->asDatetime($model->created_at) ?> - -

    Пользователь: user->username ?>

    - -
    - - - - - - - data) as $key => $item) { - echo Html::tag( - 'tr', - Html::tag('td', $key ) . Html::tag('td', $item[ 'old' ]) . Html::tag( - 'td', - $item[ 'new' ] - ) - ); - } - ?> -
    ПолеСтарое значениеНовое значение
    +
    + product_name); + if (empty($model->productVariant)) { + echo ''; + } else { + echo Html::img( + $model->productVariant->imageUrl, + [ + 'class' => 'img-thumbnail', + ] + ); + } + echo Html::beginTag('br'); + ?>
    -
    -
  • + + +
    + logs)) { + echo Html::beginTag( + 'ul', + [ + 'class' => 'timeline', + ] + ); + foreach ($model->logs as $log) { + /** + * @var OrderProductLog $log + */ + $data = Json::decode($log->data); ?> + +
  • + +
    + formatter->asDatetime( + $log->created_at + ) ?> + +

    user) ? Html::tag( + 'span', + 'Добавлен с сайта', + [ 'class' => 'text-orange' ] + ) : 'Пользователь: ' . Html::tag('span', $log->user->username, [ 'class' => 'text-blue' ]) ?> +

    + +
    + Товар удален +
    + +
    + Товар добавлен +
    + +
    +
      + $item) { + echo Html::tag( + 'li', + $model->attributeLabels()[ $key ] . ' > ' . Html::tag( + 'span', + \Yii::$app->formatter->asText($item[ 'old' ]), + [ 'class' => 'text-red' ] + ) . ' > ' . Html::tag('span', + \Yii::$app->formatter->asText($item[ 'new' ]), + [ 'class' => 'text-green' ]), + [ 'class' => 'item' ] + ); + } ?> +
    +
    + +
    +
  • + +
    + +
    +
    diff --git a/views/order/log.php b/views/order/log.php index 6bbef0f..5b4d6de 100755 --- a/views/order/log.php +++ b/views/order/log.php @@ -18,51 +18,19 @@ 'label' => \Yii::t('app', 'Заказы'), ]; $this->params[ 'breadcrumbs' ][] = [ - 'url' => yii\helpers\Url::to([ '/ecommerce/order/view', 'id' => $model->id ]), + 'url' => yii\helpers\Url::to( + [ + '/ecommerce/order/view', + 'id' => $model->id, + ] + ), 'label' => \Yii::t('app', 'Заказ #') . $model->id, ]; $this->params[ 'breadcrumbs' ][] = $this->title; - + ?>
    - -
    -
    -

    История

    -
    - -
    -
    -
    - - $logData, - 'layout' => '{items}', - 'itemView' => '_log_item', - 'itemOptions' => [ - 'tag' => false, - ], - 'options' => [ - 'tag' => $logData->totalCount == 0 ? 'div' : 'ul', - 'class' => $logData->totalCount == 0 ? 'list-view' : 'list-view timeline', - ], - 'viewParams' => [ - 'order' => $model, - ], - 'emptyText' => 'У этого заказа пока нет истории', - 'emptyTextOptions' => [ - 'class' => 'callout callout-info' - ], - ] - ); - ?> - -
    -
    @@ -77,22 +45,22 @@ $productLogData, - 'layout' => '{items}', - 'itemView' => '_log_product_item', - 'itemOptions' => [ + 'dataProvider' => $logData, + 'layout' => '{items}', + 'itemView' => '_log_item', + 'itemOptions' => [ 'tag' => false, ], - 'options' => [ - 'tag' => $productLogData->totalCount == 0 ? 'div' : 'ul', - 'class' => $productLogData->totalCount == 0 ? 'list-view' : 'list-view timeline', + 'options' => [ + 'tag' => $logData->totalCount == 0 ? 'div' : 'ul', + 'class' => $logData->totalCount == 0 ? 'list-view' : 'list-view timeline', ], - 'viewParams' => [ + 'viewParams' => [ 'order' => $model, ], - 'emptyText' => 'У этого заказа пока нет истории', + 'emptyText' => 'У этого заказа пока нет истории', 'emptyTextOptions' => [ - 'class' => 'callout callout-info' + 'class' => 'callout callout-info', ], ] ); @@ -100,5 +68,28 @@
    - + + $productLogData, + 'layout' => '{items}', + 'itemView' => '_log_product_item', + 'itemOptions' => [ + 'tag' => false, + ], + 'viewParams' => [ + 'order' => $model, + ], + 'options' => [ + 'class' => 'list-view', + ], + 'emptyText' => 'У этого заказа нет товаров', + 'emptyTextOptions' => [ + 'class' => 'callout callout-info', + ], + ] + ); + ?> +
    -- libgit2 0.21.4