Blame view

common/modules/product/widgets/specialProducts.php 1.16 KB
dc2cd017   Karnovsky A   -
1
2
3
4
5
6
7
8
9
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
  <?php
  
  namespace common\modules\product\widgets;
  
  use common\modules\product\helpers\ProductHelper;
  use common\modules\product\models\Category;
  use yii\base\Widget;
  use Yii;
  
  class specialProducts extends Widget {
      public $type = 'top';
  
      public $count = 4;
  
      public $sort = 'default';
  
      public $title;
  
      public function init()
      {
          parent::init(); // TODO: Change the autogenerated stub
      }
  
      public function run() {
          $products = ProductHelper::getSpecialProducts($this->type, $this->count, $this->sort);
  
          if (!$this->title) {
              switch($this->type) {
                  case 'top':
                      $this->title = Yii::t('product', 'Top products');
                      break;
                  case 'promo':
                      $this->title = Yii::t('product', 'Promo products');
                      break;
                  case 'new':
                      $this->title = Yii::t('product', 'New products');
                      break;
              }
          }
  
          return $this->render('products_block', [
              'title' => $this->title,
060b4806   Karnovsky A   -
43
              'class' => $this->type,
dc2cd017   Karnovsky A   -
44
45
46
47
              'products' => $products,
          ]);
      }
  }