specialProducts.php 1.19 KB
<?php

namespace common\modules\product\widgets;

use common\modules\product\helpers\ProductHelper;
use common\modules\product\models\Category;
use common\modules\product\models\Product;
use common\modules\product\models\ProductVariant;
use yii\base\Widget;
use Yii;

class specialProducts extends Widget {
    public $type = 'is_new';

    public $count = 4;

    public $sort = 'default';

    public $title;

    public $classs;

    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 'is_top':
                    $this->title = Yii::t('product', 'Top products');
                    break;
                case 'is_new':
                    $this->title = Yii::t('product', 'New products');
                    break;
            }
        }

        return $this->render('products_block', [
            'title' => $this->title,
            'class' => $this->classs ? $this->classs : $this->type,
            'products' => $products,
        ]);
    }
}