Commit 2848e106eab16a873bf93200bc370ea911055937
1 parent
3147aab1
Fix last-products widget
Showing
3 changed files
with
30 additions
and
24 deletions
Show diff stats
common/modules/product/helpers/ProductHelper.php
@@ -62,7 +62,10 @@ class ProductHelper extends Object { | @@ -62,7 +62,10 @@ class ProductHelper extends Object { | ||
62 | public static function addLastProsucts($product_id) { | 62 | public static function addLastProsucts($product_id) { |
63 | $last_products = self::getLastProducts(); | 63 | $last_products = self::getLastProducts(); |
64 | if (!in_array($product_id, $last_products)) { | 64 | if (!in_array($product_id, $last_products)) { |
65 | - $last_products[] = $product_id; | 65 | + $last_products[] = intval($product_id); |
66 | + if (count($last_products) > 16) { | ||
67 | + array_shift($last_products); | ||
68 | + } | ||
66 | Yii::$app->session->set('last_products', $last_products); | 69 | Yii::$app->session->set('last_products', $last_products); |
67 | } | 70 | } |
68 | } | 71 | } |
@@ -70,10 +73,18 @@ class ProductHelper extends Object { | @@ -70,10 +73,18 @@ class ProductHelper extends Object { | ||
70 | public static function getLastProducts($as_object = false) { | 73 | public static function getLastProducts($as_object = false) { |
71 | $last_products = Yii::$app->session->get('last_products', []); | 74 | $last_products = Yii::$app->session->get('last_products', []); |
72 | if ($as_object) { | 75 | if ($as_object) { |
73 | - $last_products = array_reverse(Product::find()->where([Product::tableName() .'.product_id' => $last_products])->all()); | ||
74 | -// $last_products = array_reverse(Product::find()->joinWith('variants')->where([Product::tableName() .'.product_id' => $last_products])->andWhere(['!=', ProductVariant::tableName() .'.stock', 0])->all()); | 76 | + $_products = []; |
77 | + foreach(Product::find()->joinWith(['variant'])->where([Product::tableName() .'.product_id' => $last_products])->andWhere(['!=', ProductVariant::tableName() .'.stock', 0])->all() as $product) { | ||
78 | + $_products[$product->product_id] = $product; | ||
79 | + } | ||
80 | + foreach($last_products as &$last_product) { | ||
81 | + if (empty($_products[$last_product])) { | ||
82 | + unset($last_product); | ||
83 | + } | ||
84 | + $last_product = $_products[$last_product]; | ||
85 | + } | ||
75 | } | 86 | } |
76 | - return $last_products; | 87 | + return array_reverse($last_products); |
77 | } | 88 | } |
78 | 89 | ||
79 | public static function getSpecialProducts($type, $count, $sort = null) { | 90 | public static function getSpecialProducts($type, $count, $sort = null) { |
common/modules/product/widgets/views/product_smart.php
@@ -8,10 +8,12 @@ use yii\helpers\Url; | @@ -8,10 +8,12 @@ use yii\helpers\Url; | ||
8 | <a href="<?= Url::to([ | 8 | <a href="<?= Url::to([ |
9 | 'catalog/product', | 9 | 'catalog/product', |
10 | 'product' => $product, | 10 | 'product' => $product, |
11 | - '#' => 'm' .$product->variant->product_variant_id]) | 11 | + '#' => 'm' .$product->enabledVariant->product_variant_id]) |
12 | ?>"> | 12 | ?>"> |
13 | - <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->imageUrl, 'list')?> | 13 | + <?= \common\components\artboximage\ArtboxImageHelper::getImage($product->enabledVariant->imageUrl, 'list')?> |
14 | + <?php if ($enabled !== false) :?> | ||
14 | </a> | 15 | </a> |
16 | + <?php endif?> | ||
15 | </div> | 17 | </div> |
16 | <?php if(!empty($product->is_top) || !empty($product->is_new) || !empty($product->akciya)) :?> | 18 | <?php if(!empty($product->is_top) || !empty($product->is_new) || !empty($product->akciya)) :?> |
17 | <ul class="product-special"> | 19 | <ul class="product-special"> |
@@ -32,31 +34,24 @@ use yii\helpers\Url; | @@ -32,31 +34,24 @@ use yii\helpers\Url; | ||
32 | ?>" class="name"><?= $product->name ?> | 34 | ?>" class="name"><?= $product->name ?> |
33 | </a> | 35 | </a> |
34 | 36 | ||
35 | - <?php | ||
36 | - | ||
37 | - echo '<div class="cost-block">'; | ||
38 | - echo '<p class="cost">'; | ||
39 | - // есть скидка | ||
40 | - if ($product->variant->price_old != 0 && $product->variant->price_old != $product->variant->price) | ||
41 | - { | ||
42 | - echo '<strike><span id=\'old_cost\'>'.$product->variant->price_old.'</span> грн.</strike> '; | ||
43 | - } | ||
44 | - | ||
45 | - echo $product->variant->price.' <span>грн.</span></p>'; | ||
46 | - | ||
47 | - echo '</div>'; | ||
48 | - | ||
49 | - ?> | 37 | + <div class="cost-block"> |
38 | + <p class="cost"> | ||
39 | + <?php if ($product->enabledVariant->price_old != 0 && $product->enabledVariant->price_old != $product->enabledVariant->price) :?> | ||
40 | + <strike><span id="old_cost"><?= $product->enabledVariant->price_old ?></span> грн.</strike> | ||
41 | + <?php endif?> | ||
42 | + <?= $product->enabledVariant->price?> <span>грн.</span></p> | ||
43 | + </div> | ||
50 | </div> | 44 | </div> |
45 | + | ||
51 | <a href="<?= Url::to([ | 46 | <a href="<?= Url::to([ |
52 | 'catalog/product', | 47 | 'catalog/product', |
53 | 'product' => $product, | 48 | 'product' => $product, |
54 | - '#' => 'm' .$product->variant->product_variant_id]) | 49 | + '#' => 'm' .$product->enabledVariant->product_variant_id]) |
55 | ?>" class="link_buy">Купить</a> | 50 | ?>" class="link_buy">Купить</a> |
56 | 51 | ||
57 | <div class="mycarousel"> | 52 | <div class="mycarousel"> |
58 | <ul class="jcarousel jcarousel-skin-tango"> | 53 | <ul class="jcarousel jcarousel-skin-tango"> |
59 | - <?php foreach ($product->variants as $variant) : ?> | 54 | + <?php foreach ($product->enabledVariants as $variant) : ?> |
60 | <li> | 55 | <li> |
61 | <a href="<?= Url::to([ | 56 | <a href="<?= Url::to([ |
62 | 'catalog/product', | 57 | 'catalog/product', |
common/modules/product/widgets/views/products_block.php
@@ -7,7 +7,7 @@ use yii\web\View; | @@ -7,7 +7,7 @@ use yii\web\View; | ||
7 | <h3><?= $title?></h3> | 7 | <h3><?= $title?></h3> |
8 | <div class="owl-carousel"> | 8 | <div class="owl-carousel"> |
9 | <?php foreach($products as $product) :?> | 9 | <?php foreach($products as $product) :?> |
10 | - <?= $this->render('product_smart', ['product' => $product]);?> | 10 | + <?= $this->render('product_smart', ['product' => $product, 'enabled' => !empty($product->enabledVariant)]);?> |
11 | <?php endforeach?> | 11 | <?php endforeach?> |
12 | </div> | 12 | </div> |
13 | <div class="both"></div> | 13 | <div class="both"></div> |