add customer cart

This commit is contained in:
2015-10-21 17:57:16 +02:00
parent baf7c79d04
commit 23a0390a27
14 changed files with 467 additions and 16 deletions

View File

@@ -13,6 +13,8 @@ use common\models\Account;
use common\models\Discount;
use common\models\Currency;
use common\models\UserSoldItem;
use common\models\Sale;
use common\models\ShoppingCart;
/**
* ContactForm is the model behind the contact form.
@@ -42,8 +44,12 @@ class ProductSaleForm extends Model
public $account;
public $currency;
public $discount;
public $customer;
public $transfer;
public $sale;
public $customerCart;
/**
* @inheritdoc
@@ -121,21 +127,32 @@ class ProductSaleForm extends Model
public function save(){
if ( $this->validate() ){
$this->saveSale();
$this->saveTransfer();
$this->saveProduct();
$this->appendToSoldList();
$this->appendToUserCart();
$this->appendToCustomerCart();
return true;
}
return false;
}
// protected function applyDiscount(){
// Discount::applyDiscount($this->, $discount);
// }
protected function saveSale(){
$this->sale = Sale::createSale($this->account, $this->discount, $this->currency, $this->count, $this->product);
/*
*/
$this->sale->status = Sale::STATUS_PAID;
if ( isset($this->comment)){
$this->sale->comment = $this->comment;
}
$this->sale->id_user = Yii::$app->user->id;
$this->sale->save();
}
protected function saveTransfer(){
$this->transfer = Transfer::createProductTransfer($this->account, $this->discount, $this->currency, $this->count, $this->product);
$this->transfer = Transfer::createProductTransfer($this->sale,$this->account, $this->discount, $this->currency, $this->count, $this->product);
/*
*/
$this->transfer->status = Transfer::STATUS_PAID;
@@ -151,7 +168,7 @@ class ProductSaleForm extends Model
$this->product->save();
}
public function isAppendToList(){
public function isAppendToUserCart(){
$result = false;
if ( isset( $this->append_to_sold_list ) && $this->append_to_sold_list == 'append' ){
$result = true;
@@ -159,12 +176,28 @@ class ProductSaleForm extends Model
return $result;
}
public function appendToSoldList(){
if ( $this->isAppendToList() ){
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 isAppendToCustomerCart(){
$result = false;
if ( isset( $this->add_to_customer ) && $this->add_to_customer == 'append' ){
$result = true;
}
return $result;
}
public function appendToCustomerCart(){
if ( $this->isAppendToCustomerCart() && isset($this->customer) ){
$item = new ShoppingCart();
$item->id_customer = $this->customer->id_customer;
$item->id_sale = $this->sale->id_sale;
$item->save(false);
}
}
}