add customer cart
This commit is contained in:
66
common/models/ShoppingCart.php
Normal file
66
common/models/ShoppingCart.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* This is the model class for table "shopping_cart".
|
||||
*
|
||||
* @property integer $id_shopping_cart
|
||||
* @property integer $id_customer
|
||||
* @property integer $id_sale
|
||||
*/
|
||||
class ShoppingCart extends \yii\db\ActiveRecord
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public static function tableName()
|
||||
{
|
||||
return 'shopping_cart';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
[['id_customer', 'id_sale'], 'integer']
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function attributeLabels()
|
||||
{
|
||||
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'),
|
||||
];
|
||||
}
|
||||
|
||||
public function getSale(){
|
||||
$this->hasOne(Sale::className(), ['id_sale' => 'id_sale']);
|
||||
}
|
||||
public function getProduct(){
|
||||
$this->hasOne(Product::className(), ['id_product' => 'id_product'])->via('sale');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $customer common\models\Customer
|
||||
* */
|
||||
public static function readCustomerCart($customer = null){
|
||||
$sales = [];
|
||||
if ( isset($customer)){
|
||||
$query = ShoppingCart::find()->andWhere( ['id_customer' => $customer->id_customer] );
|
||||
$query->with('product');
|
||||
$sales = $query->all();
|
||||
}
|
||||
return $sales;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user