fitness-web/common/models/ShoppingCart.php
2015-10-21 17:57:16 +02:00

67 lines
1.5 KiB
PHP

<?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;
}
}