From 72a992f5e8b37ee1836d3507f3fa1691881988e7 Mon Sep 17 00:00:00 2001 From: yarik Date: Thu, 13 Oct 2016 18:59:33 +0300 Subject: [PATCH] Import browser v1.0 --- backend/controllers/BannerController.php | 32 +++++++++++++------------------- backend/controllers/BgController.php | 32 +++++++++++++------------------- backend/controllers/BrandController.php | 38 +++++++++++++++----------------------- backend/controllers/CategoryController.php | 47 ++++++++++++++++------------------------------- backend/controllers/EventController.php | 41 ++++++++++++++++------------------------- backend/controllers/PageController.php | 32 +++++++++++++------------------- backend/controllers/ProjectController.php | 41 ++++++++++++++++------------------------- backend/controllers/SeoCategoryController.php | 32 +++++++++++++------------------- backend/controllers/SeoController.php | 32 +++++++++++++------------------- backend/controllers/SeoDynamicController.php | 31 +++++++++++-------------------- backend/controllers/ServiceController.php | 35 ++++++++++++++--------------------- backend/models/Label.php | 13 ++++++++----- common/behaviors/Slug.php | 30 ++++++++++++++++++------------ common/models/Banner.php | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------- common/models/Bg.php | 13 +++++++++---- common/models/Delivery.php | 25 ++++++++++++++----------- common/models/Event.php | 223 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------------------------------------------- common/models/Page.php | 9 ++++++--- common/models/ProductSpec.php | 68 ++++++++++++++++++++++++++++++++++++-------------------------------- common/models/Project.php | 14 ++++++++++---- common/models/Seo.php | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------- common/models/SeoCategory.php | 168 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------- common/models/SeoDynamic.php | 11 +++++++---- common/models/Service.php | 11 +++++++---- common/models/SliderImage.php | 16 +++++++--------- common/modules/language/behaviors/LanguageBehavior.php | 7 +++---- common/modules/language/readme.txt | 6 +++--- common/modules/product/controllers/ManageController.php | 48 ++++++++++++------------------------------------ common/modules/product/controllers/ProductUnitController.php | 34 +++++++++++++--------------------- common/modules/product/controllers/VariantController.php | 50 +++++++++++--------------------------------------- common/modules/product/helpers/ProductHelper.php | 2 +- common/modules/product/models/Brand.php | 15 +++++++++------ common/modules/product/models/Category.php | 55 ++++++++++++++++++++++++++----------------------------- common/modules/product/models/CategoryLang.php | 2 +- common/modules/product/models/CategorySearch.php | 10 ---------- common/modules/product/models/Export.php | 26 ++++++++++++++++++++------ common/modules/product/models/Import.php | 10 +++++++--- common/modules/product/models/Product.php | 23 +++++++++++++---------- common/modules/product/models/ProductSearch.php | 10 ---------- common/modules/product/models/ProductUnit.php | 176 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------- common/modules/product/models/ProductVariant.php | 50 +++++++++++++++++++++++++++----------------------- common/modules/product/models/ProductVariantListSearch.php | 8 +------- common/modules/product/models/ProductVariantSearch.php | 10 ---------- common/modules/product/views/manage/_form.php | 24 +++++++++++++++--------- common/modules/product/views/variant/_form.php | 29 +++++++++++++++++------------ common/modules/rubrication/controllers/TaxGroupController.php | 19 ++++++++----------- common/modules/rubrication/controllers/TaxOptionController.php | 30 ++++++++++-------------------- common/modules/rubrication/models/TaxGroup.php | 17 +++++++++++------ common/modules/rubrication/models/TaxOption.php | 11 +++++++---- common/modules/rubrication/views/tax-group/_form.php | 2 +- 50 files changed, 942 insertions(+), 1020 deletions(-) diff --git a/backend/controllers/BannerController.php b/backend/controllers/BannerController.php index c58fba4..8450a61 100755 --- a/backend/controllers/BannerController.php +++ b/backend/controllers/BannerController.php @@ -82,26 +82,21 @@ public function actionCreate() { $model = new Banner(); - $model_langs = $model->generateLangs(); + $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->banner_id, ]); - } else { - return $this->redirect('update', [ - 'id' => $model->banner_id, - ]); } - } else { - return $this->render('create', [ - 'model' => $model, - 'model_langs' => $model_langs, - ]); } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); } /** @@ -115,11 +110,10 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); - - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->banner_id, @@ -128,7 +122,7 @@ } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } diff --git a/backend/controllers/BgController.php b/backend/controllers/BgController.php index 589c5fe..fbafd5c 100755 --- a/backend/controllers/BgController.php +++ b/backend/controllers/BgController.php @@ -82,27 +82,21 @@ public function actionCreate() { $model = new Bg(); - $model_langs = $model->generateLangs(); + $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->id, ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->id, - ]); } - } else { - return $this->render('create', [ - 'model' => $model, - 'model_langs' => $model_langs, - ]); } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); } /** @@ -116,11 +110,11 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); + $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->id, @@ -129,7 +123,7 @@ } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } diff --git a/backend/controllers/BrandController.php b/backend/controllers/BrandController.php index f105d03..8f76829 100755 --- a/backend/controllers/BrandController.php +++ b/backend/controllers/BrandController.php @@ -92,25 +92,19 @@ public function actionCreate() { $model = new Brand(); - $model_langs = $model->generateLangs(); + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->save()) { - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ - 'view', - 'id' => $model->brand_id, - ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); - } - } else { - return $this->redirect('update', [ + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { + return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ + 'view', 'id' => $model->brand_id, - ]); + ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); } } return $this->render('create', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } @@ -125,22 +119,20 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->save()) { - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - return $this->redirect([ - 'view', - 'id' => $model->brand_id, - ]); - } + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { + return $this->redirect([ + 'view', + 'id' => $model->brand_id, + ]); } } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } diff --git a/backend/controllers/CategoryController.php b/backend/controllers/CategoryController.php index 3d2a8d5..f347685 100755 --- a/backend/controllers/CategoryController.php +++ b/backend/controllers/CategoryController.php @@ -10,7 +10,6 @@ use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; - use yii\web\UploadedFile; /** * CategoryController implements the CRUD actions for Category model. @@ -84,32 +83,22 @@ public function actionCreate() { $model = new Category(); - $model_langs = $model->generateLangs(); - + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); - - if($model->save()) { - - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ - 'view', - 'id' => $model->category_id, - ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); - } else { - return $this->redirect('update', [ - 'id' => $model->category_id, - ]); - } + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { + return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ + 'view', + 'id' => $model->category_id, + ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); } - } if(!empty( Yii::$app->request->queryParams[ 'parent' ] )) { $model->parent_id = Yii::$app->request->queryParams[ 'parent' ]; } return $this->render('create', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, 'categories' => ArtboxTreeHelper::treeMap(Category::find() ->getTree(), 'category_id', 'category_id', '.'), ]); @@ -126,23 +115,19 @@ public function actionUpdate($id) { $model = $this->findModel($id); - - $model_langs = $model->generateLangs(); - + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->save()) { - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - return $this->redirect([ - 'view', - 'id' => $model->category_id, - ]); - } + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { + return $this->redirect([ + 'view', + 'id' => $model->category_id, + ]); } } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, 'categories' => ArtboxTreeHelper::treeMap(Category::find() ->getTree(), 'category_id', 'category_id', '.'), ]); diff --git a/backend/controllers/EventController.php b/backend/controllers/EventController.php index dece42b..315c33e 100755 --- a/backend/controllers/EventController.php +++ b/backend/controllers/EventController.php @@ -82,29 +82,22 @@ public function actionCreate() { $model = new Event(); - $model_langs = $model->generateLangs(); + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); + $model->loadLangs(\Yii::$app->request); - if($model->save()) { - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - return $this->redirect([ - 'view', - 'id' => $model->event_id, - ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->event_id, - ]); - } + if($model->save() && $model->transactionStatus) { + return $this->redirect([ + 'view', + 'id' => $model->event_id, + ]); } } return $this->render('create', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } @@ -119,24 +112,22 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); + $model->loadLangs(\Yii::$app->request); - if($model->save()) { - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - return $this->redirect([ - 'view', - 'id' => $model->event_id, - ]); - } + if($model->save() && $model->transactionStatus) { + return $this->redirect([ + 'view', + 'id' => $model->event_id, + ]); } } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } diff --git a/backend/controllers/PageController.php b/backend/controllers/PageController.php index 5400aa4..e9b6521 100755 --- a/backend/controllers/PageController.php +++ b/backend/controllers/PageController.php @@ -82,26 +82,20 @@ public function actionCreate() { $model = new Page(); - $model_langs = $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->id, ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->id, - ]); } - } else { - return $this->render('create', [ - 'model' => $model, - 'model_langs' => $model_langs, - ]); } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); } /** @@ -115,11 +109,11 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); + $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->id, @@ -128,7 +122,7 @@ } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } diff --git a/backend/controllers/ProjectController.php b/backend/controllers/ProjectController.php index d209fbc..4c16af2 100755 --- a/backend/controllers/ProjectController.php +++ b/backend/controllers/ProjectController.php @@ -89,11 +89,11 @@ public function actionCreate() { $model = new Project(); - $model_langs = $model->generateLangs(); + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); + $model->loadLangs(\Yii::$app->request); $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); - if($model->save()) { + if($model->save() && $model->transactionStatus) { if($model->imagesUpload && ( ( $images = $model->imagesUpload() ) !== false )) { foreach($images as $image) { $imageModel = new ProjectImage(); @@ -102,22 +102,15 @@ $imageModel->save(); } } - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - return $this->redirect([ - 'view', - 'id' => $model->project_id, - ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->project_id, - ]); - } + return $this->redirect([ + 'view', + 'id' => $model->project_id, + ]); } } return $this->render('create', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } @@ -132,11 +125,11 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); + $model->loadLangs(\Yii::$app->request); $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); - if($model->save()) { + if($model->save() && $model->transactionStatus) { if($model->imagesUpload && ( ( $images = $model->imagesUpload() ) !== false )) { foreach($images as $image) { $imageModel = new ProjectImage(); @@ -145,17 +138,15 @@ $imageModel->save(); } } - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - return $this->redirect([ - 'view', - 'id' => $model->project_id, - ]); - } + return $this->redirect([ + 'view', + 'id' => $model->project_id, + ]); } } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } diff --git a/backend/controllers/SeoCategoryController.php b/backend/controllers/SeoCategoryController.php index 653d3f7..0c390f0 100755 --- a/backend/controllers/SeoCategoryController.php +++ b/backend/controllers/SeoCategoryController.php @@ -80,27 +80,21 @@ public function actionCreate() { $model = new SeoCategory(); - $model_langs = $model->generateLangs(); + $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->seo_category_id, ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->seo_category_id, - ]); } - } else { - return $this->render('create', [ - 'model' => $model, - 'model_langs' => $model_langs, - ]); } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); } /** @@ -114,10 +108,10 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->seo_category_id, @@ -126,7 +120,7 @@ } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } diff --git a/backend/controllers/SeoController.php b/backend/controllers/SeoController.php index ed5dfc2..84b137b 100755 --- a/backend/controllers/SeoController.php +++ b/backend/controllers/SeoController.php @@ -80,27 +80,21 @@ public function actionCreate() { $model = new Seo(); - $model_langs = $model->generateLangs(); + $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->seo_id, ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->seo_id, - ]); } - } else { - return $this->render('create', [ - 'model' => $model, - 'model_langs' => $model_langs, - ]); } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); } /** @@ -114,10 +108,10 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->seo_id, @@ -126,7 +120,7 @@ } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } diff --git a/backend/controllers/SeoDynamicController.php b/backend/controllers/SeoDynamicController.php index 475da29..2ce776a 100755 --- a/backend/controllers/SeoDynamicController.php +++ b/backend/controllers/SeoDynamicController.php @@ -82,31 +82,22 @@ public function actionCreate($seo_category_id) { $model = new SeoDynamic(); - $model_langs = $model->generateLangs(); - + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); + $model->loadLangs(\Yii::$app->request); $model->seo_category_id = $seo_category_id; - $model->save(); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'index', 'seo_category_id' => $model->seo_category_id, ]); - } else { - return $this->redirect([ - 'update', - 'seo_category_id' => $model->seo_category_id, - 'id' => $model->seo_dynamic_id, - ]); } - } else { - return $this->render('create', [ - 'model' => $model, - 'model_langs' => $model_langs, - 'seo_category_id' => $seo_category_id, - ]); } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + 'seo_category_id' => $seo_category_id, + ]); } /** @@ -121,9 +112,9 @@ { $model = $this->findModel($id); $model_langs = $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'index', 'seo_category_id' => $model->seo_category_id, diff --git a/backend/controllers/ServiceController.php b/backend/controllers/ServiceController.php index 64497b7..1a80a55 100755 --- a/backend/controllers/ServiceController.php +++ b/backend/controllers/ServiceController.php @@ -82,27 +82,20 @@ public function actionCreate() { $model = new Service(); - $model_langs = $model->generateLangs(); - - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->service_id, ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->service_id, - ]); } - } else { - return $this->render('create', [ - 'model' => $model, - 'model_langs' => $model_langs, - ]); } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); } /** @@ -116,11 +109,11 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); + $model->generateLangs(); - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->service_id, @@ -128,8 +121,8 @@ } } return $this->render('update', [ - 'model' => $model, - 'model_langs' => $model_langs, + 'model' => $model, + 'model_langs' => $model->model_langs, ]); } diff --git a/backend/models/Label.php b/backend/models/Label.php index 98d0d73..7421573 100755 --- a/backend/models/Label.php +++ b/backend/models/Label.php @@ -16,6 +16,8 @@ use yii\web\Request; * @property OrdersLabelLang $object_lang * @property string $ownerKey * @property string $langKey + * @property OrdersLabelLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey(string $value) * @method string getLangKey() @@ -23,12 +25,13 @@ use yii\web\Request; * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method OrdersLabelLang[] generateLangs() - * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) - * @method bool linkLangs(ActiveRecord[] $model_langs) - * @method bool saveLangs(ActiveRecord[] $model_langs) - * * End language behavior * + * @method void loadLangs(Request $request) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() + * * End language behavior */ -class Label extends \yii\db\ActiveRecord +class Label extends ActiveRecord { public static function tableName() diff --git a/common/behaviors/Slug.php b/common/behaviors/Slug.php index 01abbb0..a7d7314 100755 --- a/common/behaviors/Slug.php +++ b/common/behaviors/Slug.php @@ -12,7 +12,7 @@ public $in_attribute = 'name'; - public $out_attribute = 'slug'; + public $out_attribute = 'alias'; public $translit = true; @@ -66,18 +66,24 @@ private function checkUniqueSlug($slug) { - $pk = $this->owner->primaryKey(); - $pk = $pk[ 0 ]; - - $condition = $this->out_attribute . ' = :out_attribute'; - $params = [ ':out_attribute' => $slug ]; - if(!$this->owner->isNewRecord) { - $condition .= ' and ' . $pk . ' != :pk'; - $params[ ':pk' ] = $this->owner->{$pk}; + /** + * @var ActiveRecord $owner + */ + $owner = $this->owner; + $query = $owner->find()->where([ + $this->out_attribute => $slug, + ]); + if(!$owner->isNewRecord) { + $pks = $owner->primaryKey(); + if(!empty($pks)) { + $pk_rules = ['and']; + foreach($pks as $pk) { + $pk_rules[] = [$pk => $owner->$pk]; + } + $query->andWhere(['not', $pk_rules]); + } } - return !$this->owner->find() - ->where($condition, $params) - ->one(); + return !$query->exists(); } } \ No newline at end of file diff --git a/common/models/Banner.php b/common/models/Banner.php index c3cd6ef..7387cbf 100755 --- a/common/models/Banner.php +++ b/common/models/Banner.php @@ -1,76 +1,85 @@ [ - 'class' => LanguageBehavior::className(), - ], - ]; - } + namespace common\models; + + use common\modules\language\behaviors\LanguageBehavior; + use Yii; + use yii\db\ActiveQuery; + use yii\web\Request; /** - * @inheritdoc - */ - public function rules() - { - return [ - [['status'], 'integer'], - [['url'], 'string', 'max' => 255], - ]; - } - - /** - * @inheritdoc + * This is the model class for table "banner". + * @property integer $banner_id + * @property string $url + * @property integer $status + * * From language behavior * + * @property BannerLang $lang + * @property BannerLang[] $langs + * @property BannerLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @property BannerLang[] $model_langs + * @property bool $transactionStatus + * @method string getOwnerKey() + * @method void setOwnerKey( string $value ) + * @method string getLangKey() + * @method void setLangKey( string $value ) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method BannerLang[] generateLangs() + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() + * * End language behavior * */ - public function attributeLabels() + class Banner extends \yii\db\ActiveRecord { - return [ - 'banner_id' => Yii::t('app', 'banner_id'), - 'url' => Yii::t('app', 'url'), - 'status' => Yii::t('app', 'status'), - ]; + + /** + * @inheritdoc + */ + public static function tableName() + { + return 'banner'; + } + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'status' ], + 'integer', + ], + [ + [ 'url' ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'banner_id' => Yii::t('app', 'banner_id'), + 'url' => Yii::t('app', 'url'), + 'status' => Yii::t('app', 'status'), + ]; + } } -} diff --git a/common/models/Bg.php b/common/models/Bg.php index 6ee2a00..e95532f 100755 --- a/common/models/Bg.php +++ b/common/models/Bg.php @@ -10,12 +10,16 @@ /** * Class Bg + * @property int $id + * @todo Write docs * * From language behavior * * @property BgLang $lang * @property BgLang[] $langs * @property BgLang $object_lang * @property string $ownerKey * @property string $langKey + * @property BgLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -23,12 +27,13 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method BgLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ - class Bg extends \yii\db\ActiveRecord + class Bg extends ActiveRecord { public static function tableName() diff --git a/common/models/Delivery.php b/common/models/Delivery.php index b99b63e..dbc452c 100755 --- a/common/models/Delivery.php +++ b/common/models/Delivery.php @@ -10,24 +10,27 @@ /** * Class Delivery * * From language behavior * - * @property OrdersDeliveryLang $lang - * @property OrdersDeliveryLang[] $langs - * @property OrdersDeliveryLang $object_lang - * @property string $ownerKey - * @property string $langKey + * @property OrdersDeliveryLang $lang + * @property OrdersDeliveryLang[] $langs + * @property OrdersDeliveryLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @property OrdersDeliveryLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() - * @method void setOwnerKey( string $value ) + * @method void setOwnerKey(string $value) * @method string getLangKey() - * @method void setLangKey( string $value ) + * @method void setLangKey(string $value) * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method OrdersDeliveryLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs(Request $request) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ - class Delivery extends \yii\db\ActiveRecord + class Delivery extends ActiveRecord { public function behaviors() diff --git a/common/models/Event.php b/common/models/Event.php index 7e39a8a..210218b 100755 --- a/common/models/Event.php +++ b/common/models/Event.php @@ -1,115 +1,126 @@ 'common\behaviors\ShowImage', - ], - 'language' => [ - 'class' => LanguageBehavior::className(), - ], - [ - 'class' => SaveImgBehavior::className(), - 'fields' => [ + + /** + * @inheritdoc + */ + public static function tableName() + { + return 'event'; + } + + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + TimestampBehavior::className(), + [ + 'class' => 'common\behaviors\ShowImage', + ], + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + [ + 'class' => SaveImgBehavior::className(), + 'fields' => [ + [ + 'name' => 'image', + 'directory' => 'event', + ], + ], + ], + ]; + } + + public function beforeSave($insert) + { + if(parent::beforeSave($insert)) { + $this->end_at = strtotime($this->end_at); + return true; + } else { + return false; + } + } + + public function afterFind() + { + $this->end_at = date("Y-m-d", $this->end_at); + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ [ - 'name' => 'image', - 'directory' => 'event', + 'created_at', + 'updated_at', ], + 'integer', ], - ], - ]; - } - - - public function beforeSave($insert) - { - if (parent::beforeSave($insert)) { - $this->end_at = strtotime($this->end_at); - return true; - } else { - return false; + [ + [ 'end_at' ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'event_id' => Yii::t('app', 'event_id'), + 'image' => Yii::t('app', 'image'), + 'created_at' => Yii::t('app', 'created_at'), + 'updated_at' => Yii::t('app', 'updated_at'), + 'end_at' => Yii::t('app', 'end_at'), + ]; } } - - public function afterFind(){ - $this->end_at = date("Y-m-d", $this->end_at); - } - - - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['created_at', 'updated_at' ], 'integer'], - [['end_at'], 'string', 'max' => 255], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'event_id' => Yii::t('app', 'event_id'), - 'image' => Yii::t('app', 'image'), - 'created_at' => Yii::t('app', 'created_at'), - 'updated_at' => Yii::t('app', 'updated_at'), - 'end_at' => Yii::t('app', 'end_at'), - ]; - } -} diff --git a/common/models/Page.php b/common/models/Page.php index 3e8c5f9..55925aa 100755 --- a/common/models/Page.php +++ b/common/models/Page.php @@ -17,6 +17,8 @@ * @property PageLang $object_lang * @property string $ownerKey * @property string $langKey + * @property PageLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -24,9 +26,10 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method PageLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ class Page extends ActiveRecord diff --git a/common/models/ProductSpec.php b/common/models/ProductSpec.php index 30b662a..d0e4ec6 100755 --- a/common/models/ProductSpec.php +++ b/common/models/ProductSpec.php @@ -11,31 +11,33 @@ /** * This is the model class for table "product_spec". - * @property integer $product_spec_id - * @property integer $product_id - * @property string $tech_spec_link - * @property string $tech_char_link - * @property Product $product - * + * @property integer $product_spec_id + * @property integer $product_id + * @property string $tech_spec_link + * @property string $tech_char_link + * @property Product $product * * From language behavior * - * @property ProductSpecLang $lang - * @property ProductSpecLang[] $langs - * @property ProductSpecLang $object_lang - * @property string $ownerKey - * @property string $langKey + * @property ProductSpecLang $lang + * @property ProductSpecLang[] $langs + * @property ProductSpecLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @property ProductSpecLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() - * @method void setOwnerKey(string $value) + * @method void setOwnerKey( string $value ) * @method string getLangKey() - * @method void setLangKey(string $value) + * @method void setLangKey( string $value ) * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method ProductSpecLang[] generateLangs() - * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) - * @method bool linkLangs(ActiveRecord[] $model_langs) - * @method bool saveLangs(ActiveRecord[] $model_langs) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ - class ProductSpec extends \yii\db\ActiveRecord + class ProductSpec extends ActiveRecord { /** @@ -64,7 +66,7 @@ ], ]; } - + /** * @inheritdoc */ @@ -100,19 +102,19 @@ public function upload() { $storage = \Yii::getAlias('@storage'); - $product_dir = $storage.'/product_spec/'.$this->product_id; + $product_dir = $storage . '/product_spec/' . $this->product_id; if(!is_dir($product_dir)) { mkdir($product_dir); } if($this->validate()) { - if(!empty($this->techSpecFile)) { - $path = $product_dir.'/'.$this->techSpecFile->baseName.'.'.$this->techSpecFile->extension; - $this->tech_spec_link = $this->techSpecFile->baseName.'.'.$this->techSpecFile->extension; + if(!empty( $this->techSpecFile )) { + $path = $product_dir . '/' . $this->techSpecFile->baseName . '.' . $this->techSpecFile->extension; + $this->tech_spec_link = $this->techSpecFile->baseName . '.' . $this->techSpecFile->extension; $this->techSpecFile->saveAs($path); } - if(!empty($this->techCharFile)) { - $path = $product_dir.'/'.$this->techCharFile->baseName.'.'.$this->techCharFile->extension; - $this->tech_char_link = $this->techCharFile->baseName.'.'.$this->techCharFile->extension; + if(!empty( $this->techCharFile )) { + $path = $product_dir . '/' . $this->techCharFile->baseName . '.' . $this->techCharFile->extension; + $this->tech_char_link = $this->techCharFile->baseName . '.' . $this->techCharFile->extension; $this->techCharFile->saveAs($path); } return true; @@ -129,17 +131,19 @@ return $this->hasOne(Product::className(), [ 'product_id' => 'product_id' ]); } - public function getTechSpecUrl() { - if(!empty($this->tech_spec_link)) { - return '/storage/product_spec/'.$this->product_id.'/'.$this->tech_spec_link; + public function getTechSpecUrl() + { + if(!empty( $this->tech_spec_link )) { + return '/storage/product_spec/' . $this->product_id . '/' . $this->tech_spec_link; } else { return false; } } - - public function getTechCharUrl() { - if(!empty($this->tech_char_link)) { - return '/storage/product_spec/'.$this->product_id.'/'.$this->tech_char_link; + + public function getTechCharUrl() + { + if(!empty( $this->tech_char_link )) { + return '/storage/product_spec/' . $this->product_id . '/' . $this->tech_char_link; } else { return false; } diff --git a/common/models/Project.php b/common/models/Project.php index 97386cc..fc63891 100755 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -10,6 +10,9 @@ /** * This is the model class for table "project". + * + * @todo Refactor + * * @property integer $project_id * @property integer $date_add * @property ProjectImage[] $images @@ -23,6 +26,8 @@ * @property ProjectLang $object_lang * @property string $ownerKey * @property string $langKey + * @property ProjectLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -30,12 +35,13 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method ProjectLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ - class Project extends \yii\db\ActiveRecord + class Project extends ActiveRecord { public $imagesUpload = []; diff --git a/common/models/Seo.php b/common/models/Seo.php index 0136cfa..ccaef7c 100755 --- a/common/models/Seo.php +++ b/common/models/Seo.php @@ -1,75 +1,84 @@ [ - 'class' => LanguageBehavior::className(), - ], - ]; - } + + namespace common\models; + + use common\modules\language\behaviors\LanguageBehavior; + use Yii; + use yii\db\ActiveQuery; + use yii\db\ActiveRecord; + use yii\web\Request; /** - * @inheritdoc - */ - public function rules() - { - return [ - [['url'], 'required'], - [['url'], 'string', 'max' => 255], - ]; - } - - /** - * @inheritdoc + * This is the model class for table "seo". + * @property integer $seo_id + * @property string $url + * * From language behavior * + * @property SeoLang $lang + * @property SeoLang[] $langs + * @property SeoLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @property SeoLang[] $model_langs + * @property bool $transactionStatus + * @method string getOwnerKey() + * @method void setOwnerKey( string $value ) + * @method string getLangKey() + * @method void setLangKey( string $value ) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method SeoLang[] generateLangs() + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() + * * End language behavior * */ - public function attributeLabels() + class Seo extends ActiveRecord { - return [ - 'seo_id' => Yii::t('app', 'seo_id'), - 'url' => Yii::t('app', 'url'), - ]; + + /** + * @inheritdoc + */ + public static function tableName() + { + return 'seo'; + } + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'url' ], + 'required', + ], + [ + [ 'url' ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_id' => Yii::t('app', 'seo_id'), + 'url' => Yii::t('app', 'url'), + ]; + } } -} diff --git a/common/models/SeoCategory.php b/common/models/SeoCategory.php index 2e19821..6324192 100755 --- a/common/models/SeoCategory.php +++ b/common/models/SeoCategory.php @@ -1,87 +1,95 @@ [ - 'class' => LanguageBehavior::className(), - ], - ]; - } + namespace common\models; + + use common\modules\language\behaviors\LanguageBehavior; + use Yii; + use yii\db\ActiveQuery; + use yii\db\ActiveRecord; + use yii\web\Request; /** - * @inheritdoc - */ - public function rules() - { - return [ - [['status'], 'integer'], - [['controller'], 'string', 'max' => 100], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'seo_category_id' => Yii::t('app', 'seo_category_id'), - 'controller' => Yii::t('app', 'controller'), - 'status' => Yii::t('app', 'status'), - ]; - } - - /** - * @return \yii\db\ActiveQuery + * This is the model class for table "seo_category". + * @property integer $seo_category_id + * @property string $controller + * @property integer $status + * * From language behavior * + * @property SeoCategoryLang $lang + * @property SeoCategoryLang[] $langs + * @property SeoCategoryLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @property SeoCategoryLang[] $model_langs + * @property bool $transactionStatus + * @method string getOwnerKey() + * @method void setOwnerKey( string $value ) + * @method string getLangKey() + * @method void setLangKey( string $value ) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method SeoCategoryLang[] generateLangs() + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() + * * End language behavior * + * @property SeoDynamic[] $seoDynamics */ - public function getSeoDynamics() + class SeoCategory extends ActiveRecord { - return $this->hasMany(SeoDynamic::className(), ['seo_category_id' => 'seo_category_id']); + + /** + * @inheritdoc + */ + public static function tableName() + { + return 'seo_category'; + } + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'status' ], + 'integer', + ], + [ + [ 'controller' ], + 'string', + 'max' => 100, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'seo_category_id' => Yii::t('app', 'seo_category_id'), + 'controller' => Yii::t('app', 'controller'), + 'status' => Yii::t('app', 'status'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSeoDynamics() + { + return $this->hasMany(SeoDynamic::className(), [ 'seo_category_id' => 'seo_category_id' ]); + } } -} diff --git a/common/models/SeoDynamic.php b/common/models/SeoDynamic.php index 0757fa7..a985f24 100755 --- a/common/models/SeoDynamic.php +++ b/common/models/SeoDynamic.php @@ -22,6 +22,8 @@ * @property SeoDynamicLang $object_lang * @property string $ownerKey * @property string $langKey + * @property SeoDynamicLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -29,13 +31,14 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method SeoDynamicLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * * @property SeoCategory $seoCategory */ - class SeoDynamic extends \yii\db\ActiveRecord + class SeoDynamic extends ActiveRecord { /** diff --git a/common/models/Service.php b/common/models/Service.php index cdae8e3..051f201 100755 --- a/common/models/Service.php +++ b/common/models/Service.php @@ -22,6 +22,8 @@ * @property ServiceLang $object_lang * @property string $ownerKey * @property string $langKey + * @property ServiceLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -29,12 +31,13 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method ServiceLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ - class Service extends \yii\db\ActiveRecord + class Service extends ActiveRecord { /** diff --git a/common/models/SliderImage.php b/common/models/SliderImage.php index 95ef598..9c7a541 100755 --- a/common/models/SliderImage.php +++ b/common/models/SliderImage.php @@ -25,6 +25,8 @@ * @property SliderImageLang $object_lang * @property string $ownerKey * @property string $langKey + * @property SliderImageLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -32,17 +34,13 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method SliderImageLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) - * * End language behavior * - * * From transaction behavior * - * @property SliderImageLang[] $model_langs - * @property bool $transactionStatus + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() * @method bool getTransactionStatus() - * * End transaction behavior * + * * End language behavior * */ - class SliderImage extends \yii\db\ActiveRecord + class SliderImage extends ActiveRecord { /** diff --git a/common/modules/language/behaviors/LanguageBehavior.php b/common/modules/language/behaviors/LanguageBehavior.php index ec955c0..ea5d6a0 100755 --- a/common/modules/language/behaviors/LanguageBehavior.php +++ b/common/modules/language/behaviors/LanguageBehavior.php @@ -2,7 +2,6 @@ namespace common\modules\language\behaviors; use common\modules\language\models\Language; - use common\modules\product\models\Product; use yii\base\Behavior; use yii\base\InvalidConfigException; use yii\db\ActiveQuery; @@ -252,6 +251,9 @@ $owner = $this->owner; $db = $owner::getDb(); $this->_transaction = $db->beginTransaction(); + if($owner->hasAttribute('remote_id') && empty($owner->remote_id)) { + $owner->remote_id = strval(microtime(true)*10000); + } } public function afterSave($event) @@ -272,9 +274,6 @@ $this->_transaction->commit(); $this->_transaction_status = true; } - if($owner->hasAttribute('remote_id') && empty($owner->remote_id)) { - $owner->remote_id = (int) $owner->primaryKey(); - } } /** diff --git a/common/modules/language/readme.txt b/common/modules/language/readme.txt index e25929f..e678750 100755 --- a/common/modules/language/readme.txt +++ b/common/modules/language/readme.txt @@ -66,9 +66,9 @@ public function behaviors() { * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method {TableLang}[] generateLangs() - * @method void loadLangs(Request $request, ActiveRecord[] $model_langs) - * @method bool linkLangs(ActiveRecord[] $model_langs) - * @method bool saveLangs(ActiveRecord[] $model_langs) + * @method void loadLangs(Request $request) + * @method bool linkLangs() + * @method bool saveLangs() * @method bool getTransactionStatus() * * End language behavior * 3.2. Убрать language behavior с наследуемых таблиц от {Table} ({TableSearch}...) diff --git a/common/modules/product/controllers/ManageController.php b/common/modules/product/controllers/ManageController.php index 39dbef5..630be1e 100755 --- a/common/modules/product/controllers/ManageController.php +++ b/common/modules/product/controllers/ManageController.php @@ -101,7 +101,7 @@ $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); $model->certificateUpload = UploadedFile::getInstances($model, 'certificateUpload'); - if($model->save()) { + if($model->save() && $model->transactionStatus) { if(!empty( $model->imagesUpload ) && ( ( $images = $model->imagesUpload() ) !== false )) { foreach($images as $image) { @@ -127,30 +127,14 @@ $product_spec->product_id = $model->product_id; $product_spec->techSpecFile = UploadedFile::getInstance($product_spec, 'techSpecFile'); $product_spec->techCharFile = UploadedFile::getInstance($product_spec, 'techCharFile'); - if($product_spec->upload() && $model->linkLangs() && $model->saveLangs()) { - $product_spec->save(false); - if($product_spec->linkLangs() && $product_spec->saveLangs()) { + if($product_spec->upload()) { + if($product_spec->save(false) && $product_spec->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->product_id, ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->product_id, - ]); } } - } elseif($model->linkLangs() && $model->saveLangs()) { - return $this->redirect([ - 'view', - 'id' => $model->product_id, - ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->product_id, - ]); } } } @@ -173,7 +157,7 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); + $model->generateLangs(); if(!empty( $model->productSpec )) { $product_spec = $model->productSpec; } else { @@ -181,12 +165,12 @@ 'product_id' => $model->product_id, ]); } - $product_spec_langs = $product_spec->generateLangs(); + $product_spec->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); + $model->loadLangs(\Yii::$app->request); $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); $model->certificateUpload = UploadedFile::getInstances($model, 'certificateUpload'); - if($model->save()) { + if($model->save() && $model->transactionStatus) { if(!empty( $model->imagesUpload ) && ( ( $images = $model->imagesUpload() ) !== false )) { foreach($images as $image) { $imageModel = new ProductImage(); @@ -195,7 +179,6 @@ $imageModel->save(); } } - if(!empty( $model->certificateUpload ) && ( ( $certificates = $model->certificateUpload() ) !== false )) { foreach($certificates as $certificate) { $certificateModel = new ProductCertificate([ @@ -205,35 +188,28 @@ $certificateModel->save(false); } } - if($product_spec->load(Yii::$app->request->post())) { - $product_spec->loadLangs(\Yii::$app->request, $product_spec_langs); + $product_spec->loadLangs(\Yii::$app->request); $product_spec->techSpecFile = UploadedFile::getInstance($product_spec, 'techSpecFile'); $product_spec->techCharFile = UploadedFile::getInstance($product_spec, 'techCharFile'); - if($product_spec->upload() && $model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - $product_spec->save(false); - if($product_spec->linkLangs($product_spec_langs) && $product_spec->saveLangs($product_spec_langs)) { + if($product_spec->upload()) { + if($product_spec->save(false) && $product_spec->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->product_id, ]); } } - } elseif($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { - return $this->redirect([ - 'view', - 'id' => $model->product_id, - ]); } } } $groups = $model->getTaxGroupsByLevel(0); return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, 'groups' => $groups, 'product_spec' => $product_spec, - 'product_spec_langs' => $product_spec_langs, + 'product_spec_langs' => $product_spec->model_langs, ]); } diff --git a/common/modules/product/controllers/ProductUnitController.php b/common/modules/product/controllers/ProductUnitController.php index 16b9a5f..960b618 100755 --- a/common/modules/product/controllers/ProductUnitController.php +++ b/common/modules/product/controllers/ProductUnitController.php @@ -67,27 +67,20 @@ public function actionCreate() { $model = new ProductUnit(); - $model_langs = $model->generateLangs(); - - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->product_unit_id, ]); - } else { - return $this->redirect([ - 'update', - 'id' => $model->product_unit_id, - ]); } - } else { - return $this->render('create', [ - 'model' => $model, - 'model_langs' => $model_langs, - ]); } + return $this->render('create', [ + 'model' => $model, + 'model_langs' => $model->model_langs, + ]); } /** @@ -101,11 +94,10 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); - - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + $model->generateLangs(); + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->product_unit_id, @@ -114,7 +106,7 @@ } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } diff --git a/common/modules/product/controllers/VariantController.php b/common/modules/product/controllers/VariantController.php index eda1231..ccced1c 100755 --- a/common/modules/product/controllers/VariantController.php +++ b/common/modules/product/controllers/VariantController.php @@ -80,19 +80,15 @@ { $model = new ProductVariant(); $model->product_id = $product_id; - $model_langs = $model->generateLangs(); + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); + $model->loadLangs(\Yii::$app->request); $model->imagesUpload = UploadedFile::getInstances($model, 'imagesUpload'); - $model->validate(); - - if($model->save()) { - + if($model->save() && $model->transactionStatus) { if(( $image = UploadedFile::getInstance($model, 'image') )) { $imageModel = ProductImage::find() ->where([ 'product_variant_id' => $model->product_variant_id ]) ->one(); - if($imageModel instanceof ProductImage) { $imageModel->product_id = $model->product_id; $imageModel->product_variant_id = $model->product_variant_id; @@ -105,20 +101,14 @@ $imageModel->image = $image->name; $imageModel->save(); } - $imgDir = Yii::getAlias('@storage/products/'); - if(!is_dir($imgDir)) { mkdir($imgDir, 0755, true); } - $image->saveAs(Yii::getAlias('@storage/products/' . $image->name)); } - $ProductStocks = Yii::$app->request->post('ProductStock'); - $total_quantity = 0; - if(!empty( $ProductStocks ) && is_array($ProductStocks)) { $model->unlinkAll('stocks', true); $sorted_array = []; @@ -164,26 +154,18 @@ } $model->stock = $total_quantity; - $model->save(); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'index', 'product_id' => $product_id, ]); - } else { - return $this->redirect([ - 'update', - 'product_id' => $product_id, - 'id' => $model->product_variant_id, - ]); } } } $groups = $model->getTaxGroupsByLevel(1); - return $this->render('create', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, 'groups' => $groups, 'stocks' => [ new ProductStock() ], ]); @@ -201,16 +183,14 @@ public function actionUpdate($product_id, $id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->save()) { - + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { if(( $image = UploadedFile::getInstance($model, 'image') )) { $imageModel = ProductImage::find() ->where([ 'product_variant_id' => $model->product_variant_id ]) ->one(); - if($imageModel instanceof ProductImage) { $imageModel->product_id = $model->product_id; $imageModel->product_variant_id = $model->product_variant_id; @@ -223,20 +203,14 @@ $imageModel->image = $image->name; $imageModel->save(); } - $imgDir = Yii::getAlias('@storage/products/'); - if(!is_dir($imgDir)) { mkdir($imgDir, 0755, true); } - $image->saveAs(Yii::getAlias('@storage/products/' . $image->name)); } - $ProductStocks = Yii::$app->request->post('ProductStock'); - $total_quantity = 0; - if(!empty( $ProductStocks ) && is_array($ProductStocks)) { $model->unlinkAll('stocks', true); $sorted_array = []; @@ -280,9 +254,8 @@ } else { $model->unlinkAll('stocks', true); } - $model->stock = $total_quantity; - if($model->save() && $model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'index', 'product_id' => $product_id, @@ -291,20 +264,19 @@ } } $groups = $model->getTaxGroupsByLevel(1); - return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, 'groups' => $groups, 'stocks' => ( !empty( $model->variantStocks ) ) ? $model->variantStocks : [ new ProductStock ], ]); - } /** * Deletes an existing ProductVariant model. * If deletion is successful, the browser will be redirected to the 'index' page. * + * @param integer $product_id * @param integer $id * * @return mixed diff --git a/common/modules/product/helpers/ProductHelper.php b/common/modules/product/helpers/ProductHelper.php index f12b200..b3bd499 100755 --- a/common/modules/product/helpers/ProductHelper.php +++ b/common/modules/product/helpers/ProductHelper.php @@ -20,7 +20,7 @@ public static function getCategories() { return Category::find() - ->getTree(); + ->getTree(null, 'lang'); } public static function getBrands() diff --git a/common/modules/product/models/Brand.php b/common/modules/product/models/Brand.php index 37a8b16..4d61bcd 100755 --- a/common/modules/product/models/Brand.php +++ b/common/modules/product/models/Brand.php @@ -21,6 +21,8 @@ * @property BrandLang $object_lang * @property string $ownerKey * @property string $langKey + * @property BrandLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -28,12 +30,13 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method BrandLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ - class Brand extends \yii\db\ActiveRecord + class Brand extends ActiveRecord { public $_items_count = 0; @@ -83,8 +86,8 @@ public function attributeLabels() { return [ - 'brand_id' => Yii::t('product', 'Brand ID'), - 'image' => Yii::t('product', 'Image'), + 'brand_id' => Yii::t('product', 'Brand ID'), + 'image' => Yii::t('product', 'Image'), ]; } diff --git a/common/modules/product/models/Category.php b/common/modules/product/models/Category.php index e278bbd..a01d9fb 100755 --- a/common/modules/product/models/Category.php +++ b/common/modules/product/models/Category.php @@ -4,7 +4,6 @@ use common\behaviors\SaveImgBehavior; use common\components\artboxtree\ArtboxTreeBehavior; - use common\components\artboxtree\ArtboxTreeHelper; use common\modules\language\behaviors\LanguageBehavior; use common\modules\rubrication\models\TaxGroup; use Yii; @@ -16,7 +15,7 @@ /** * This is the model class for table "category". * @property integer $category_id - * @property string $remote_id + * @property integer $remote_id * @property integer $parent_id * @property string $path * @property integer $depth @@ -28,6 +27,8 @@ * @property CategoryLang $object_lang * @property string $ownerKey * @property string $langKey + * @property CategoryLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -35,15 +36,16 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method CategoryLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * * @property Product[] $products * @property ProductUnit $productUnit * @property ProductCategory[] $productCategories */ - class Category extends \yii\db\ActiveRecord + class Category extends ActiveRecord { public function behaviors() @@ -160,18 +162,6 @@ ->andWhere([ 'level' => $level ]); } - public function getRemote_category() - { - return ArtboxTreeHelper::getArrayField($this->remote_id); - } - - public function setRemote_category($value) - { - if(!empty( $value ) && is_array($value)) { - $this->remote_id = ArtboxTreeHelper::setArrayField($value, false); - } - } - public function beforeSave($insert) { if(parent::beforeSave($insert)) { @@ -227,14 +217,14 @@ 0, ]); $query3 = ( new Query() )->select([ - 'tax_option.*', - 'tax_group.*', - 'tax_option.alias as option_alias', - 'tax_group.alias as group_alias', - 'tax_option.value as value', - 'tax_option.sort AS tax_option_sort', - 'tax_group.sort AS tax_group_sort', - ]) + 'tax_option.*', + 'tax_group.*', + 'tax_option.alias as option_alias', + 'tax_group.alias as group_alias', + 'tax_option.value as value', + 'tax_option.sort AS tax_option_sort', + 'tax_group.sort AS tax_group_sort', + ]) ->from([ 'tax_option' ]) ->where([ 'tax_option.tax_option_id' => $query1->union($query2) ]) ->innerJoin('tax_group', 'tax_group.tax_group_id = tax_option.tax_group_id') @@ -257,12 +247,19 @@ ) ) AND tax_group.is_menu = TRUE AND tax_group_to_category.category_id = :category_id', [ - ':category_id' => $this->category_id, - - ]); + ':category_id' => $this->category_id, + + ]); return $command->queryAll(); } + /** + * @todo Write doc + * + * @param $value + * + * @return mixed + */ public function setTaxGroup($value) { return $this->tax_group = $value; diff --git a/common/modules/product/models/CategoryLang.php b/common/modules/product/models/CategoryLang.php index 36d8a46..070f848 100755 --- a/common/modules/product/models/CategoryLang.php +++ b/common/modules/product/models/CategoryLang.php @@ -57,7 +57,7 @@ class CategoryLang extends \yii\db\ActiveRecord { return [ [['name'], 'required'], - [['seo_text'], 'string'], + [['seo_text', 'alias'], 'string'], [['name', 'meta_title', 'meta_robots', 'meta_desc', 'h1'], 'string', 'max' => 255], [['category_id', 'language_id'], 'unique', 'targetAttribute' => ['category_id', 'language_id'], 'message' => 'The combination of Category ID and Language ID has already been taken.'], [['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => Category::className(), 'targetAttribute' => ['category_id' => 'category_id']], diff --git a/common/modules/product/models/CategorySearch.php b/common/modules/product/models/CategorySearch.php index c307786..4355ead 100755 --- a/common/modules/product/models/CategorySearch.php +++ b/common/modules/product/models/CategorySearch.php @@ -71,14 +71,4 @@ class CategorySearch extends Category return $dataProvider; } - - public static function findByRemoteID($id) { - /** @var CategoryQuery $query */ - $query = Category::find() - ->andFilterWhere(['@>', 'remote_id', ArtboxTreeHelper::setArrayField($id)]); - if (($model = $query->one()) !== null) { - return $model; - } - return null; - } } diff --git a/common/modules/product/models/Export.php b/common/modules/product/models/Export.php index 04a3332..d0b5dad 100755 --- a/common/modules/product/models/Export.php +++ b/common/modules/product/models/Export.php @@ -3,6 +3,7 @@ namespace common\modules\product\models; use common\modules\language\models\Language; + use common\modules\rubrication\models\TaxOption; use yii\base\Model; class Export extends Model @@ -44,7 +45,10 @@ $language = Language::findOne(\Yii::$app->session->get('export_lang', Language::getDefaultLanguage()->language_id)); Language::setCurrent($language->url); - + + /** + * @var Product[] $products + */ $products = Product::find() ->with('variantsWithFilters', 'brand.lang', 'categories.lang', 'filters') ->joinWith('lang', true, 'INNER JOIN') @@ -59,23 +63,26 @@ $filterString = $this->convertFilterToString($product->filters); foreach($product->variantsWithFilters as $variant) { + /** + * @var ProductVariant $variant + */ $color = $variant->lang->name; - $mods[] = $variant->sku . '=' . $this->convertFilterToString($variant->filters) . '=' . $color . '=' . ( ( !empty( $variant->image ) ) ? $variant->image->image : '' ) . '=' . $variant->stock; + $mods[] = $variant->sku.$this->generateID($variant->remote_id) . '=' . $this->convertFilterToString($variant->filters) . '=' . $color . '=' . ( ( !empty( $variant->image ) ) ? $variant->image->image : '' ) . '=' . $variant->stock; } $fotos = []; $categories = []; foreach($product->categories as $value) { - $categories[] = $value->lang->name; + $categories[] = $value->lang->name.$this->generateID($value->remote_id); } $categories = implode(',', $categories); $list = [ $categories, - ( ( !empty( $product->brand ) ) ? $product->brand->lang->name : '' ), - $product->lang->name, + ( ( !empty( $product->brand ) ) ? $product->brand->lang->name.$this->generateID($product->brand->remote_id) : '' ), + $product->lang->name.$this->generateID($product->remote_id), '', ( ( !empty( $product->lang->description ) ) ? $product->lang->description : '' ), $filterString, @@ -121,8 +128,11 @@ public function convertFilterToString($filters) { $fittersArray = []; + /** + * @var TaxOption[] $filters + */ foreach($filters as $filter) { - $fittersArray[ $filter->taxGroup->alias ][] = $filter->lang->value; + $fittersArray[ $filter->taxGroup->lang->name.$this->generateID($filter->taxGroup->remote_id) ][] = $filter->lang->value.$this->generateID($filter->remote_id); } $filterString = []; @@ -132,4 +142,8 @@ } return implode('*', $filterString); } + + private function generateID(string $id):string { + return sprintf('(#%s#)', $id); + } } \ No newline at end of file diff --git a/common/modules/product/models/Import.php b/common/modules/product/models/Import.php index e8a757b..d1f6c55 100755 --- a/common/modules/product/models/Import.php +++ b/common/modules/product/models/Import.php @@ -352,10 +352,11 @@ if(!empty ( $data[ $i ] )) { $mod_arr = explode('=', $data[ $i ]); $mod_art = $mod_arr[ 0 ]; + $mod_art_parsed = $this->parseName($mod_art); $variant_filters = explode('*', $mod_arr[ 1 ]); $mod_name = $mod_arr[ 2 ]; if(empty( $mod_name )) { - $mod_name = $mod_art; + $mod_name = $mod_art_parsed['name']; } $mod_image = $mod_arr[ 3 ]; $mod_stock = isset( $mod_arr[ 4 ] ) ? $mod_arr[ 4 ] : 1; @@ -367,12 +368,15 @@ */ if(( $_productVariant = ProductVariant::find() ->joinWith('lang') - ->andFilterWhere([ 'sku' => $mod_art ]) + ->andFilterWhere([ 'remote_id' => $mod_art_parsed['remote_id'] ]) ->andFilterWhere([ 'product_variant.product_id' => $product_id ]) ->one() ) === NULL ) { $_productVariant = new ProductVariant(); $_productVariant->product_id = $product_id; + if(!empty($mod_art_parsed['remote_id'])) { + $_productVariant->remote_id = $mod_art_parsed['remote_id']; + } $_productVariant->generateLangs(); $product_variant_langs = $_productVariant->model_langs; foreach($product_variant_langs as $product_variant_lang) { @@ -387,7 +391,7 @@ } } $_productVariant->product_unit_id = 1; - $_productVariant->sku = $mod_art; + $_productVariant->sku = $mod_art_parsed['name']; $_productVariant->price = $mod_cost; $_productVariant->price_old = $mod_old_cost; $_productVariant->stock = $mod_stock; diff --git a/common/modules/product/models/Product.php b/common/modules/product/models/Product.php index 2dc3255..f764778 100755 --- a/common/modules/product/models/Product.php +++ b/common/modules/product/models/Product.php @@ -39,21 +39,24 @@ * @property ProductSpec $productSpec * @property ProductCertificate[] $productCertificates * * From language behavior * - * @property ProductLang $lang - * @property ProductLang[] $langs - * @property ProductLang $object_lang - * @property string $ownerKey - * @property string $langKey + * @property ProductLang $lang + * @property ProductLang[] $langs + * @property ProductLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @property ProductLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() - * @method void setOwnerKey( string $value ) + * @method void setOwnerKey(string $value) * @method string getLangKey() - * @method void setLangKey( string $value ) + * @method void setLangKey(string $value) * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method ProductLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs(Request $request) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ class Product extends \yii\db\ActiveRecord diff --git a/common/modules/product/models/ProductSearch.php b/common/modules/product/models/ProductSearch.php index a3fc817..201010d 100755 --- a/common/modules/product/models/ProductSearch.php +++ b/common/modules/product/models/ProductSearch.php @@ -110,14 +110,4 @@ class ProductSearch extends Product return $dataProvider; } - - public static function findByRemoteID($id) { - /** @var CategoryQuery $query */ - $query = Product::find() - ->andFilterWhere(['remote_id' => $id]); - if (($model = $query->one()) !== null) { - return $model; - } - return null; - } } diff --git a/common/modules/product/models/ProductUnit.php b/common/modules/product/models/ProductUnit.php index 38bd6d1..9c35960 100755 --- a/common/modules/product/models/ProductUnit.php +++ b/common/modules/product/models/ProductUnit.php @@ -1,93 +1,97 @@ [ - 'class' => LanguageBehavior::className(), - ], - ]; - } + namespace common\modules\product\models; + + use common\modules\language\behaviors\LanguageBehavior; + use Yii; + use yii\db\ActiveQuery; + use yii\db\ActiveRecord; + use yii\web\Request; /** - * @inheritdoc - */ - public function rules() - { - return [ - [['is_default'], 'boolean'], - ]; - } - - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'product_unit_id' => Yii::t('product', 'Product Unit ID'), - 'is_default' => Yii::t('product', 'Is Default'), - ]; - } - - /** - * @return \yii\db\ActiveQuery - */ - public function getCategories() - { - return $this->hasMany(Category::className(), ['product_unit_id' => 'product_unit_id']); - } - - /** - * @return \yii\db\ActiveQuery + * This is the model class for table "product_unit". + * @property integer $product_unit_id + * @property boolean $is_default + * @property Category[] $categories + * @property ProductVariant[] $productVariants + * * From language behavior * + * @property ProductUnitLang $lang + * @property ProductUnitLang[] $langs + * @property ProductUnitLang $object_lang + * @property string $ownerKey + * @property string $langKey + * @property ProductUnitLang[] $model_langs + * @property bool $transactionStatus + * @method string getOwnerKey() + * @method void setOwnerKey( string $value ) + * @method string getLangKey() + * @method void setLangKey( string $value ) + * @method ActiveQuery getLangs() + * @method ActiveQuery getLang( integer $language_id ) + * @method ProductUnitLang[] generateLangs() + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() + * * End language behavior * */ - public function getProductVariants() + class ProductUnit extends ActiveRecord { - return $this->hasMany(ProductVariant::className(), ['product_unit_id' => 'product_unit_id']); + + /** + * @inheritdoc + */ + public static function tableName() + { + return 'product_unit'; + } + + public function behaviors() + { + return [ + 'language' => [ + 'class' => LanguageBehavior::className(), + ], + ]; + } + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'is_default' ], + 'boolean', + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'product_unit_id' => Yii::t('product', 'Product Unit ID'), + 'is_default' => Yii::t('product', 'Is Default'), + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getCategories() + { + return $this->hasMany(Category::className(), [ 'product_unit_id' => 'product_unit_id' ]); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getProductVariants() + { + return $this->hasMany(ProductVariant::className(), [ 'product_unit_id' => 'product_unit_id' ]); + } } -} diff --git a/common/modules/product/models/ProductVariant.php b/common/modules/product/models/ProductVariant.php index 3b3201b..75fa08e 100755 --- a/common/modules/product/models/ProductVariant.php +++ b/common/modules/product/models/ProductVariant.php @@ -13,9 +13,10 @@ /** * This is the model class for table "product_variant". + * @todo Refactor * @property integer $product_variant_id * @property integer $product_id - * @property string $remote_id + * @property integer $remote_id * @property string $sku * @property double $price * @property double $price_old @@ -32,6 +33,8 @@ * @property ProductVariantLang $object_lang * @property string $ownerKey * @property string $langKey + * @property ProductVariantLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -39,18 +42,21 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method ProductVariantLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ - class ProductVariant extends \yii\db\ActiveRecord + class ProductVariant extends ActiveRecord { public $sum_cost; public $product_name; + private $_options; + /** @var array $_images */ public $imagesUpload = ''; @@ -107,11 +113,6 @@ 'max' => 255, ], [ - [ 'remote_id' ], - 'string', - 'max' => 20, - ], - [ [ 'options', 'imagesUpload', @@ -269,7 +270,7 @@ public function setOptions($values) { - $this->options = $values; + $this->_options = $values; } public function getOptions() @@ -333,29 +334,32 @@ ->where([ 'tax_group_to_category.category_id' => $categories ]) ->where([ 'level' => $level ]); } - + public function afterSave($insert, $changedAttributes) { - - if(!empty($this->_options)){ + parent::afterSave($insert, $changedAttributes); + if(!empty( $this->_options )) { $options = TaxOption::findAll($this->_options); - $this->unlinkAll('options',true); - foreach($options as $option){ + $this->unlinkAll('options', true); + foreach($options as $option) { $this->link('options', $option); } } - - - if (!empty($this->stocks)) { - ProductStock::deleteAll(['product_variant_id' => $this->product_variant_id]); + + if(!empty( $this->stocks )) { + ProductStock::deleteAll([ 'product_variant_id' => $this->product_variant_id ]); $values = []; - foreach ($this->stocks as $id => $quantity) { - $productStock = ProductStock::find()->where(['product_variant_id' => $this->product_variant_id, 'stock_id' => $id])->one(); + foreach($this->stocks as $id => $quantity) { + $productStock = ProductStock::find() + ->where([ + 'product_variant_id' => $this->product_variant_id, + 'stock_id' => $id, + ]) + ->one(); $productStock->quantity = $quantity; $productStock->save(); } } - parent::afterSave($insert, $changedAttributes); } public function imagesUpload() diff --git a/common/modules/product/models/ProductVariantListSearch.php b/common/modules/product/models/ProductVariantListSearch.php index 87590c8..056cacb 100755 --- a/common/modules/product/models/ProductVariantListSearch.php +++ b/common/modules/product/models/ProductVariantListSearch.php @@ -34,7 +34,6 @@ [ [ 'sku', - 'remote_id', ], 'safe', ], @@ -102,12 +101,7 @@ 'like', 'sku', $this->sku, - ]) - ->andFilterWhere([ - 'like', - 'remote_id', - $this->remote_id, - ]); + ]); return $dataProvider; } diff --git a/common/modules/product/models/ProductVariantSearch.php b/common/modules/product/models/ProductVariantSearch.php index 4eb51e0..ca30c24 100755 --- a/common/modules/product/models/ProductVariantSearch.php +++ b/common/modules/product/models/ProductVariantSearch.php @@ -138,14 +138,4 @@ class ProductVariantSearch extends ProductVariant } return NULL; } - - public static function findByRemoteID($id) { - /** @var CategoryQuery $query */ - $query = ProductVariant::find() - ->andFilterWhere(['remote_id' => $id]); - if (($model = $query->one()) !== null) { - return $model; - } - return NULL; - } } diff --git a/common/modules/product/views/manage/_form.php b/common/modules/product/views/manage/_form.php index 4981eca..8f90cb4 100755 --- a/common/modules/product/views/manage/_form.php +++ b/common/modules/product/views/manage/_form.php @@ -4,6 +4,7 @@ use common\models\ProductSpecLang; use common\modules\language\widgets\LanguageForm; use common\modules\product\models\ProductLang; + use common\modules\rubrication\models\TaxGroup; use yii\db\ActiveQuery; use yii\helpers\Html; use yii\widgets\ActiveForm; @@ -41,13 +42,14 @@ field($model, 'brand_id') ->dropDownList(ArrayHelper::map(ProductHelper::getBrands() - ->all(), 'brand_id', 'brand_id'), [ + ->with('lang') + ->all(), 'brand_id', 'lang.name'), [ 'prompt' => Yii::t('product', 'Select brand'), ]) ?> field($model, 'categories') ->widget(Select2::className(), [ - 'data' => ArtboxTreeHelper::treeMap(ProductHelper::getCategories(), 'category_id', 'category_id'), + 'data' => ArtboxTreeHelper::treeMap(ProductHelper::getCategories(), 'category_id', 'lang.name'), 'language' => 'ru', 'options' => [ 'placeholder' => Yii::t('product', 'Select categories'), @@ -110,16 +112,20 @@ ], ]); ?> - - all() as $group) : ?> - field($model, 'options') - ->checkboxList(ArrayHelper::map($group->options, 'tax_option_id', 'tax_option_id'), [ + with('lang')->all() as $group) { + /** + * @var TaxGroup $group + */ + echo $form->field($model, 'options') + ->checkboxList(ArrayHelper::map($group->getOptions()->with('lang')->all(), 'tax_option_id', 'lang.value'), [ 'multiple' => true, 'unselect' => NULL, ]) - ->label($group->tax_group_id); ?> - - + ->label($group->lang->name); + } + } + ?>
diff --git a/common/modules/product/views/variant/_form.php b/common/modules/product/views/variant/_form.php index 065e4f8..68fdcb6 100755 --- a/common/modules/product/views/variant/_form.php +++ b/common/modules/product/views/variant/_form.php @@ -2,6 +2,7 @@ use common\modules\language\widgets\LanguageForm; use common\modules\product\models\ProductStock; + use common\modules\product\models\ProductUnit; use common\modules\product\models\ProductVariant; use common\modules\product\models\ProductVariantLang; use yii\db\ActiveQuery; @@ -145,22 +146,26 @@ $(".dynamicform_wrapper").on("limitReached", function(e, item) { field($model, 'product_unit_id') - ->dropDownList(ArrayHelper::map(\common\modules\product\models\ProductUnit::find() - ->all(), 'product_unit_id', 'product_unit_id'), [ + ->dropDownList(ArrayHelper::map(ProductUnit::find() + ->with('lang') + ->all(), 'product_unit_id', 'lang.name'), [ 'prompt' => Yii::t('product', 'Unit'), ]) ->label(Yii::t('product', 'Unit')) ?> - - all() as $group) : ?> - field($model, 'options') - ->checkboxList(ArrayHelper::map($group->options, 'tax_option_id', 'tax_option_id'), [ - 'multiple' => true, - 'unselect' => NULL, - ]) - ->label($group->tax_group_id); ?> - - + with('lang') + ->all() as $group) { + echo $form->field($model, 'options') + ->checkboxList(ArrayHelper::map($group->getOptions() + ->with('lang') + ->all(), 'tax_option_id', 'lang.value'), [ + 'multiple' => true, + 'unselect' => NULL, + ]) + ->label($group->lang->name); + } + } ?>
isNewRecord ? Yii::t('product', 'Create') : Yii::t('product', 'Update'), [ 'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary' ]) ?> diff --git a/common/modules/rubrication/controllers/TaxGroupController.php b/common/modules/rubrication/controllers/TaxGroupController.php index 0eee7e7..ba84ed2 100755 --- a/common/modules/rubrication/controllers/TaxGroupController.php +++ b/common/modules/rubrication/controllers/TaxGroupController.php @@ -76,12 +76,11 @@ public function actionCreate($level) { $model = new TaxGroup(); - $model_langs = $model->generateLangs(); - + $model->generateLangs(); if($model->load(Yii::$app->request->post()) && $model->validate()) { - $model->loadLangs(\Yii::$app->request, $model_langs); + $model->loadLangs(\Yii::$app->request); $model->level = $level; - if($model->save() && $model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'index', 'level' => $level, @@ -90,7 +89,7 @@ } return $this->render('create', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } @@ -106,11 +105,10 @@ public function actionUpdate($level, $id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); - + $model->generateLangs(); if($model->load(Yii::$app->request->post())) { - $model->loadLangs(\Yii::$app->request, $model_langs); - if($model->save() && $model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'index', 'level' => $level, @@ -119,7 +117,7 @@ } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, ]); } @@ -149,7 +147,6 @@ { TaxOption::find() ->rebuildMP($id); - return $this->redirect([ 'index' ]); } diff --git a/common/modules/rubrication/controllers/TaxOptionController.php b/common/modules/rubrication/controllers/TaxOptionController.php index cf7a3c1..7cd44d4 100755 --- a/common/modules/rubrication/controllers/TaxOptionController.php +++ b/common/modules/rubrication/controllers/TaxOptionController.php @@ -74,24 +74,16 @@ public function actionCreate() { $model = new TaxOption(); - $model_langs = $model->generateLangs(); + $model->generateLangs(); $group = TaxGroup::findOne(Yii::$app->request->queryParams[ 'group' ]); - - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); + if($model->save() && $model->transactionStatus) { return is_null(Yii::$app->request->post('create_and_new')) ? $this->redirect([ 'view', 'id' => $model->tax_option_id, ]) : $this->redirect(array_merge([ 'create' ], Yii::$app->request->queryParams)); - } else { - return $this->redirect([ - 'update', - 'id' => $model->tax_option_id, - ]); } - } $model->tax_group_id = $group->tax_group_id; if(!empty( Yii::$app->request->queryParams[ 'parent' ] )) { @@ -99,7 +91,7 @@ } return $this->render('create', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, 'group' => $group, ]); } @@ -115,15 +107,13 @@ public function actionUpdate($id) { $model = $this->findModel($id); - $model_langs = $model->generateLangs(); + $model->generateLangs(); $group = TaxGroup::findOne($model->tax_group_id); - - if($model->load(Yii::$app->request->post()) && $model->save()) { - $model->loadLangs(\Yii::$app->request, $model_langs); - + if($model->load(Yii::$app->request->post())) { + $model->loadLangs(\Yii::$app->request); TaxOption::find() ->rebuildMP($model->tax_group_id); - if($model->linkLangs($model_langs) && $model->saveLangs($model_langs)) { + if($model->save() && $model->transactionStatus) { return $this->redirect([ 'view', 'id' => $model->tax_option_id, @@ -132,7 +122,7 @@ } return $this->render('update', [ 'model' => $model, - 'model_langs' => $model_langs, + 'model_langs' => $model->model_langs, 'group' => $group, ]); } diff --git a/common/modules/rubrication/models/TaxGroup.php b/common/modules/rubrication/models/TaxGroup.php index e3b6227..f276a0d 100755 --- a/common/modules/rubrication/models/TaxGroup.php +++ b/common/modules/rubrication/models/TaxGroup.php @@ -26,6 +26,8 @@ * @property TaxGroupLang $object_lang * @property string $ownerKey * @property string $langKey + * @property TaxGroupLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -33,12 +35,13 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method TaxGroupLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ - class TaxGroup extends \yii\db\ActiveRecord + class TaxGroup extends ActiveRecord { /** @@ -146,12 +149,14 @@ ->inverseOf('taxGroup'); } - public function getAlias() { + public function getAlias() + { $default_lang = Language::getDefaultLanguage(); /** * @var TaxGroupLang $lang */ - $lang = $this->getLang($default_lang->language_id)->one(); + $lang = $this->getLang($default_lang->language_id) + ->one(); return $lang->alias; } } diff --git a/common/modules/rubrication/models/TaxOption.php b/common/modules/rubrication/models/TaxOption.php index b3e7126..1d4ac15 100755 --- a/common/modules/rubrication/models/TaxOption.php +++ b/common/modules/rubrication/models/TaxOption.php @@ -31,6 +31,8 @@ * @property TaxOptionLang $object_lang * @property string $ownerKey * @property string $langKey + * @property TaxOptionLang[] $model_langs + * @property bool $transactionStatus * @method string getOwnerKey() * @method void setOwnerKey( string $value ) * @method string getLangKey() @@ -38,12 +40,13 @@ * @method ActiveQuery getLangs() * @method ActiveQuery getLang( integer $language_id ) * @method TaxOptionLang[] generateLangs() - * @method void loadLangs( Request $request, ActiveRecord[] $model_langs ) - * @method bool linkLangs( ActiveRecord[] $model_langs ) - * @method bool saveLangs( ActiveRecord[] $model_langs ) + * @method void loadLangs( Request $request ) + * @method bool linkLangs() + * @method bool saveLangs() + * @method bool getTransactionStatus() * * End language behavior * */ - class TaxOption extends \yii\db\ActiveRecord + class TaxOption extends ActiveRecord { public $_items_count; diff --git a/common/modules/rubrication/views/tax-group/_form.php b/common/modules/rubrication/views/tax-group/_form.php index 8801508..b3ac930 100755 --- a/common/modules/rubrication/views/tax-group/_form.php +++ b/common/modules/rubrication/views/tax-group/_form.php @@ -22,7 +22,7 @@ [ 'enctype' => 'multipart/form-data' ] ]); ?> field($model, 'categories') - ->dropDownList(ArtboxTreeHelper::treeMap(ProductHelper::getCategories(), 'category_id', 'category_id'), [ + ->dropDownList(ArtboxTreeHelper::treeMap(ProductHelper::getCategories(), 'category_id', 'lang.name'), [ 'multiple' => true, ]) ->label('Use in the following categories') ?> -- libgit2 0.21.4