[ 'name', 'phone', 'email', 'city', 'address', 'comment', ], self::SCENARIO_DELIVERY => [ 'delivery_id', ], self::SCENARIO_PAYMENT => [ 'payment_id', ], ] ); } /** * @inheritdoc */ public function rules() { return [ [ [ 'name', 'phone', 'email', 'delivery_id', 'payment_id', ], 'required', ], [ [ 'name', 'phone', 'email', 'city', 'address', ], 'string', 'max' => 255, ], [ [ 'comment', ], 'string', ], [ [ 'delivery_id', 'payment_id', ], 'integer', ], [ [ 'delivery_id', ], 'exist', 'targetClass' => Delivery::className(), 'targetAttribute' => 'id', ], [ [ 'payment_id', ], 'exist', 'targetClass' => Payment::className(), 'targetAttribute' => 'id', ], ]; } /** * Save active attributes to session variable 'order' */ public function saveActive() { $order = \Yii::$app->session->get('order', []); foreach ($this->activeAttributes() as $attribute) { $order[ $attribute ] = $this->getAttribute($attribute); } \Yii::$app->session[ 'order' ] = $order; } /** * Load active attributes from session variable 'order' */ public function loadActive() { $order = \Yii::$app->session->get('order'); if (!empty($order)) { foreach ($this->activeAttributes() as $attribute) { if (!empty($order[ $attribute ])) { $this->setAttribute($attribute, $order[ $attribute ]); } } } } }