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 @@ +
Поле | -Старое значение | -Новое значение | -
---|