Commit 4e03534e0ddbd9768c916a86056810c545175629

Authored by Administrator
1 parent 4ec0b3c5

add similar products

helpers/ProductHelper.php
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 4
5 use artweb\artbox\ecommerce\models\Category; 5 use artweb\artbox\ecommerce\models\Category;
6 use artweb\artbox\ecommerce\models\Product; 6 use artweb\artbox\ecommerce\models\Product;
  7 + use artweb\artbox\ecommerce\models\ProductVariant;
7 use yii\base\InvalidConfigException; 8 use yii\base\InvalidConfigException;
8 use yii\base\InvalidParamException; 9 use yii\base\InvalidParamException;
9 use yii\base\Object; 10 use yii\base\Object;
@@ -179,6 +180,23 @@ @@ -179,6 +180,23 @@
179 $product->id, 180 $product->id,
180 ] 181 ]
181 ); 182 );
  183 +
  184 +
  185 + $query->andWhere([
  186 + '>=',
  187 + ProductVariant::tableName() . '.price',
  188 + ($product->variant->price * 0.8),
  189 + ]);
  190 +
  191 +
  192 + $query->andWhere([
  193 + '<=',
  194 + ProductVariant::tableName() . '.price',
  195 + ($product->variant->price * 1.2),
  196 + ]);
  197 +
  198 +
  199 +
182 $query->groupBy('product.id'); 200 $query->groupBy('product.id');
183 $query->limit($count); 201 $query->limit($count);
184 return $query; 202 return $query;
widgets/similarProducts.php
@@ -22,8 +22,9 @@ @@ -22,8 +22,9 @@
22 22
23 public function run() 23 public function run()
24 { 24 {
25 - $products = ProductHelper::getSimilarProducts($this->product, $this->count);  
26 - 25 + $products = ProductHelper::getSimilarProducts($this->product, $this->count)->all();
  26 +
  27 +
27 if (!$this->title) { 28 if (!$this->title) {
28 $this->title = Yii::t('product', 'Similar products'); 29 $this->title = Yii::t('product', 'Similar products');
29 } 30 }
widgets/views/product_smart.php
1 <?php 1 <?php
2 - /**  
3 - * @var $product artweb\artbox\ecommerce\models\Product  
4 - */  
5 - use artweb\artbox\components\artboximage\ArtboxImageHelper;  
6 - use yii\helpers\Html;  
7 - use yii\helpers\Url; 2 +/**
  3 + * @var $model Product
  4 + */
  5 +use artweb\artbox\components\artboximage\ArtboxImageHelper;
  6 +use artweb\artbox\ecommerce\models\Product;
  7 +use yii\bootstrap\Html;
  8 +use yii\helpers\ArrayHelper;
8 9
9 -?>  
10 -<div class="catalog_item">  
11 - <div class="wrapper">  
12 - <div class="item_container">  
13 - <input class="prodInfo" type="hidden" value="[]">  
14 - <div class="title">  
15 - <?= Html::a(  
16 - $product->lang->title,  
17 - Url::to(  
18 - [  
19 - 'catalog/product',  
20 - 'product' => $product->lang->alias,  
21 - ]  
22 - ),  
23 - [ 'class' => 'btn-product-details' ]  
24 - ) ?>  
25 - </div>  
26 - <div class="img">  
27 - <a class="btn-product-details" href="<?= Url::to( 10 +
  11 +
  12 +if($this->beginCache('_item_list'.$model->id,[
  13 + 'variations' => [\Yii::$app->language],
  14 + 'id' => $model->id,
  15 + 'duration' => 3600 *24
  16 +])){
  17 +
  18 +
  19 + $fullname = $model->fullName;
  20 + if(!empty($model->enabledVariants)) {
  21 + $variant = $model->enabledVariants[ 0 ];
  22 + } else {
  23 + $variant = $model->variant;
  24 + }
  25 + $imageMap = ArrayHelper::map($model->enabledVariants, 'sku', 'images', 'lang.title');
  26 + $firstImage = [
  27 + 'sku' => $variant->sku,
  28 + 'image' => '',
  29 + ];
  30 +
  31 + $firstIteration = true;
  32 + foreach ($imageMap as $key => $item) {
  33 + $imageMap[ $key ] = array_filter($item);
  34 + foreach ($imageMap[ $key ] as $subKey => $subValue) {
  35 + foreach ($subValue as $subSubValue) {
  36 + if (!empty( $subSubValue )) {
  37 + $imageMap[ $key ][ $subKey ] = $subSubValue->imageUrl;
  38 + if ($firstIteration) {
  39 + $firstImage = [
  40 + 'sku' => $subKey,
  41 + 'image' => $subSubValue->imageUrl,
  42 + ];
  43 + }
  44 + $firstIteration = false;
  45 + break;
  46 + }
  47 + }
  48 + }
  49 + }
  50 + ?>
  51 + <div class="item_catalog">
  52 + <div class="bg-status">
  53 + <?php
  54 + if ($model->is_discount) {
  55 + echo Html::tag(
  56 + 'div',
  57 + Html::tag('span', \Yii::t('app', 'ะฐะบั†ะธั')),
  58 + [
  59 + 'class' => 'sale_bg',
  60 + ]
  61 + );
  62 + }
  63 + if ($model->is_top) {
  64 + echo Html::tag(
  65 + 'div',
  66 + Html::tag('span', \Yii::t('app', 'top')),
  67 + [
  68 + 'class' => 'top_bg',
  69 + ]
  70 + );
  71 + }
  72 + if ($model->is_new) {
  73 + echo Html::tag(
  74 + 'div',
  75 + Html::tag('span', \Yii::t('app', 'new')),
  76 + [
  77 + 'class' => 'new_bg',
  78 + ]
  79 + );
  80 + }
  81 + ?>
  82 + </div>
  83 + <div class="img style">
  84 + <?php
  85 + echo Html::a(
  86 + ArtboxImageHelper::getImage(
  87 + $firstImage[ 'image' ],
  88 + 'category_item',
  89 + [
  90 + 'alt' => $fullname,
  91 + 'title' => $fullname,
  92 + ],
  93 + 90,
  94 + true
  95 + ),
  96 + [
  97 + 'catalog/product',
  98 + 'product' => $model->lang->alias,
  99 + 'variant' => $firstImage[ 'sku' ],
  100 + ],
  101 + [
  102 + 'data-pjax' => 0,
  103 + 'title' => $fullname,
  104 + ]
  105 + );
  106 + ?>
  107 + </div>
  108 + <?php
  109 + echo Html::a(
  110 + yii\helpers\StringHelper::truncate($fullname, 41),
  111 + [
  112 + 'catalog/product',
  113 + 'product' => $model->lang->alias,
  114 + 'variant' => $variant->sku,
  115 + ],
  116 + [
  117 + 'class' => 'style title_cat',
  118 + 'data-pjax' => 0,
  119 + 'title' => $model->lang->title,
  120 + ]
  121 + );
  122 + ?>
  123 + <p class="style category_cat">
  124 + <?php
  125 + echo !empty($model->brand) ?$model->brand->lang->title:'';
  126 + ?>
  127 + </p>
  128 + <div class="style price_cat">
  129 + <?php
  130 + if (!empty( $variant->price_old )) {
  131 + ?>
  132 + <p>
  133 + <span class="price_cat-sale"><?php echo $variant->price_old; ?> <?= \Yii::t('app', 'hrn') ?></span>
  134 + <?php
  135 + echo $variant->price;
  136 + ?>
  137 + <span> ะณั€ะฝ.</span>
  138 + </p>
  139 + <div class="price_cat-sale_">
  140 + -<?php echo round(100 - ( $variant->price * 100 / $variant->price_old )); ?> %
  141 + </div>
  142 + <?php
  143 + } else {
  144 + ?>
  145 + <p>
  146 + <?php
  147 + echo $variant->price;
  148 + ?>
  149 + <span> <?= \Yii::t('app', 'hrn') ?></span>
  150 + </p>
  151 + <?php
  152 + }
  153 + ?>
  154 + </div>
  155 + <div class="style buttons_cat-wr">
  156 + <div class="buttons_cat">
  157 + <?php
  158 +
  159 + echo Html::a(
  160 + \Yii::t('app', 'ะŸะพะดั€ะพะฑะฝะตะต'),
28 [ 161 [
29 'catalog/product', 162 'catalog/product',
30 - 'product' => $product->lang->alias, 163 + 'product' => $model->lang->alias,
  164 + 'variant' => $variant->sku,
  165 + ],
  166 + [
  167 + 'class' => 'btn_view_cat',
  168 + 'data-pjax' => 0,
31 ] 169 ]
32 - ) ?>">  
33 - <?= ArtboxImageHelper::getImage(  
34 - $product->enabledVariants[ 0 ]->imageUrl,  
35 - 'list',  
36 - [  
37 - 'alt' => $product->category->lang->title . ' ' . $product->fullname,  
38 - 'title' => $product->category->lang->title . ' ' . $product->fullname,  
39 - 'class' => 'selected',  
40 - ]  
41 - ) ?> 170 + );
  171 + ?>
  172 + <a class="btn_buy_cat<?php echo( $variant->stock ? '' : ' disabled' ); ?>" href="#" data-variant="<?php echo $variant->id; ?>">
  173 + <?php
  174 + if ($variant->stock) {
  175 + ?>
  176 + <p><?= \Yii::t('app', 'buy') ?></p>
  177 + <?= \Yii::t('app', 'span_buy') ?>
  178 + <?php
  179 + } else {
  180 + echo \Yii::t('app', 'ะะตั‚ ะฒ ะฝะฐะปะธั‡ะธะธ');
  181 + }
  182 + ?>
42 </a> 183 </a>
43 - <div class="info_icons">  
44 - <a href="#" class="btn buy_button" data-toggle="modal" data-target="#buyForm" data-id="<?= $product->variant->id; ?>" lang="145">ะšัƒะฟะธั‚ัŒ</a>  
45 - <ul class="ul wishlike_block hidden">  
46 - <li class="compare hidden">  
47 - <a onclick="add2compare(); return false;" class="compare compare_text_link_3631483" href="#">ะš ัั€ะฐะฒะฝะตะฝะธัŽ</a>  
48 - <span class="icon"></span>  
49 - </li>  
50 - <li class="like hidden">  
51 - <a class="like like_text_link_3631483" href="#">ะ’ ะธะทะฑั€ะฐะฝะฝะพะต</a><span class="icon"></span>  
52 - </li>  
53 - </ul>  
54 - </div>  
55 </div> 184 </div>
56 - <div class="price">  
57 - <div class="dlexfduinxipi">  
58 - ะฆะตะฝะฐ:  
59 - <span class="main">  
60 - <?= $product->variant->price ?>  
61 - <span class="currency">ะณั€ะฝ</span>  
62 - </span>  
63 - </div>  
64 - </div>  
65 - <div class="additional_info params">  
66 - <div class="block_title">ะžัะพะฑะตะฝะฝะพัั‚ะธ</div>  
67 - <div class="descr">  
68 - <div class="info">  
69 - <ul class="sv">  
70 -  
71 - <li><span>ะ‘ั€ะตะฝะด:</span> <?= $product->brand->lang->title ?></li>  
72 -  
73 - <?php foreach ($product->getProperties() as $group): ?>  
74 - <li>  
75 - <span><?= $group->lang->title ?> <?php foreach ( $group->customOptions as $option ) : ?>&nbsp;</span><?= $option->lang->value ?><?php endforeach ?>  
76 - </li>  
77 - <?php endforeach; ?>  
78 -  
79 -  
80 - </ul>  
81 - </div>  
82 - <div class="clearfix"></div>  
83 - </div>  
84 - <div class="price" style="display: none;">  
85 - <div class="dlexfduinxipi">  
86 - ะฆะตะฝะฐ:  
87 - <span class="main"> 185 + </div>
  186 + </div>
  187 + <div class="additional_wr">
  188 + <div class="additional_bg">
  189 + <div class="addit_wr">
  190 + <div class="addit_bl"><?php
  191 + echo Html::a(
  192 + '',
  193 + [
  194 + 'catalog/product',
  195 + 'product' => $model->lang->alias,
  196 + 'variant' => $variant->sku,
  197 + '#' => 'video',
  198 + ],
  199 + [
  200 + 'class' => 'videos_btn' . ( empty( $model->videos ) ? ' disabled' : '' ),
  201 + ]
  202 + )
  203 + ?></div>
  204 + <div class="addit_bl">
  205 + <div class="slider_cat-wr">
  206 + <ul style="top:0" class="<?php
  207 + if (count($imageMap) > 3) {
  208 + echo "jcarousel jcarousel-skin-tango";
  209 + } else {
  210 + echo "not-carousel";
  211 + }
  212 + ?>">
88 <?php 213 <?php
89 -  
90 - echo '<div class="cost-block" itemprop="offers" itemscope itemtype="http://schema.org/Offer">';  
91 -  
92 - // ะตัั‚ัŒ ัะบะธะดะบะฐ  
93 - echo '<p class="cost">';  
94 - if ($product->enabledVariants[ 0 ]->price_old != 0 && $product->enabledVariants[ 0 ]->price_old != $product->enabledVariants[ 0 ]->price) {  
95 - echo '<strike><span id=\'old_cost\' itemprop="price">' . $product->enabledVariants[ 0 ]->price_old . '</span> ะณั€ะฝ.</strike>&nbsp;';  
96 - echo $product->enabledVariants[ 0 ]->price . ' <span>ะณั€ะฝ.</span></p>';  
97 - } else {  
98 - echo '<span itemprop="price">' . $product->enabledVariants[ 0 ]->price . ' </span><span>ะณั€ะฝ.</span></p>'; 214 + foreach ($imageMap as $item) {
  215 + if (!empty( $item )) {
  216 + echo Html::tag(
  217 + 'li',
  218 + Html::a(
  219 + ArtboxImageHelper::getImage(
  220 + '/storage/white.jpg',
  221 + 'category_thumb',
  222 + [
  223 + 'alt' => $model->lang->title,
  224 + 'title' => $model->lang->title,
  225 + 'class' => 'artbox-lazy-event',
  226 + 'data-original' => ArtboxImageHelper::getImageSrc(current($item), 'category_thumb', null, 90),
  227 + ],
  228 + 10
  229 + ),
  230 + [
  231 + 'catalog/product',
  232 + 'product' => $model->lang->alias,
  233 + 'variant' => key($item),
  234 + ],
  235 + [
  236 + 'data-pjax' => 0,
  237 + ]
  238 + )
  239 + );
99 } 240 }
100 - echo '<meta itemprop="priceCurrency" content = "UAH">';  
101 - echo '</div>';  
102 - 241 + }
103 ?> 242 ?>
104 - </span> 243 + </ul>
  244 + </div>
  245 + </div>
  246 + <div class="addit_bl">
  247 + <div class="style addit_buttons">
  248 + <?php
  249 + /*
  250 + ?>
  251 + <div><a class="btn_aside" href="#">ะพั‚ะปะพะถะธั‚ัŒ</a></div>
  252 + <div><a class="btn_compare" href="#">ัั€ะฐะฒะฝะธั‚ัŒ</a></div>
  253 + */
  254 + ?>
105 </div> 255 </div>
106 </div> 256 </div>
107 </div> 257 </div>
108 - <div class="opacity_bg"></div>  
109 </div> 258 </div>
110 </div> 259 </div>
111 -</div>  
112 \ No newline at end of file 260 \ No newline at end of file
  261 + <?php $this->endCache(); }?>
113 \ No newline at end of file 262 \ No newline at end of file
widgets/views/products_block.php
1 <?php 1 <?php
2 - use artweb\artbox\ecommerce\models\Product;  
3 - use yii\web\View;  
4 -  
5 - /**  
6 - * @var Product[] $products  
7 - */  
8 -?>  
9 -<?php if(!empty( $products )) { ?>  
10 - <div class="_prd_spec-wr">  
11 - <div class="special-products products<?= ( !empty( $class ) ? ' ' . $class : '' ) ?>">  
12 - <span style="text-align: center;  
13 - text-transform: uppercase;  
14 - font-size: 20px; display: block;  
15 - -webkit-margin-before: 1em;  
16 - -webkit-margin-after: 1em;  
17 - -webkit-margin-start: 0;  
18 - -webkit-margin-end: 0;  
19 - font-weight: bold;"><?= $title ?></span>  
20 - <div id="<?= $class ?>">  
21 - <?php foreach($products as $product) : ?>  
22 - <?= $this->render('product_smart', [ 'product' => $product ]); ?>  
23 - <?php endforeach ?> 2 +if (!empty($products)) {
  3 + ?>
  4 + <div class="style slider-wr">
  5 + <div class="container">
  6 + <div class="row">
  7 + <div class="col-xs-12" style="padding: 0;">
  8 + <div class="style title_slider">
  9 + <span><?= \Yii::t('app', $title) ?></span>
  10 + <div class="customNavigation">
  11 + <div class="prev_btn"></div>
  12 + <div class="next_btn"></div>
  13 + </div>
  14 + </div>
  15 + <div class="style slider_">
  16 + <div class="owl-carousel">
  17 + <?php
  18 + foreach ($products as $item) {
  19 + echo \yii\helpers\Html::tag(
  20 + 'div',
  21 + $this->render(
  22 + 'product_smart',
  23 + [
  24 + 'model' => $item,
  25 + ]
  26 + ),
  27 + [
  28 + 'class' => 'catalog-wr',
  29 + ]
  30 + );
  31 + }
  32 + ?>
  33 + </div>
  34 + </div>
  35 + </div>
24 </div> 36 </div>
25 - <div class="both"></div>  
26 </div> 37 </div>
27 </div> 38 </div>
28 - <?php $js = "$('#$class').owlCarousel({  
29 -navigation:true,  
30 -navigationText: []  
31 -})  
32 -";  
33 - $this->registerJs($js, View::POS_READY);  
34 - ?>  
35 -<?php } ?>  
36 \ No newline at end of file 39 \ No newline at end of file
  40 + <?php
  41 +}
  42 +?>
37 \ No newline at end of file 43 \ No newline at end of file