Exemple #1
0
 /**
  * Actual run function for all widget classes extending BaseWidget
  *
  * @return mixed
  */
 public function widgetRun()
 {
     // this header needs this plugin
     BootstrapHoverDropdown::register($this->view);
     $order = Order::getOrder(false);
     return $this->render('header', ['order' => $order, 'collapseOnSmallScreen' => $this->collapseOnSmallScreen]);
 }
 /**
  * Get Order.
  * @param bool $create Create order if it does not exist
  * @param bool $throwException Throw exception if it does not exist
  * @return Order
  * @throws NotFoundHttpException
  */
 protected function loadOrder($create = false, $throwException = true)
 {
     $model = Order::getOrder($create);
     if (is_null($model) && $throwException) {
         throw new NotFoundHttpException();
     }
     return $model;
 }
Exemple #3
0
 public function run()
 {
     /** @var Order $order */
     $order = Order::getOrder(false);
     if (!empty($order)) {
         $order->calculate();
     }
     return $this->render($this->viewFile, ['order' => $order]);
 }
 /**
  * @param $event OrderStageLeafEvent
  */
 public static function handleDelivery(OrderStageLeafEvent $event)
 {
     $event->setStatus(false);
     if (\Yii::$app->request->isPost) {
         $order = Order::getOrder();
         if (empty($order)) {
             return null;
         }
         /** @var DeliveryInformation $deliveryInformation */
         $deliveryInformation = empty($order->contragent) ? null : (empty($order->contragent->deliveryInformation) ? DeliveryInformation::createNewDeliveryInformation($order->contragent) : $order->contragent->deliveryInformation);
         /** @var OrderDeliveryInformation|HasProperties $orderDeliveryInformation */
         $orderDeliveryInformation = empty($order->orderDeliveryInformation) ? OrderDeliveryInformation::createNewOrderDeliveryInformation($order) : $order->orderDeliveryInformation;
         if (empty($deliveryInformation) || empty($orderDeliveryInformation)) {
             return null;
         }
         if ($deliveryInformation->load(\Yii::$app->request->post())) {
             if (!$deliveryInformation->save()) {
                 return null;
             }
         }
         $data = \Yii::$app->request->post();
         $isNewModel = $orderDeliveryInformation->isNewRecord;
         $orderDeliveryInformation->setScenario('shipping_option_select');
         if ($orderDeliveryInformation->load(\Yii::$app->request->post()) && $orderDeliveryInformation->save()) {
             if ($isNewModel && !empty($orderDeliveryInformation->getPropertyGroup())) {
                 $orderDeliveryInformation->getPropertyGroup()->appendToObjectModel($orderDeliveryInformation);
                 $data[$orderDeliveryInformation->getAbstractModel()->formName()] = isset($data['OrderDeliveryInformationNew']) ? $data['OrderDeliveryInformationNew'] : [];
             }
             $orderDeliveryInformation->saveModelWithProperties($data);
         } else {
             return null;
         }
         $event->setStatus(true);
     }
 }
 /**
  *
  */
 public static function handlePurchase()
 {
     if (null === ($order = Order::getOrder())) {
         return;
     }
     /** @var Currency $currency */
     $currency = static::$currency;
     $ya = ['action' => 'purchase', 'currency' => $currency->iso_code, 'orderId' => $order->id, 'products' => []];
     foreach ($order->items as $item) {
         $ya['products'][] = ['id' => $item->product->id, 'name' => $item->product->name, 'category' => self::getCategories($item->product), 'price' => CurrencyHelper::convertCurrencies($item->product->price, $item->product->currency, $currency), 'quantity' => $item->quantity];
     }
     $js = 'window.DotPlantParams = window.DotPlantParams || {};';
     $js .= 'window.DotPlantParams.ecYandex = ' . Json::encode($ya) . ';';
     \Yii::$app->getView()->registerJs($js, View::POS_BEGIN);
 }