Commit 14eadb86e48260b0638ba6bc9cad2e473cdf3173
1 parent
290fae5b
Eager loading for catalog-models and autocomplete for relation create/update
Showing
22 changed files
with
164 additions
and
97 deletions
Show diff stats
backend/controllers/CategoryController.php
... | ... | @@ -90,7 +90,7 @@ class CategoryController extends Controller |
90 | 90 | } |
91 | 91 | return $this->render('create', [ |
92 | 92 | 'model' => $model, |
93 | - 'categories' => ArtboxTreeHelper::treeMap(Category::find()->getTree(), 'category_id', 'name', '.') | |
93 | + 'categories' => ArtboxTreeHelper::treeMap(Category::find()->with('categoryName')->getTree(), 'category_id', 'categoryName.value', '.') | |
94 | 94 | ]); |
95 | 95 | } |
96 | 96 | } |
... | ... | @@ -110,7 +110,7 @@ class CategoryController extends Controller |
110 | 110 | } else { |
111 | 111 | return $this->render('update', [ |
112 | 112 | 'model' => $model, |
113 | - 'categories' => ArtboxTreeHelper::treeMap(Category::find()->getTree(), 'category_id', 'name', '.') | |
113 | + 'categories' => ArtboxTreeHelper::treeMap(Category::find()->with('categoryName')->getTree(), 'category_id', 'categoryName.value', '.') | |
114 | 114 | ]); |
115 | 115 | } |
116 | 116 | } | ... | ... |
common/components/artboxtree/ArtboxTreeBehavior.php
... | ... | @@ -89,19 +89,20 @@ class ArtboxTreeBehavior extends Behavior { |
89 | 89 | * get all-level children items |
90 | 90 | * use MP-method |
91 | 91 | */ |
92 | - public function getAllChildren($depth = null, $where = []) { | |
93 | - return $this->getAllChildrenMP($depth)->where($where); | |
92 | + public function getAllChildren($depth = null, $where = [], $with = null) { | |
93 | + return $this->getAllChildrenMP($depth, $where, $with); | |
94 | 94 | } |
95 | 95 | |
96 | 96 | /* |
97 | 97 | * get all-level children items |
98 | 98 | * use MP-method |
99 | 99 | */ |
100 | - public function getAllChildrenTree($depth = null, $where = []) { | |
101 | - return $this->buildTree($this->getAllChildrenMP($depth, $where)->all(), $this->owner->getAttribute($this->keyNameId)); | |
100 | + public function getAllChildrenTree($depth = null, $where = [], $with = null) { | |
101 | + $query = $this->getAllChildrenMP($depth, $where, $with); | |
102 | + return $this->buildTree($query->all(), $this->owner->getAttribute($this->keyNameId)); | |
102 | 103 | } |
103 | 104 | |
104 | - protected function buildTree(array $data, $parentId = 0) { | |
105 | + public function buildTree(array $data, $parentId = 0) { | |
105 | 106 | $result = []; |
106 | 107 | foreach ($data as $key => $element) { |
107 | 108 | if ($element->getAttribute($this->keyNameParentId) == $parentId) { |
... | ... | @@ -205,7 +206,7 @@ class ArtboxTreeBehavior extends Behavior { |
205 | 206 | } |
206 | 207 | |
207 | 208 | |
208 | - public function getAllChildrenMP($depth = null) | |
209 | + public function getAllChildrenMP($depth = null, $where = [], $with = null) | |
209 | 210 | { |
210 | 211 | $tableName = $this->owner->tableName(); |
211 | 212 | $path = $this->owner->getAttribute($this->keyNamePath); |
... | ... | @@ -220,6 +221,13 @@ class ArtboxTreeBehavior extends Behavior { |
220 | 221 | $orderBy["{$tableName}.[[{$this->keyNameDepth}]]"] = SORT_ASC; |
221 | 222 | $orderBy["{$tableName}.[[{$this->keyNameId}]]"] = SORT_ASC; |
222 | 223 | |
224 | + if ($where) { | |
225 | + $query->andWhere($where); | |
226 | + } | |
227 | + if ($with) { | |
228 | + $query->with($with); | |
229 | + } | |
230 | + | |
223 | 231 | $query |
224 | 232 | ->andWhere($this->groupWhere()) |
225 | 233 | ->addOrderBy($orderBy); | ... | ... |
common/components/artboxtree/ArtboxTreeQueryTrait.php
... | ... | @@ -23,13 +23,15 @@ trait ArtboxTreeQueryTrait { |
23 | 23 | return self::$model; |
24 | 24 | } |
25 | 25 | |
26 | - public function getTree($group = null) { | |
26 | + public function getTree($group = null, $with = null) { | |
27 | 27 | $model = $this->getModel(); |
28 | 28 | if ($group !== null) { |
29 | - $data = $this->andWhere([$model->keyNameGroup => $group])->all(); | |
30 | - } else { | |
31 | - $data = $this->all(); | |
29 | + $this->andWhere([$model->keyNameGroup => $group]); | |
32 | 30 | } |
31 | + if ($with) { | |
32 | + $this->with($with); | |
33 | + } | |
34 | + $data = $this->all(); | |
33 | 35 | if (empty($data)) |
34 | 36 | return []; |
35 | 37 | |
... | ... | @@ -53,8 +55,8 @@ trait ArtboxTreeQueryTrait { |
53 | 55 | /** |
54 | 56 | * @param int $group |
55 | 57 | */ |
56 | - public function rebuildMP($group) { | |
57 | - $tree = $this->getTree($group); | |
58 | + public function rebuildMP($group, $with = null) { | |
59 | + $tree = $this->getTree($group, $with); | |
58 | 60 | |
59 | 61 | $this->_recursiveRebuild($tree); |
60 | 62 | } | ... | ... |
common/config/main.php
... | ... | @@ -81,14 +81,17 @@ return [ |
81 | 81 | 'entity1' => [ |
82 | 82 | 'model' => '\common\modules\product\models\Product', |
83 | 83 | 'label' => 'Product', |
84 | - 'listField' => 'fullname', | |
84 | + 'listField' => 'name', | |
85 | + 'searchField' => 'name', | |
85 | 86 | 'key' => 'product_id', |
86 | 87 | 'linked_key' => 'product_id', |
87 | 88 | ], |
88 | 89 | 'entity2' => [ |
89 | 90 | 'model' => '\common\modules\product\models\Category', |
90 | 91 | 'label' => 'Category', |
91 | - 'listField' => 'name', | |
92 | + 'listField' => 'categoryName.value', | |
93 | + 'searchField' => 'category_name.value', | |
94 | + 'searchJoin' => 'categoryName', | |
92 | 95 | 'key' => 'category_id', |
93 | 96 | 'linked_key' => 'category_id', |
94 | 97 | 'hierarchy' => [ | ... | ... |
common/modules/product/helpers/ProductHelper.php
... | ... | @@ -8,10 +8,10 @@ use yii\base\Object; |
8 | 8 | |
9 | 9 | class ProductHelper extends Object { |
10 | 10 | public static function getCategories() { |
11 | - return Category::find()->getTree(); | |
11 | + return Category::find()->with('categoryName')->getTree(); | |
12 | 12 | } |
13 | 13 | |
14 | 14 | public static function getBrands() { |
15 | - return Brand::find(); | |
15 | + return Brand::find()->with('brandName'); | |
16 | 16 | } |
17 | 17 | } |
18 | 18 | \ No newline at end of file | ... | ... |
common/modules/product/models/Brand.php
common/modules/product/models/BrandSearch.php
common/modules/product/models/Category.php
... | ... | @@ -87,6 +87,7 @@ class Category extends \yii\db\ActiveRecord |
87 | 87 | [['alias', 'name'], 'string', 'max' => 250], |
88 | 88 | [['populary'], 'boolean'], |
89 | 89 | [['group_to_category'], 'safe'], |
90 | + [['category_name_id'], 'exist', 'skipOnError' => true, 'targetClass' => CategoryName::className(), 'targetAttribute' => ['category_name_id' => 'category_name_id']], | |
90 | 91 | // [['image'], 'file', 'skipOnEmpty' => false, 'extensions' => 'png, jpg, gif'], |
91 | 92 | // [['product_unit_id'], 'exist', 'skipOnError' => true, 'targetClass' => ProductUnit::className(), 'targetAttribute' => ['product_unit_id' => 'product_unit_id']], |
92 | 93 | ]; |
... | ... | @@ -160,8 +161,9 @@ class Category extends \yii\db\ActiveRecord |
160 | 161 | return $this->hasOne(CategoryName::className(), ['category_name_id' => 'category_name_id']); |
161 | 162 | } |
162 | 163 | |
163 | - public function getName() { | |
164 | - $value = $this->getCategoryName()->one(); | |
165 | - return empty($value) ? $this->_getValue('name') : $value->value; | |
166 | - } | |
164 | +// public function getName() { | |
165 | +//// return $this->getCategoryName(); | |
166 | +// $value = $this->getCategoryName()->one(); | |
167 | +// return empty($value) ? $this->_getValue('name') : $value->value; | |
168 | +// } | |
167 | 169 | } | ... | ... |
common/modules/product/models/CategoryQuery.php
... | ... | @@ -34,15 +34,4 @@ class CategoryQuery extends \yii\db\ActiveQuery |
34 | 34 | { |
35 | 35 | return parent::one($db); |
36 | 36 | } |
37 | - | |
38 | - /** | |
39 | - * Select category by alias | |
40 | - * @param $slug | |
41 | - * @return $this | |
42 | - */ | |
43 | - public function byAlias($alias) | |
44 | - { | |
45 | - $this->andFilterWhere(['alias' => $alias]); | |
46 | - return $this; | |
47 | - } | |
48 | 37 | } | ... | ... |
common/modules/product/models/CategorySearch.php
... | ... | @@ -55,7 +55,7 @@ class CategorySearch extends Category |
55 | 55 | */ |
56 | 56 | public function search($params) |
57 | 57 | { |
58 | - $query = Category::find(); | |
58 | + $query = Category::find()->with('categoryName'); | |
59 | 59 | |
60 | 60 | // add conditions that should always apply here |
61 | 61 | |
... | ... | @@ -88,8 +88,9 @@ class CategorySearch extends Category |
88 | 88 | |
89 | 89 | public static function findByAlias($alias) { |
90 | 90 | /** @var CategoryQuery $query */ |
91 | - $query = Category::find(); | |
92 | - $query->byAlias($alias); | |
91 | + $query = Category::find() | |
92 | + ->with('categoryName') | |
93 | + ->andFilterWhere(['alias' => $alias]); | |
93 | 94 | if (($model = $query->one()) !== null) { |
94 | 95 | return $model; |
95 | 96 | } else { | ... | ... |
common/modules/product/models/Product.php
common/modules/product/widgets/brandsCarouselWidget.php
common/modules/product/widgets/catalogSubmenuWidget.php
... | ... | @@ -15,12 +15,22 @@ class catalogSubmenuWidget extends Widget { |
15 | 15 | } |
16 | 16 | |
17 | 17 | public function run() { |
18 | + /** @var Category $rootCategory */ | |
18 | 19 | $rootCategory = Category::findOne($this->root_id); |
20 | + | |
21 | + $categories = $rootCategory->getAllChildren(2, [], 'categoryName')->all(); | |
22 | + $populary = []; | |
23 | + foreach($categories as $category) { | |
24 | + if ($category->populary) { | |
25 | + $populary[] = $category; | |
26 | + } | |
27 | + } | |
28 | + | |
19 | 29 | return $this->render('submenu', [ |
20 | 30 | 'rootCategory' => $rootCategory, |
21 | 31 | 'rootClass' => $this->rootClass, |
22 | - 'populary' => $rootCategory->getAllChildren(2, ['populary' => true])->all(), | |
23 | - 'items' => $rootCategory->getAllChildrenTree(2) | |
32 | + 'populary' => $populary, | |
33 | + 'items' => $rootCategory->buildTree($categories, $rootCategory->category_id) | |
24 | 34 | ]); |
25 | 35 | } |
26 | 36 | } |
27 | 37 | \ No newline at end of file | ... | ... |
common/modules/product/widgets/views/submenu.php
1 | 1 | <div class="menu_item"> |
2 | - <?= \yii\helpers\Html::a($rootCategory->name, ['catalog/category', 'alias' => $rootCategory->alias], ['class' => 'submenu_button '. $rootClass])?> | |
2 | + <?= \yii\helpers\Html::a($rootCategory->categoryName->value, ['catalog/category', 'alias' => $rootCategory->alias], ['class' => 'submenu_button '. $rootClass])?> | |
3 | 3 | <div class="submenu"> |
4 | 4 | <ul class="categories"> |
5 | 5 | <li class="sub_cat"><span>Популярные категории</span> |
... | ... | @@ -15,7 +15,7 @@ |
15 | 15 | <img valign="top" src="<?= $_item->image?>"> |
16 | 16 | <?php endif?> |
17 | 17 | </div> |
18 | - <div class="title"><?= $_item->name?></div> | |
18 | + <div class="title"><?= $_item->categoryName->value?></div> | |
19 | 19 | </a></div> |
20 | 20 | <?php endforeach?> |
21 | 21 | </div> |
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 | </li> |
25 | 25 | <?php foreach($items as $item) :?> |
26 | 26 | <li class="sub_cat"> |
27 | - <span><?= $item['item']->name?></span> | |
27 | + <span><?= $item['item']->categoryName->value?></span> | |
28 | 28 | <?php if(!empty($item['children'])) :?> |
29 | 29 | <div class="sub_cat_content"> |
30 | 30 | <div class="content_items"> |
... | ... | @@ -34,17 +34,17 @@ |
34 | 34 | <?php if (empty($_item['item']->image)) :?> |
35 | 35 | <img valign="top" src="/images/no_photo.png"> |
36 | 36 | <?php else :?> |
37 | - <img valign="top" src="<?= $_item['item']->image?>" alt="<?= $_item['item']->name?>"> | |
37 | + <img valign="top" src="<?= $_item['item']->image?>" alt="<?= $_item['item']->categoryName->value?>"> | |
38 | 38 | <?php endif?> |
39 | 39 | </div> |
40 | - <div class="title"><?= $_item['item']->name?></div> | |
40 | + <div class="title"><?= $_item['item']->categoryName->value?></div> | |
41 | 41 | </a></div> |
42 | 42 | <?php endforeach?> |
43 | 43 | </div> |
44 | 44 | </div> |
45 | 45 | <?php endif?> |
46 | 46 | </li> |
47 | - <?php endforeach?> | |
47 | + <?php endforeach ?> | |
48 | 48 | </ul> |
49 | 49 | </div> |
50 | 50 | </div> | ... | ... |
common/modules/relation/controllers/ManageController.php
... | ... | @@ -4,8 +4,12 @@ namespace common\modules\relation\controllers; |
4 | 4 | |
5 | 5 | use common\modules\rubrication\models\TaxOption; |
6 | 6 | use yii\base\Exception; |
7 | +use yii\db\ActiveQuery; | |
8 | +use yii\helpers\ArrayHelper; | |
9 | +use yii\web\Response; | |
7 | 10 | use yii\data\ActiveDataProvider; |
8 | 11 | use yii\db\ActiveRecord; |
12 | +use yii\filters\ContentNegotiator; | |
9 | 13 | use yii\web\Controller; |
10 | 14 | use Yii; |
11 | 15 | use common\modules\relation\relationHelper; |
... | ... | @@ -18,6 +22,20 @@ use yii\web\NotFoundHttpException; |
18 | 22 | */ |
19 | 23 | class ManageController extends Controller |
20 | 24 | { |
25 | + public function behaviors() | |
26 | + { | |
27 | + return [ | |
28 | + /*'bootstrap' => [ | |
29 | + 'class' => ContentNegotiator::className(), | |
30 | + 'only' => ['autocomplete'], | |
31 | + 'formats' => [ 'application/json' => Response::FORMAT_JSON], | |
32 | + 'languages' => [ | |
33 | + 'ru', | |
34 | + ], | |
35 | + ],*/ | |
36 | + ]; | |
37 | + } | |
38 | + | |
21 | 39 | /** |
22 | 40 | * Renders the relations view |
23 | 41 | * @return string |
... | ... | @@ -66,14 +84,6 @@ class ManageController extends Controller |
66 | 84 | |
67 | 85 | $model = new $relation['via']['model']; |
68 | 86 | |
69 | - $query1 = $relation['entity1']['model']::find(); | |
70 | - if (!empty($relation['entity1']['where'])) | |
71 | - $query1->where($relation['entity1']['where']); | |
72 | - | |
73 | - $query2 = $relation['entity2']['model']::find(); | |
74 | - if (!empty($relation['entity2']['where'])) | |
75 | - $query2->where($relation['entity2']['where']); | |
76 | - | |
77 | 87 | if ($model->load(Yii::$app->request->post())) { |
78 | 88 | $model->save(); |
79 | 89 | return $this->redirect(['pars', 'relation' => $relation_key]); |
... | ... | @@ -81,8 +91,8 @@ class ManageController extends Controller |
81 | 91 | } else { |
82 | 92 | return $this->render('create', [ |
83 | 93 | 'model' => $model, |
84 | - 'items1' => $query1->all(), | |
85 | - 'items2' => $query2->all(), | |
94 | +// 'items1' => $query1->limit(100)->all(), | |
95 | +// 'items2' => $query2->asArray()->all(), | |
86 | 96 | 'relation_key' => $relation_key, |
87 | 97 | 'relation' => $relation, |
88 | 98 | ]); |
... | ... | @@ -103,14 +113,6 @@ class ManageController extends Controller |
103 | 113 | |
104 | 114 | $model = $this->findModel($relation_key, $id1, $id2); |
105 | 115 | |
106 | - $query1 = $relation['entity1']['model']::find(); | |
107 | - if (!empty($relation['entity1']['where'])) | |
108 | - $query1->where($relation['entity1']['where']); | |
109 | - | |
110 | - $query2 = $relation['entity2']['model']::find(); | |
111 | - if (!empty($relation['entity2']['where'])) | |
112 | - $query2->where($relation['entity2']['where']); | |
113 | - | |
114 | 116 | if ($model->load(Yii::$app->request->post())) { |
115 | 117 | $connection = Yii::$app->getDb(); |
116 | 118 | $transaction = $connection->beginTransaction(); |
... | ... | @@ -137,8 +139,8 @@ class ManageController extends Controller |
137 | 139 | } else { |
138 | 140 | return $this->render('update', [ |
139 | 141 | 'model' => $model, |
140 | - 'items1' => $query1->all(), | |
141 | - 'items2' => $query2->all(), | |
142 | + 'value1' => $model->entity1->getAttribute($relation['entity1']['listField']), | |
143 | + 'value2' => $model->entity2->getAttribute($relation['entity2']['listField']), | |
142 | 144 | 'relation_key' => $relation_key, |
143 | 145 | 'relation' => $relation, |
144 | 146 | ]); |
... | ... | @@ -178,6 +180,28 @@ class ManageController extends Controller |
178 | 180 | return $this->redirect(['pars', 'relation' => $relation_key]); |
179 | 181 | } |
180 | 182 | |
183 | + public function actionAutocomplete() { | |
184 | + $relation_key = Yii::$app->request->get('relation_key'); | |
185 | + $entity = Yii::$app->request->get('entity'); | |
186 | + $term = Yii::$app->request->get('term'); | |
187 | + $relation_key = strtolower($relation_key); | |
188 | + $relation = relationHelper::getRelation($relation_key); | |
189 | + | |
190 | + /** @var ActiveQuery $query */ | |
191 | + $query = $relation[$entity]['model']::find(); | |
192 | + | |
193 | + if (!empty($relation[$entity]['searchJoin'])) { | |
194 | + $query->innerJoinWith($relation[$entity]['searchJoin']); | |
195 | + } | |
196 | + if (!empty($relation[$entity]['where'])) { | |
197 | + $query->where($relation[$entity]['where']); | |
198 | + } | |
199 | + $query->where(['ilike', $relation[$entity]['searchField'], $term]); | |
200 | + | |
201 | + print json_encode(ArrayHelper::map($query->limit(50)->all(), $relation[$entity]['key'], $relation[$entity]['listField'])); | |
202 | + exit; | |
203 | + } | |
204 | + | |
181 | 205 | /** |
182 | 206 | * Finds the based model for relation on its primaries keys value. |
183 | 207 | * If the model is not found, a 404 HTTP exception will be thrown. | ... | ... |
common/modules/relation/views/manage/_form.php
... | ... | @@ -3,6 +3,7 @@ |
3 | 3 | use yii\helpers\Html; |
4 | 4 | use yii\widgets\ActiveForm; |
5 | 5 | use yii\helpers\ArrayHelper; |
6 | +use yii\jui\AutoComplete; | |
6 | 7 | |
7 | 8 | /* @var $this yii\web\View */ |
8 | 9 | /* @var $model common\modules\rubrication\models\TaxGroup */ |
... | ... | @@ -13,19 +14,40 @@ use yii\helpers\ArrayHelper; |
13 | 14 | |
14 | 15 | <?php $form = ActiveForm::begin(); ?> |
15 | 16 | |
16 | - <?= $form->field($model, $relation['entity1']['linked_key'])->dropDownList( | |
17 | - ArrayHelper::map($items1, $relation['entity1']['key'], $relation['entity1']['listField']), | |
18 | - [ | |
19 | - 'prompt' => Yii::t('relation', 'Select value'), | |
17 | + <?= $form->field($model, $relation['entity1']['linked_key'])->widget( | |
18 | + AutoComplete::className(), [ | |
19 | +// 'model' => \common\modules\relation\models\Relation::className(), | |
20 | + 'clientOptions' => [ | |
21 | + 'source' => \yii\helpers\Url::to(['manage/autocomplete/', 'relation_key' => $relation_key, 'entity' => 'entity1']), | |
22 | + 'dataType' => 'json', | |
23 | + 'autoFill' => true, | |
24 | + 'minLength' => '2', | |
25 | + ], | |
26 | + 'options' => [ | |
27 | + 'value' => empty($value1) ? '' : $value1, | |
28 | + 'class'=>'form-control', | |
29 | + 'placeholder' => $relation['entity1']['label'] | |
20 | 30 | ] |
21 | - ) ?> | |
22 | - | |
23 | - <?= $form->field($model, $relation['entity2']['linked_key'])->dropDownList( | |
24 | - ArrayHelper::map($items2, $relation['entity2']['key'], $relation['entity2']['listField']), | |
25 | - [ | |
26 | - 'prompt' => Yii::t('relation', 'Select value'), | |
31 | + ]); | |
32 | + ?> | |
33 | + | |
34 | + <?= $form->field($model, $relation['entity2']['linked_key'])->widget( | |
35 | + AutoComplete::className(), [ | |
36 | +// 'model' => \common\modules\relation\models\Relation::className(), | |
37 | + 'clientOptions' => [ | |
38 | + 'source' => \yii\helpers\Url::to(['manage/autocomplete/', 'relation_key' => $relation_key, 'entity' => 'entity2']), | |
39 | + 'dataType' => 'json', | |
40 | + 'autoFill' => true, | |
41 | + 'minLength' => '2', | |
42 | + 'allowClear' => true, | |
43 | + ], | |
44 | + 'options' => [ | |
45 | + 'value' => empty($value2) ? '' : $value2, | |
46 | + 'class'=>'form-control', | |
47 | + 'placeholder' => $relation['entity2']['label'] | |
27 | 48 | ] |
28 | - ) ?> | |
49 | + ]); | |
50 | + ?> | |
29 | 51 | |
30 | 52 | <div class="form-group"> |
31 | 53 | <?= Html::submitButton($model->isNewRecord ? Yii::t('relation', 'Create') : Yii::t('relation', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> | ... | ... |
common/modules/relation/views/manage/create.php
... | ... | @@ -2,7 +2,6 @@ |
2 | 2 | |
3 | 3 | use yii\helpers\Html; |
4 | 4 | |
5 | - | |
6 | 5 | /* @var $this yii\web\View */ |
7 | 6 | |
8 | 7 | $this->title = Yii::t('relation', $relation['name']); |
... | ... | @@ -16,8 +15,6 @@ $this->params['breadcrumbs'][] = $this->title; |
16 | 15 | |
17 | 16 | <?= $this->render('_form', [ |
18 | 17 | 'model' => $model, |
19 | - 'items1' => $items1, | |
20 | - 'items2' => $items2, | |
21 | 18 | 'relation_key' => $relation_key, |
22 | 19 | 'relation' => $relation, |
23 | 20 | ]) ?> | ... | ... |
common/modules/relation/views/manage/update.php
... | ... | @@ -16,8 +16,8 @@ $this->params['breadcrumbs'][] = $this->title; |
16 | 16 | |
17 | 17 | <?= $this->render('_form', [ |
18 | 18 | 'model' => $model, |
19 | - 'items1' => $items1, | |
20 | - 'items2' => $items2, | |
19 | + 'value1' => $value1, | |
20 | + 'value2' => $value2, | |
21 | 21 | 'relation_key' => $relation_key, |
22 | 22 | 'relation' => $relation, |
23 | 23 | ]) ?> | ... | ... |
common/modules/rubrication/models/TaxOption.php
... | ... | @@ -166,7 +166,7 @@ class TaxOption extends \yii\db\ActiveRecord |
166 | 166 | public function getValueRenderFlash() |
167 | 167 | { |
168 | 168 | $valueClass = $this->getValueModelName(); |
169 | - $value = $this->getValue()->one(); | |
169 | + $value = $this->value; | |
170 | 170 | if ($valueClass && method_exists($valueClass, 'getValueRenderFlash')) { |
171 | 171 | return $valueClass::getValueRenderFlash($value); |
172 | 172 | } elseif(!empty($value)) { |
... | ... | @@ -181,7 +181,7 @@ class TaxOption extends \yii\db\ActiveRecord |
181 | 181 | public function getValueRenderHTML() |
182 | 182 | { |
183 | 183 | $valueClass = $this->getValueModelName(); |
184 | - $value = $this->getValue()->one(); | |
184 | + $value = $this->value; | |
185 | 185 | if ($valueClass && method_exists($valueClass, 'getValueRenderHTML')) { |
186 | 186 | return $valueClass::getValueRenderHTML($value); |
187 | 187 | } else { |
... | ... | @@ -219,7 +219,7 @@ class TaxOption extends \yii\db\ActiveRecord |
219 | 219 | // } |
220 | 220 | |
221 | 221 | private function getValueModelName() { |
222 | - $group = $this->getTaxGroup()->one(); | |
222 | + $group = $this->taxGroup; | |
223 | 223 | $valueClass = '\common\modules\rubrication\models\TaxValue'. ucfirst($group->module); |
224 | 224 | return class_exists($valueClass) ? $valueClass : FALSE; |
225 | 225 | } | ... | ... |
frontend/controllers/CatalogController.php
... | ... | @@ -12,6 +12,7 @@ use common\modules\product\models\ProductSearch; |
12 | 12 | use common\modules\product\models\ProductVariant; |
13 | 13 | use common\modules\rubrication\models\TaxGroup; |
14 | 14 | use common\modules\rubrication\models\TaxOption; |
15 | +use common\modules\rubrication\models\TaxValueString; | |
15 | 16 | use yii\data\ActiveDataProvider; |
16 | 17 | use yii\data\Pagination; |
17 | 18 | use yii\data\Sort; |
... | ... | @@ -64,6 +65,7 @@ class CatalogController extends \yii\web\Controller |
64 | 65 | $all_count = $query->count(); |
65 | 66 | |
66 | 67 | $brandsQuery = Brand::find() |
68 | + ->innerJoinWith('brandName') | |
67 | 69 | ->innerJoinWith('products') |
68 | 70 | ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. Product::tableName() .'.product_id') |
69 | 71 | ->where([ |
... | ... | @@ -71,7 +73,7 @@ class CatalogController extends \yii\web\Controller |
71 | 73 | ]) |
72 | 74 | ->groupBy(Brand::tableName() .'.brand_id'); |
73 | 75 | $brands = $brandsQuery->all(); |
74 | - $brands_count = $brandsQuery->count(); | |
76 | + $brands_count = count($brands); // $brandsQuery->count(); | |
75 | 77 | |
76 | 78 | $optionsQuery = TaxOption::find() |
77 | 79 | ->select([ |
... | ... | @@ -80,6 +82,7 @@ class CatalogController extends \yii\web\Controller |
80 | 82 | ]) |
81 | 83 | ->innerJoin(ProductOption::tableName(), ProductOption::tableName() .'.option_id='. TaxOption::tableName() .'.tax_option_id') |
82 | 84 | ->innerJoin(ProductCategory::tableName(), ProductCategory::tableName() .'.product_id='. ProductOption::tableName() .'.product_id') |
85 | + ->innerJoinWith('group') | |
83 | 86 | ->where([ |
84 | 87 | ProductCategory::tableName() .'.category_id' => $category->category_id |
85 | 88 | ]) |
... | ... | @@ -133,12 +136,12 @@ class CatalogController extends \yii\web\Controller |
133 | 136 | foreach($options_alias as &$option_alias) { |
134 | 137 | $option_alias = "'". $option_alias ."'"; |
135 | 138 | } |
136 | - $group = TaxGroup::find()->where(['like', 'alias', $group_alias])->one(); | |
139 | + /*$group = TaxGroup::find()->where(['like', 'alias', $group_alias])->one(); | |
137 | 140 | if (!$group) { |
138 | 141 | continue; |
139 | - } | |
140 | - $query->andWhere(Product::tableName() .'.product_id IN (SELECT product_id AS products FROM product_option INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id WHERE tax_option.alias IN ('. implode(',', $options_alias) .'))'); | |
142 | + }*/ | |
141 | 143 | } |
144 | + $query->andWhere(Product::tableName() .'.product_id IN (SELECT product_id AS products FROM product_option INNER JOIN tax_option ON tax_option.tax_option_id = product_option.option_id WHERE tax_option.alias IN ('. implode(',', $options_alias) .'))'); | |
142 | 145 | } |
143 | 146 | |
144 | 147 | if (($_brands = \Yii::$app->request->get('brand')) != false && is_array($_brands) && count($_brands) > 0) { |
... | ... | @@ -152,12 +155,17 @@ class CatalogController extends \yii\web\Controller |
152 | 155 | } |
153 | 156 | } |
154 | 157 | |
155 | - $count = $query->count(); | |
158 | + $query->with('variant'); | |
159 | + $query->with('brand'); | |
160 | + $query->with('categories'); | |
161 | + $query->with('image'); | |
156 | 162 | |
163 | + $count = $query->count(); | |
157 | 164 | $pages = new Pagination(['totalCount' => $count, 'pageSize' => $per_page]); |
158 | 165 | $query->offset($pages->offset) |
159 | 166 | ->orderBy($sort->orders) |
160 | 167 | ->limit($pages->limit); |
168 | + | |
161 | 169 | $products = $query->all(); |
162 | 170 | |
163 | 171 | return $this->render( | ... | ... |
frontend/views/catalog/categories.php
... | ... | @@ -14,7 +14,7 @@ $this->params['breadcrumbs'][] = $this->title; |
14 | 14 | |
15 | 15 | <div class="category_wrap_3_colum"><!-- 3 colons for items ================================== 1rst colum --> |
16 | 16 | |
17 | - <?php foreach($category->getAllChildrenTree(2) as $category) :?> | |
17 | + <?php foreach($category->getAllChildrenTree(2, [], 'categoryName') as $category) :?> | |
18 | 18 | <div class="wrap"> |
19 | 19 | <div class="cat_li_cont"> |
20 | 20 | <?php if (!empty($category['item']->image)) :?> | ... | ... |
frontend/views/catalog/products.php
... | ... | @@ -2,11 +2,11 @@ |
2 | 2 | /** @var $this \yii\web\View */ |
3 | 3 | /** @var $dataProvider \yii\data\ActiveDataProvider */ |
4 | 4 | |
5 | -$this->title = $category->name; | |
5 | +$this->title = $category->categoryName->value; | |
6 | 6 | foreach($category->getParents()->all() as $parent) { |
7 | - $this->params['breadcrumbs'][] = ['label' => $parent->name, 'url' => ['catalog/category', 'alias' => $parent->alias]]; | |
7 | + $this->params['breadcrumbs'][] = ['label' => $parent->categoryName->value, 'url' => ['catalog/category', 'alias' => $parent->alias]]; | |
8 | 8 | } |
9 | -$this->params['breadcrumbs'][] = $category->name; | |
9 | +$this->params['breadcrumbs'][] = $category->categoryName->value; | |
10 | 10 | ?> |
11 | 11 | <script type="text/javascript"> |
12 | 12 | $(document).ready(function() { |
... | ... | @@ -184,11 +184,11 @@ $this->params['breadcrumbs'][] = $category->name; |
184 | 184 | |
185 | 185 | <!-- catalog list with all item cards --> |
186 | 186 | <div class="cat_p_catalog_list"> |
187 | - <div class="title"><?= $category->name?> <span>(<?= $all_count?>)</span></div> | |
187 | + <div class="title"><?= $category->categoryName->value?> <span>(<?= $all_count?>)</span></div> | |
188 | 188 | |
189 | 189 | <?php if (empty($products)) :?> |
190 | 190 | <h2>По данному запросу товары не найдены.</h2><br> |
191 | - <p>Показать <a href="<?= \yii\helpers\Url::to(['catalog/category', 'alias' => $category->alias])?>">все товары из категории "<?= $category->name?>"</a></p> | |
191 | + <p>Показать <a href="<?= \yii\helpers\Url::to(['catalog/category', 'alias' => $category->alias])?>">все товары из категории "<?= $category->categoryName->value?>"</a></p> | |
192 | 192 | <?php else :?> |
193 | 193 | <!-- sort menu --> |
194 | 194 | <div class="sort_menu"> | ... | ... |