/var/www/vhosts/nabawater/api/modules/v1/models
Edit: /var/www/vhosts/nabawater/api/modules/v1/models/Item.php (4786B)
function ($model) {
return $model->is_offer == Item::ACTIVE ? 1 : 0;
},
'orginal_price' => function ($model) {
return $model->orginal_price != null ? $model->orginal_price : 0;
},
'item_price',
'item_name',
'item_description',
'item_size',
'unit_name',
'item_purchase_type',
'item_short_desc' => function (self $model) {
return $model->item_short_desc != null ? $model->item_short_desc : '';
},
'item_image' => function ($model){
return ItemImage::find()
->where([
'item_id' => $model->getPrimaryKey(),
// 'language_code' => \Yii::$app->language,
])->all();
},
'is_offer_tag' => function (self $model) {
return $model->promotion_count != 0 ? 1 : 0;
},
'is_user_fav' => function (self $model) {
return ($model->is_user_fav != 0 ? 1 : 0);
},
'number_user_rating' => function (self $model) {
return BranchReview::find()->where(['item_id' => $model->getPrimaryKey(), 'status' => self::ACTIVE])->count();
},
'rating' => function (self $model) {
$modelAvg = BranchReview::find()
->select(['Avg(rating) as rating'])
->where([
'item_id' => $model->item_id,
'status' => BranchReview::STATUS_APPROVED
])
->groupBy('item_id')
->one();
return (isset($modelAvg->rating) ? number_format($modelAvg->rating, 2) : '0');
},
'review' => function (self $model) {
return BranchReview::find()
->where([
'item_id' => $model->item_id,
'status' => BranchReview::STATUS_APPROVED,
])->all();
},
'quantity',
'category_id',
'category_name',
'is_refund_bottle',
];
}
/**
* @return array
*/
public function fieldsScenarios(): array
{
$fieldsScenarios = parent::fieldsScenarios();
$fieldsScenarios[self::ITEM_LISTING] =
[
'item_key',
'is_offer',
'orginal_price',
'item_price',
'item_name',
'item_size',
'unit_name',
'item_short_desc',
'item_image',
];
return $fieldsScenarios;
}
/**
*
* @return array
*/
public function getItemImages()
{
return $this->hasMany(ItemImage::className(), ['item_id' => 'item_id'])
->where(['language_code' => Yii::$app->language]);
}
/**
*
* @return array
*/
public function getItemsIngredientGroup()
{
$model = ItemIngredientGroup::find()->alias('IIG')
->select(['IIG.*'])
->leftJoin(['IMG'=> ItemMappingGroup::tableName()],
'IMG.item_ingredient_group_id = IIG.item_ingredient_group_id')
->leftJoin(['IM' => ItemMapping::tableName()],
'IM.item_mapping_id = IMG.item_mapping_id')
->where([
'IM.item_id' => $this->item_id,
'IIG.item_ingredient_status' => Item::ACTIVE,
'IM.item_mapping_status' => ItemMapping::ACTIVE
]);
ItemIngredientGroup::selectTranslation($model);
return $model;
}
/**
*
* @return array
*/
public function getItemType()
{
$model = ItemType::find()->alias('IT')
->select(['IT.*'])
->leftJoin(['ITD' => ItemTypeDetails::tableName()],
'IT.item_type_id = ITD.item_type_id')
->where(['ITD.item_id' => $this->item_id]);
ItemType::selectTranslation($model);
return $model;
}
}