public function getPrice($type = 'lower') { $price = $this->hasOne(Price::className(), ['product_id' => 'product_id']); if ($type == 'lower') { $price = $price->orderBy('price ASC')->one(); } elseif ($type) { $price = $price->where(['type_id' => $type])->one(); } elseif ($defaultType = yii::$app->getModule('shop')->getPriceTypeId($this)) { $price = $price->where(['type_id' => $defaultType])->one(); } else { $price = $price->orderBy('price DESC')->one(); } if ($price) { return $price->price; } return null; }
public function getPrices() { $return = $this->hasMany(Price::className(), ['product_id' => 'id'])->orderBy('price ASC'); return $return; }