Blame view

common/modules/product/widgets/specialProducts.php 1.33 KB
d8c1a2e0   Yarik   Big commit artbox
1
  <?php
5c2eb7c8   Yarik   Big commit almost...
2
3
4
5
6
7
8
9
      
      namespace common\modules\product\widgets;
      
      use common\modules\product\helpers\ProductHelper;
      use yii\base\Widget;
      use Yii;
      
      class specialProducts extends Widget
d8c1a2e0   Yarik   Big commit artbox
10
      {
5c2eb7c8   Yarik   Big commit almost...
11
12
13
14
15
          
          public $type = 'top';
          
          public $count = 8;
          
5c2eb7c8   Yarik   Big commit almost...
16
17
18
19
20
21
22
23
24
          public $title;
          
          public function init()
          {
              parent::init();
          }
          
          public function run()
          {
772a3ca4   Yarik   Big commit
25
              $products = ProductHelper::getSpecialProducts($this->type, $this->count);
5c2eb7c8   Yarik   Big commit almost...
26
              
772a3ca4   Yarik   Big commit
27
28
              if (!$this->title) {
                  switch ($this->type) {
5c2eb7c8   Yarik   Big commit almost...
29
30
31
32
33
34
35
36
37
38
                      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;
                  }
d8c1a2e0   Yarik   Big commit artbox
39
              }
5c2eb7c8   Yarik   Big commit almost...
40
              
772a3ca4   Yarik   Big commit
41
42
43
44
45
46
47
48
              return $this->render(
                  'products_block',
                  [
                      'title'    => $this->title,
                      'class'    => $this->type,
                      'products' => $products,
                  ]
              );
d8c1a2e0   Yarik   Big commit artbox
49
          }
772a3ca4   Yarik   Big commit
50
51
      }