Commit 3523d4884138e33bfb8170288981ff94889f7aef
1 parent
8bef359d
big commti
Showing
3 changed files
with
20 additions
and
10 deletions
Show diff stats
common/modules/product/models/Product.php
... | ... | @@ -281,19 +281,26 @@ class Product extends \yii\db\ActiveRecord |
281 | 281 | } |
282 | 282 | |
283 | 283 | public function getActiveProperties($category_id) { |
284 | - $groups = $options = []; | |
285 | - foreach ($this->options as $option) { | |
286 | - $options[$option->tax_group_id][] = $option; | |
287 | - } | |
284 | + $cacheKey = ['ActiveProperties','id' => $category_id]; | |
288 | 285 | |
289 | - $taxGroups = TaxGroup::find()->joinWith('categories')->where(['tax_group.tax_group_id' => array_keys($options), 'tax_group.display' => TRUE, 'category.category_id' => $category_id])->all(); | |
286 | + if(!$groups = Yii::$app->cache->get($cacheKey)){ | |
290 | 287 | |
291 | - foreach ($taxGroups as $group) { | |
292 | - if (!empty($options[$group->tax_group_id])) { | |
293 | - $group->_options = $options[$group->tax_group_id]; | |
294 | - $groups[] = $group; | |
288 | + $groups = $options = []; | |
289 | + foreach ($this->options as $option) { | |
290 | + $options[$option->tax_group_id][] = $option; | |
291 | + } | |
292 | + | |
293 | + $taxGroups = TaxGroup::find()->joinWith('categories')->where(['tax_group.tax_group_id' => array_keys($options), 'tax_group.display' => TRUE, 'category.category_id' => $category_id])->all(); | |
294 | + | |
295 | + foreach ($taxGroups as $group) { | |
296 | + if (!empty($options[$group->tax_group_id])) { | |
297 | + $group->_options = $options[$group->tax_group_id]; | |
298 | + $groups[] = $group; | |
299 | + } | |
295 | 300 | } |
301 | + Yii::$app->cache->set($cacheKey,$groups); | |
296 | 302 | } |
303 | + | |
297 | 304 | return $groups; |
298 | 305 | } |
299 | 306 | ... | ... |
frontend/controllers/CatalogController.php
frontend/views/layouts/main.php
... | ... | @@ -258,7 +258,9 @@ use common\models\Event; |
258 | 258 | <div class="col-md-12"> |
259 | 259 | <div class="row"> |
260 | 260 | <div class="col-md-4"> |
261 | - <?php if($this->beginCache('articles_show',3600*24) ){?> | |
261 | + <?php if($this->beginCache('articles_show',[ | |
262 | + 'duration' => 3600*24 | |
263 | + ]) ){?> | |
262 | 264 | <span class="posts-title">Статьи</span> |
263 | 265 | <ul class="posts-links style"> |
264 | 266 | <?php foreach(Articles::find()->all() as $article):?> | ... | ... |