Commit 2848e106eab16a873bf93200bc370ea911055937

Authored by Karnovsky A
1 parent 3147aab1

Fix last-products widget

common/modules/product/helpers/ProductHelper.php
... ... @@ -62,7 +62,10 @@ class ProductHelper extends Object {
62 62 public static function addLastProsucts($product_id) {
63 63 $last_products = self::getLastProducts();
64 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 69 Yii::$app->session->set('last_products', $last_products);
67 70 }
68 71 }
... ... @@ -70,10 +73,18 @@ class ProductHelper extends Object {
70 73 public static function getLastProducts($as_object = false) {
71 74 $last_products = Yii::$app->session->get('last_products', []);
72 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 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 8 <a href="<?= Url::to([
9 9 'catalog/product',
10 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 15 </a>
  16 + <?php endif?>
15 17 </div>
16 18 <?php if(!empty($product->is_top) || !empty($product->is_new) || !empty($product->akciya)) :?>
17 19 <ul class="product-special">
... ... @@ -32,31 +34,24 @@ use yii\helpers\Url;
32 34 ?>" class="name"><?= $product->name ?>
33 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>&nbsp;';
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>&nbsp;
  41 + <?php endif?>
  42 + <?= $product->enabledVariant->price?> <span>грн.</span></p>
  43 + </div>
50 44 </div>
  45 +
51 46 <a href="<?= Url::to([
52 47 'catalog/product',
53 48 'product' => $product,
54   - '#' => 'm' .$product->variant->product_variant_id])
  49 + '#' => 'm' .$product->enabledVariant->product_variant_id])
55 50 ?>" class="link_buy">Купить</a>
56 51  
57 52 <div class="mycarousel">
58 53 <ul class="jcarousel jcarousel-skin-tango">
59   - <?php foreach ($product->variants as $variant) : ?>
  54 + <?php foreach ($product->enabledVariants as $variant) : ?>
60 55 <li>
61 56 <a href="<?= Url::to([
62 57 'catalog/product',
... ...
common/modules/product/widgets/views/products_block.php
... ... @@ -7,7 +7,7 @@ use yii\web\View;
7 7 <h3><?= $title?></h3>
8 8 <div class="owl-carousel">
9 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 11 <?php endforeach?>
12 12 </div>
13 13 <div class="both"></div>
... ...