add customer cart
This commit is contained in:
@@ -9,7 +9,7 @@ use Yii;
|
||||
*
|
||||
* @property integer $id_shopping_cart
|
||||
* @property integer $id_customer
|
||||
* @property integer $id_sale
|
||||
* @property integer $id_transfer
|
||||
*/
|
||||
class ShoppingCart extends \yii\db\ActiveRecord
|
||||
{
|
||||
@@ -27,7 +27,7 @@ class ShoppingCart extends \yii\db\ActiveRecord
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_customer', 'id_sale'], 'integer']
|
||||
[['id_customer', 'id_transfer'], 'integer']
|
||||
];
|
||||
}
|
||||
|
||||
@@ -39,28 +39,43 @@ class ShoppingCart extends \yii\db\ActiveRecord
|
||||
return [
|
||||
'id_shopping_cart' => Yii::t('common/shopping-cart', 'Id Shopping Cart'),
|
||||
'id_customer' => Yii::t('common/shopping-cart', 'Id Customer'),
|
||||
'id_sale' => Yii::t('common/shopping-cart', 'Id Sale'),
|
||||
'id_transfer' => Yii::t('common/shopping-cart', 'Id Transfer'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getSale(){
|
||||
$this->hasOne(Sale::className(), ['id_sale' => 'id_sale']);
|
||||
public function getTransfer(){
|
||||
return $this->hasOne(Transfer::className(), ['id_transfer' => 'id_transfer']);
|
||||
}
|
||||
public function getProduct(){
|
||||
$this->hasOne(Product::className(), ['id_product' => 'id_product'])->via('sale');
|
||||
return $this->hasOne(Product::className(), ['id_product' => 'id_product'])->via('transfer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $customer common\models\Customer
|
||||
* */
|
||||
public static function readCustomerCart($customer = null){
|
||||
$sales = [];
|
||||
$transfers = [];
|
||||
if ( isset($customer)){
|
||||
$query = ShoppingCart::find()->andWhere( ['id_customer' => $customer->id_customer] );
|
||||
$query->with('product');
|
||||
$sales = $query->all();
|
||||
$transfers = $query->all();
|
||||
}
|
||||
return $sales;
|
||||
return $transfers;
|
||||
}
|
||||
|
||||
public static function payout( $customer) {
|
||||
//apply transfer object
|
||||
//delete cart
|
||||
$sql = "UPDATE transfer AS t
|
||||
INNER JOIN shopping_cart AS s ON t.id_transfer = s.id_transfer
|
||||
SET t.status = " . Transfer::STATUS_PAID
|
||||
. " WHERE t.status = " . Transfer::STATUS_NOT_PAID;
|
||||
|
||||
$q1 = Yii::$app->db->createCommand($sql);
|
||||
$q1->execute();
|
||||
|
||||
ShoppingCart::deleteAll(['id_customer' => $customer->id_customer]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -144,6 +144,10 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
return $this->hasOne( UserSoldItem::className(), ["id_transfer" =>"id_transfer" ] );
|
||||
}
|
||||
|
||||
public function getCustomerCart(){
|
||||
return $this->hasOne( ShoppingCart::className(), ["id_transfer" =>"id_transfer" ] );
|
||||
}
|
||||
|
||||
public function getSale(){
|
||||
return $this->hasOne( Sale::className(), ["id_sale" =>"id_object" ] ) ;
|
||||
}
|
||||
@@ -398,6 +402,18 @@ class Transfer extends \common\models\BaseFitnessActiveRecord
|
||||
|
||||
return $transfers;
|
||||
}
|
||||
public static function readCustomerCart($customer){
|
||||
$transfers = [];
|
||||
|
||||
if ( isset($customer) ){
|
||||
$query = Transfer::find();
|
||||
$query->innerJoinWith('customerCart');
|
||||
$query->andWhere(['shopping_cart.id_customer' => $customer->id_customer ]);
|
||||
$transfers = $query->all();
|
||||
}
|
||||
|
||||
return $transfers;
|
||||
}
|
||||
|
||||
public static function types( ) {
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user