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
 public static function handleSaveDelivery(OrderCalculateEvent $event)
 {
     if (OrderCalculateEvent::BEFORE_CALCULATE !== $event->state) {
         return null;
     }
     $deliveryInformation = $event->order->orderDeliveryInformation;
     $shippingOption = $event->order->shippingOption;
     $special_price_list = SpecialPriceList::find()->where(['handler' => 'getDeliveryPriceOrder', 'object_id' => $event->order->object->id])->one();
     if (null !== $deliveryInformation && null !== $shippingOption) {
         SpecialPriceObject::setObject($special_price_list->id, $event->order->id, $shippingOption->cost, $shippingOption->name);
     } else {
         SpecialPriceObject::deleteAll(['special_price_list_id' => $special_price_list->id, 'object_model_id' => $event->order->id]);
     }
 }