Esempio n. 1
0
 public static function getOrderPrice(Order $order, $type = null)
 {
     $price = 0;
     foreach ($order->items as $item) {
         $price += $item->total_price;
     }
     $cacheKey = 'PriceHelper::getOrderPrice' . json_encode([$order->object->id, $type]);
     if (!($specialPriceList = Yii::$app->cache->get($cacheKey))) {
         $specialPriceListQuery = SpecialPriceList::find()->where(['object_id' => $order->object->id])->orderBy(['sort_order' => SORT_ASC]);
         if ($type !== null) {
             $specialPriceListQuery->andWhere(['type' => $type]);
         }
         $specialPriceList = $specialPriceListQuery->all();
         Yii::$app->cache->set($cacheKey, $specialPriceList, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(SpecialPriceList::className())]]));
     }
     foreach ($specialPriceList as $specialPriceRow) {
         $class = $specialPriceRow->class;
         $handler = $specialPriceRow->handler;
         $price = $class::$handler($order, $specialPriceRow, $price);
     }
     return round($price, 2);
 }
Esempio n. 2
0
 /**
  * @return SpecialPriceList|null
  */
 public function getSpecialPriceList()
 {
     return $this->hasOne(SpecialPriceList::className(), ['id' => 'special_price_list_id']);
 }