Blame view

widgets/views/product_smart.php 9.04 KB
2f25da09   Yarik   first commit
1
  <?php
4e03534e   Administrator   add similar products
2
3
4
5
6
7
8
  /**
   * @var $model  Product
   */
  use artweb\artbox\components\artboximage\ArtboxImageHelper;
  use artweb\artbox\ecommerce\models\Product;
  use yii\bootstrap\Html;
  use yii\helpers\ArrayHelper;
2f25da09   Yarik   first commit
9
  
4e03534e   Administrator   add similar products
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
  
  
  if($this->beginCache('_item_list'.$model->id,[
      'variations' => [\Yii::$app->language],
      'id' => $model->id,
      'duration' => 3600 *24
  ])){
  
  
      $fullname = $model->fullName;
      if(!empty($model->enabledVariants)) {
          $variant = $model->enabledVariants[ 0 ];
      } else {
          $variant = $model->variant;
      }
      $imageMap = ArrayHelper::map($model->enabledVariants, 'sku', 'images', 'lang.title');
      $firstImage = [
          'sku'   => $variant->sku,
          'image' => '',
      ];
  
      $firstIteration = true;
      foreach ($imageMap as $key => $item) {
          $imageMap[ $key ] = array_filter($item);
          foreach ($imageMap[ $key ] as $subKey => $subValue) {
              foreach ($subValue as $subSubValue) {
                  if (!empty( $subSubValue )) {
                      $imageMap[ $key ][ $subKey ] = $subSubValue->imageUrl;
                      if ($firstIteration) {
                          $firstImage = [
                              'sku'   => $subKey,
                              'image' => $subSubValue->imageUrl,
                          ];
                      }
                      $firstIteration = false;
                      break;
                  }
              }
          }
      }
      ?>
      <div class="item_catalog">
          <div class="bg-status">
              <?php
              if ($model->is_discount) {
                  echo Html::tag(
                      'div',
                      Html::tag('span', \Yii::t('app', 'акция')),
                      [
                          'class' => 'sale_bg',
                      ]
                  );
              }
              if ($model->is_top) {
                  echo Html::tag(
                      'div',
                      Html::tag('span', \Yii::t('app', 'top')),
                      [
                          'class' => 'top_bg',
                      ]
                  );
              }
              if ($model->is_new) {
                  echo Html::tag(
                      'div',
                      Html::tag('span', \Yii::t('app', 'new')),
                      [
                          'class' => 'new_bg',
                      ]
                  );
              }
              ?>
          </div>
          <div class="img style">
              <?php
              echo Html::a(
                  ArtboxImageHelper::getImage(
                      $firstImage[ 'image' ],
                      'category_item',
                      [
                          'alt'   => $fullname,
                          'title' => $fullname,
                      ],
                      90,
                      true
                  ),
                  [
                      'catalog/product',
                      'product' => $model->lang->alias,
                      'variant' => $firstImage[ 'sku' ],
                  ],
                  [
                      'data-pjax' => 0,
                      'title'     => $fullname,
                  ]
              );
              ?>
          </div>
          <?php
          echo Html::a(
              yii\helpers\StringHelper::truncate($fullname, 41),
              [
                  'catalog/product',
                  'product' => $model->lang->alias,
                  'variant' => $variant->sku,
              ],
              [
                  'class'     => 'style title_cat',
                  'data-pjax' => 0,
                  'title'     => $model->lang->title,
              ]
          );
          ?>
          <p class="style category_cat">
              <?php
              echo !empty($model->brand) ?$model->brand->lang->title:'';
              ?>
          </p>
          <div class="style price_cat">
              <?php
              if (!empty( $variant->price_old )) {
                  ?>
                  <p>
                      <span class="price_cat-sale"><?php echo $variant->price_old; ?> <?= \Yii::t('app', 'hrn') ?></span>
                      <?php
                      echo $variant->price;
                      ?>
                      <span> грн.</span>
                  </p>
                  <div class="price_cat-sale_">
                      -<?php echo round(100 - ( $variant->price * 100 / $variant->price_old )); ?> %
                  </div>
                  <?php
              } else {
                  ?>
                  <p>
                      <?php
                      echo $variant->price;
                      ?>
                      <span> <?= \Yii::t('app', 'hrn') ?></span>
                  </p>
                  <?php
              }
              ?>
          </div>
          <div class="style buttons_cat-wr">
              <div class="buttons_cat">
                  <?php
  
                  echo Html::a(
                      \Yii::t('app', 'Подробнее'),
2f25da09   Yarik   first commit
161
162
                      [
                          'catalog/product',
4e03534e   Administrator   add similar products
163
164
165
166
167
168
                          'product' => $model->lang->alias,
                          'variant' => $variant->sku,
                      ],
                      [
                          'class'     => 'btn_view_cat',
                          'data-pjax' => 0,
2f25da09   Yarik   first commit
169
                      ]
4e03534e   Administrator   add similar products
170
171
172
173
174
175
176
177
178
179
180
181
182
                  );
                  ?>
                  <a class="btn_buy_cat<?php echo( $variant->stock ? '' : ' disabled' ); ?>" href="#" data-variant="<?php echo $variant->id; ?>">
                      <?php
                      if ($variant->stock) {
                          ?>
                          <p><?= \Yii::t('app', 'buy') ?></p>
                          <?= \Yii::t('app', 'span_buy') ?>
                          <?php
                      } else {
                          echo \Yii::t('app', 'Нет в наличии');
                      }
                      ?>
2f25da09   Yarik   first commit
183
                  </a>
2f25da09   Yarik   first commit
184
              </div>
4e03534e   Administrator   add similar products
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
          </div>
      </div>
      <div class="additional_wr">
          <div class="additional_bg">
              <div class="addit_wr">
                  <div class="addit_bl"><?php
                      echo Html::a(
                          '',
                          [
                              'catalog/product',
                              'product' => $model->lang->alias,
                              'variant' => $variant->sku,
                              '#'       => 'video',
                          ],
                          [
                              'class' => 'videos_btn' . ( empty( $model->videos ) ? ' disabled' : '' ),
                          ]
                      )
                      ?></div>
                  <div class="addit_bl">
                      <div class="slider_cat-wr">
                          <ul style="top:0" class="<?php
                          if (count($imageMap) > 3) {
                              echo "jcarousel jcarousel-skin-tango";
                          } else {
                              echo "not-carousel";
                          }
                          ?>">
2f25da09   Yarik   first commit
213
                              <?php
4e03534e   Administrator   add similar products
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
                              foreach ($imageMap as $item) {
                                  if (!empty( $item )) {
                                      echo Html::tag(
                                          'li',
                                          Html::a(
                                              ArtboxImageHelper::getImage(
                                                  '/storage/white.jpg',
                                                  'category_thumb',
                                                  [
                                                      'alt'   => $model->lang->title,
                                                      'title' => $model->lang->title,
                                                      'class' => 'artbox-lazy-event',
                                                      'data-original' => ArtboxImageHelper::getImageSrc(current($item), 'category_thumb', null, 90),
                                                  ],
                                                  10
                                              ),
                                              [
                                                  'catalog/product',
                                                  'product' => $model->lang->alias,
                                                  'variant' => key($item),
                                              ],
                                              [
                                                  'data-pjax' => 0,
                                              ]
                                          )
                                      );
2f25da09   Yarik   first commit
240
                                  }
4e03534e   Administrator   add similar products
241
                              }
2f25da09   Yarik   first commit
242
                              ?>
4e03534e   Administrator   add similar products
243
244
245
246
247
248
249
250
251
252
253
254
                          </ul>
                      </div>
                  </div>
                  <div class="addit_bl">
                      <div class="style addit_buttons">
                          <?php
                          /*
                          ?>
                          <div><a class="btn_aside" href="#">отложить</a></div>
                          <div><a class="btn_compare" href="#">сравнить</a></div>
                          */
                          ?>
2f25da09   Yarik   first commit
255
256
257
                      </div>
                  </div>
              </div>
2f25da09   Yarik   first commit
258
259
          </div>
      </div>
4e03534e   Administrator   add similar products
260
      <?php $this->endCache(); }?>