255], ///////////////////// //cart ///////////////////// [['cart'], 'string', 'max' => 10] ]; } public function validateTicketType($attribute,$params){ $type = TicketType::findOne($this->id_ticket_type); if ( !isset($type)) { $this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid ticket type' )); } } public function validateAccount($attribute,$params){ $this->_account = Account::findOne($this->id_account); if ( !isset($this->_account )) { $this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid transfer' )); } } public function validateDiscount($attribute,$params){ $this->_discount = Discount::findOne($this->id_discount); if ( !isset($this->_discount)) { $this->addError($attribute,Yii::t('frontend/ticket' , 'Invalid discount' )); } } public function afterSave($insert, $changedAttributes){ $this->addTransfer(); $this->appendToUserCart(); $this->appendToCustomerCart(); } protected function addTransfer(){ $transfer = Transfer::createTicketTransfer($this->_account, $this->_discount, null, 1, $this); $status = Transfer::STATUS_PAID; if ( $this->isAppendToUserCart() ){ $status = Transfer::STATUS_NOT_PAID; }else if ( $this->isAppendToCustomerCart() ){ $status = Transfer::STATUS_NOT_PAID; $customer = $this->customer; }else { $status = Transfer::STATUS_PAID; $transfer->paid_at = date('Y-m-d H:i:s' ) ; } $transfer->status = $status; if ( isset($this->comment)){ $transfer->comment = $this->comment; } $transfer->id_user = \Yii::$app->user->id; $transfer->id_customer = $this->customer->id_customer; $transfer->save(); $this->_transfer = $transfer; } protected function addToCart(){ if ( $this->isAddToCart()){ $item = new UserSoldItem(); $item->id_transfer = $this->_transfer->id_transfer; $item->id_user = \Yii::$app->user->id; $item->save(false); } } public function isAppendToUserCart(){ $result = false; if ( isset( $this->cart ) && $this->cart == 'user' ){ $result = true; } return $result; } public function isAppendToCustomerCart(){ $result = false; if ( isset( $this->cart ) && $this->cart == 'customer' ){ $result = true; } return $result; } public function appendToUserCart(){ if ( $this->isAppendToUserCart() ){ $item = new UserSoldItem(); $item->id_transfer = $this->_transfer->id_transfer; $item->id_user = \Yii::$app->user->id; $item->save(false); } } public function appendToCustomerCart(){ if ( $this->isAppendToCustomerCart() && isset($this->customer) ){ $item = new ShoppingCart(); $item->id_customer = $this->customer->id_customer; $item->id_transfer = $this->_transfer->id_transfer; $item->save(false); } } }