sell product list

This commit is contained in:
2015-10-05 17:24:26 +02:00
parent 203dfeac72
commit 2610749305
15 changed files with 373 additions and 40 deletions

View File

@@ -12,6 +12,7 @@ use yii\base\Object;
use common\models\Account;
use common\models\Discount;
use common\models\Currency;
use common\models\UserSoldItem;
/**
* ContactForm is the model behind the contact form.
@@ -19,6 +20,8 @@ use common\models\Currency;
class ProductSaleForm extends Model
{
public $append_to_sold_list;
public $id_product;
public $count;
public $id_currency;
@@ -51,11 +54,13 @@ class ProductSaleForm extends Model
[['id_product','count','id_account'], 'required'],
[['id_product','id_currency','id_account', 'id_discount','count'], 'integer'],
[['comment'], 'string' ,'max' => 255],
[['append_to_sold_list'], 'string' ,'max' => 10],
[['id_product' ], 'validateProduct'],
[['count' ], 'validateCount'],
[['id_currency' ], 'validateCurrency'],
[['id_account' ], 'validateAccount'],
[['id_discount' ], 'validateDiscount'],
[['id_discount' ], 'validateDiscount'],
];
}
@@ -114,6 +119,7 @@ class ProductSaleForm extends Model
if ( $this->validate() ){
$this->saveTransfer();
$this->saveProduct();
$this->appendToSoldList();
return true;
}
return false;
@@ -137,4 +143,20 @@ class ProductSaleForm extends Model
$this->product->save();
}
public function isAppendToList(){
$result = false;
if ( isset( $this->append_to_sold_list ) && $this->append_to_sold_list == 'append' ){
$result = true;
}
return $result;
}
public function appendToSoldList(){
if ( $this->isAppendToList() ){
$item = new UserSoldItem();
$item->id_transfer = $this->transfer->id_transfer;
$item->id_user = Yii::$app->user->id;
$item->save(false);
}
}
}