public function actionIndex()
 {
     $data = Json::decode(Yii::$app->request->rawBody);
     if (is_array($data) === true) {
         // sort by event name
         $eventsNames = array_keys(array_reduce($data, function ($carry, $item) {
             if (isset($item['eventName'])) {
                 $carry[$item['eventName']] = 1;
             }
             return $carry;
         }, []));
         // preload all events into identity map
         Events::findByNames($eventsNames);
         // now we can handle it all
         foreach ($data as $eventItem) {
             if (isset($eventItem['eventName'], $eventItem['event'], $eventItem['timestamp']) === true) {
                 $eventModel = Events::findByName($eventItem['eventName']);
                 if ($eventModel !== null) {
                     $className = $eventModel->event_class_name;
                     $specialEvent = new $className($eventItem['event']);
                     EventTriggeringHelper::triggerSpecialEvent($specialEvent);
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param null $id
  * @return Response
  * @throws NotFoundHttpException
  * @throws \yii\base\Exception
  */
 public function actionStageLeaf($id = null)
 {
     if (empty($id)) {
         return $this->redirect(Url::to(['stage']));
     }
     /** @var OrderStageLeaf $orderStageLeaf */
     $orderStageLeaf = OrderStageLeaf::findOne(['id' => $id]);
     if (empty($orderStageLeaf)) {
         return $this->redirect(Url::to(['stage']));
     }
     $order = $this->loadOrder(false, false);
     if (empty($order)) {
         return $this->redirect(Url::to(['index']));
     }
     $orderStage = $order->stage;
     if ($orderStage->id !== $orderStageLeaf->stage_from_id && $orderStage->id !== $orderStageLeaf->stage_to_id) {
         return $this->redirect(Url::to(['stage']));
     }
     if (null !== Yii::$app->request->get('previous') && 1 !== intval($orderStageLeaf->stageFrom->immutable_by_user)) {
         $order->order_stage_id = $orderStageLeaf->stageFrom->id;
         $order->save();
     } else {
         /** @var Events $eventClassName */
         $eventClassName = Events::findByName($orderStageLeaf->event_name);
         if (!empty($eventClassName) && is_subclass_of($eventClassName->event_class_name, OrderStageLeafEvent::className())) {
             /** @var OrderStageLeafEvent $event */
             $event = new $eventClassName->event_class_name();
             EventTriggeringHelper::triggerSpecialEvent($event);
             if ($event->getStatus()) {
                 $order->order_stage_id = $order->order_stage_id == $orderStageLeaf->stage_to_id ? $orderStageLeaf->stage_from_id : $orderStageLeaf->stage_to_id;
                 $order->save();
                 Yii::$app->session->set('OrderStageReach', true);
             }
         }
     }
     return $this->redirect(Url::to(['stage']));
 }
Ejemplo n.º 3
0
 /**
  * Product page view
  *
  * @param null $model_id
  * @return string
  * @throws NotFoundHttpException
  * @throws ServerErrorHttpException
  */
 public function actionShow($model_id = null)
 {
     if (null === ($object = Object::getForClass(Product::className()))) {
         throw new ServerErrorHttpException('Object not found.');
     }
     $cacheKey = 'Product:' . $model_id;
     if (false === ($product = Yii::$app->cache->get($cacheKey))) {
         if (null === ($product = Product::findById($model_id))) {
             throw new NotFoundHttpException();
         }
         Yii::$app->cache->set($cacheKey, $product, 86400, new TagDependency(['tags' => [ActiveRecordHelper::getObjectTag(Product::className(), $model_id)]]));
     }
     $request = Yii::$app->request;
     $values_by_property_id = $request->get('properties', []);
     if (!is_array($values_by_property_id)) {
         $values_by_property_id = [$values_by_property_id];
     }
     $selected_category_id = $request->get('last_category_id');
     $selected_category_ids = $request->get('categories', []);
     if (!is_array($selected_category_ids)) {
         $selected_category_ids = [$selected_category_ids];
     }
     $category_group_id = intval($request->get('category_group_id', 0));
     // trigger that we are to show product to user!
     // wow! such product! very events!
     $specialEvent = new ProductPageShowed(['product_id' => $product->id]);
     EventTriggeringHelper::triggerSpecialEvent($specialEvent);
     if (!empty($product->meta_description)) {
         $this->view->registerMetaTag(['name' => 'description', 'content' => ContentBlockHelper::compileContentString($product->meta_description, Product::className() . ":{$product->id}:meta_description", new TagDependency(['tags' => [ActiveRecordHelper::getCommonTag(ContentBlock::className()), ActiveRecordHelper::getCommonTag(Product::className())]]))], 'meta_description');
     }
     $selected_category = $selected_category_id > 0 ? Category::findById($selected_category_id) : null;
     $this->view->title = $product->title;
     $this->view->blocks['h1'] = $product->h1;
     $this->view->blocks['announce'] = $product->announce;
     $this->view->blocks['content'] = $product->content;
     $this->view->blocks['title'] = $product->title;
     return $this->render($this->computeViewFile($product, 'show'), ['model' => $product, 'category_group_id' => $category_group_id, 'values_by_property_id' => $values_by_property_id, 'selected_category_id' => $selected_category_id, 'selected_category' => $selected_category, 'selected_category_ids' => $selected_category_ids, 'object' => $object, 'breadcrumbs' => $this->buildBreadcrumbsArray($selected_category, $product)]);
 }
Ejemplo n.º 4
0
 /**
  * Calculate order total price and items count with all additional markups.
  * @param bool $callSave Call save method after calculating.
  * @param bool $deleteNotActiveProducts Delete Order Item if product is not active or is not exist.
  * @return bool
  */
 public function calculate($callSave = false, $deleteNotActiveProducts = true)
 {
     $itemsCount = 0;
     foreach ($this->items as $item) {
         if (null === OrderItem::findOne(['id' => $item->id])) {
             $item->delete();
             continue;
         }
         if ($deleteNotActiveProducts && (null === $item->product || $item->product->active == 0)) {
             $item->delete();
             continue;
         }
         if (Yii::$app->getModule('shop')->countChildrenProducts == 1) {
             $itemsCount += Yii::$app->getModule('shop')->countUniqueProductsOnly == 1 ? 1 : $item->quantity;
         } else {
             if ($item->parent_id == 0) {
                 $itemsCount += Yii::$app->getModule('shop')->countUniqueProductsOnly == 1 ? 1 : $item->quantity;
             }
         }
     }
     $event = new OrderCalculateEvent();
     $event->order = $this;
     $event->price = PriceHelper::getOrderPrice($this, SpecialPriceList::TYPE_CORE);
     EventTriggeringHelper::triggerSpecialEvent($event);
     $this->items_count = $itemsCount;
     $this->total_price = PriceHelper::getOrderPrice($this);
     $event->state = OrderCalculateEvent::AFTER_CALCULATE;
     EventTriggeringHelper::triggerSpecialEvent($event);
     TagDependency::invalidate(Yii::$app->cache, ['Session:' . Yii::$app->session->id]);
     return $callSave ? $this->save(true, ['items_count', 'total_price', 'total_price_with_shipping']) : true;
 }