add frontend changes
This commit is contained in:
@@ -7,8 +7,16 @@ use common\models\Account;
|
||||
use common\models\Discount;
|
||||
use common\models\Transfer;
|
||||
use common\models\UserSoldItem;
|
||||
use common\models\ShoppingCart;
|
||||
use yii\base\Object;
|
||||
|
||||
/**
|
||||
* @property $cart string name of cart, into we put the ticket
|
||||
* @property $userCart common\models\Transfer[] items in user cart
|
||||
* @property $customerCart common\models\Transfer[] items in customer cart
|
||||
* @property $customer common\models\Customer selected customer
|
||||
*
|
||||
* */
|
||||
class TicketCreate extends Ticket{
|
||||
|
||||
public $_currency;
|
||||
@@ -16,6 +24,12 @@ class TicketCreate extends Ticket{
|
||||
public $_discount;
|
||||
public $_transfer;
|
||||
|
||||
|
||||
public $customer;
|
||||
public $userCart;
|
||||
public $customerCart;
|
||||
|
||||
|
||||
public $cart;
|
||||
|
||||
public function rules()
|
||||
@@ -88,14 +102,15 @@ class TicketCreate extends Ticket{
|
||||
|
||||
public function afterSave($insert, $changedAttributes){
|
||||
$this->addTransfer();
|
||||
$this->addToCart();
|
||||
$this->appendToUserCart();
|
||||
$this->appendToCustomerCart();
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected function addTransfer(){
|
||||
$transfer = Transfer::createTicketTransfer($this->_account, $this->_discount, null, 1, $this);
|
||||
$transfer->status = Transfer::STATUS_PAID;
|
||||
// $transfer->status = Transfer::STATUS_PAID;
|
||||
if ( isset($this->comment)){
|
||||
$transfer->comment = $this->comment;
|
||||
}
|
||||
@@ -114,12 +129,41 @@ class TicketCreate extends Ticket{
|
||||
}
|
||||
|
||||
|
||||
public function isAddToCart(){
|
||||
$result = false;
|
||||
if ( isset( $this->cart ) && $this->cart == 'add' ){
|
||||
$result = true;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user