ShopDelivery.php 3.66 KB
Newer Older
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 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
<?php
/**
 * @author Semenov Alexander <semenov@skeeks.com>
 * @link http://skeeks.com/
 * @copyright 2010 SkeekS (СкикС)
 * @date 02.04.2015
 */
namespace skeeks\modules\cms\shop\models;
use skeeks\cms\models\behaviors\HasStatus;
use skeeks\cms\models\behaviors\HasStatusBoolean;
use skeeks\cms\models\Core;
use \Yii;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%shop_delivery}}".
 *
 * @property integer $id
 * @property integer $created_by
 * @property integer $updated_by
 * @property integer $created_at
 * @property integer $updated_at
 * @property string $currency
 * @property string $name
 * @property string $description
 * @property integer $period_from
 * @property integer $period_to
 * @property string $period_type
 * @property integer $weight_from
 * @property integer $weight_to
 * @property string $order_price_from
 * @property string $order_price_to
 * @property string $order_currency
 * @property integer $status
 * @property string $price
 *
 * @property CmsUser $updatedBy
 * @property CmsUser $createdBy
 */
class ShopDelivery extends Core
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%shop_delivery}}';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            HasStatusBoolean::className() =>
            [
                'class' => HasStatusBoolean::className(),
            ]
        ]);
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return array_merge(parent::attributeLabels(), [
            'id' => Yii::t('app', 'ID'),
            'created_by' => Yii::t('app', 'Created By'),
            'updated_by' => Yii::t('app', 'Updated By'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'currency' => Yii::t('app', 'Currency'),
            'name' => Yii::t('app', 'Name'),
            'description' => Yii::t('app', 'Description'),
            'period_from' => Yii::t('app', 'Period From'),
            'period_to' => Yii::t('app', 'Period To'),
            'period_type' => Yii::t('app', 'Period Type'),
            'weight_from' => Yii::t('app', 'Weight From'),
            'weight_to' => Yii::t('app', 'Weight To'),
            'order_price_from' => Yii::t('app', 'Order Price From'),
            'order_price_to' => Yii::t('app', 'Order Price To'),
            'order_currency' => Yii::t('app', 'Order Currency'),
            'status' => Yii::t('app', 'Status'),
            'price' => Yii::t('app', 'Price'),
        ]);
    }

    public function scenarios()
    {
        $scenarios = parent::scenarios();

        $scenarios[self::SCENARIO_DEFAULT];

        $scenarios['create'] = $scenarios[self::SCENARIO_DEFAULT];
        $scenarios['update'] = $scenarios[self::SCENARIO_DEFAULT];

        return $scenarios;
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return array_merge(parent::rules(), [
            [['created_by', 'updated_by', 'created_at', 'updated_at', 'period_from', 'period_to', 'weight_from', 'weight_to', 'status'], 'integer'],
            [['name'], 'required'],
            [['description'], 'string'],
            [['order_price_from', 'order_price_to', 'price'], 'number'],
            [['currency', 'order_currency'], 'string', 'max' => 3],
            [['name'], 'string', 'max' => 255],
            [['period_type'], 'string', 'max' => 1]
        ]);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getShopOrders()
    {
        return $this->hasMany(ShopOrder::className(), ['person_type_id' => 'id']);
    }
}