/**
  * @return \yii\db\ActiveQuery
  */
 public function getShopProductPrice()
 {
     return $this->hasOne(ShopProductPrice::className(), ['id' => 'shop_product_price_id']);
 }
Example #2
0
 /**
  *
  * Лучшая цена по которой может купить этот товар пользователь, среди всех доступных
  * Операемся на курс
  *
  * @param null $shopFuser
  * @return $this
  */
 public function getMinProductPrice($shopFuser = null)
 {
     if ($shopFuser === null) {
         $shopFuser = \Yii::$app->shop->shopFuser;
     }
     return $this->hasOne(ShopProductPrice::className(), ['product_id' => 'id'])->select(['shop_product_price.*', 'realPrice' => '( (SELECT course FROM `money_currency` WHERE `money_currency`.`code` = `shop_product_price`.`currency_code`) * `shop_product_price`.`price` )'])->leftJoin('money_currency', '`money_currency`.`code` = `shop_product_price`.`currency_code`')->orWhere(['and', ['>', 'price', 0], ['type_price_id' => ArrayHelper::map($shopFuser->buyTypePrices, 'id', 'id')]])->orWhere(['type_price_id' => \Yii::$app->shop->baseTypePrice->id])->orderBy(['realPrice' => SORT_ASC]);
 }