Ejemplo n.º 1
0
 public function actionOrder()
 {
     $order = new Orders();
     /* @var $cart ShoppingCart */
     $cart = \Yii::$app->cart;
     /* @var $products Product[] */
     $products = $cart->getPositions();
     $total = $cart->getCost();
     if ($order->load(Yii::$app->request->post()) && $order->validate()) {
         $transaction = $order->getDb()->beginTransaction();
         $order->save(false);
         foreach ($products as $product) {
             $orderItem = new OrderItem();
             $orderItem->order_id = $order->order_id;
             $orderItem->item_id = $product->item_id;
             $orderItem->price = $product->getPrice();
             $orderItem->quantity = $product->getQuantity();
             if (!$orderItem->save(false)) {
                 $transaction->rollBack();
                 Yii::$app->session->addFlash('error', 'Cannot place your order. Please contact us.');
                 // TODO: may need to add Yii::t()
                 return $this->redirect('../');
                 // redirect to web root
             }
         }
         $transaction->commit();
         \Yii::$app->cart->removeAll();
         Yii::$app->session->addFlash('success', 'Thanks for your order. We\'ll contact you soon.');
         $order->sendEmail();
         return $this->redirect('../');
         // redirect to web root
     }
     return $this->render('order', ['order' => $order, 'products' => $products, 'total' => $total]);
 }
Ejemplo n.º 2
0
 /**
  * Creates a new Orders model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Orders();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->ID]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Users model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Orders();
     //        $model = new Users(['scenario' =>'login']);
     //        error_log(print_r($model,1));
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Ejemplo n.º 4
0
 /**
  * input user data
  * @param $id_tour
  * @param $id_booking
  * @return string
  */
 public function actionRegistration($id_tour, $id_booking)
 {
     $model = new Orders();
     if (Yii::$app->request->isPost) {
         $model->load(Yii::$app->request->post());
         $model->id_tour = $id_tour;
         $model->id_booking = $id_booking;
         if ($model->save()) {
             $this->redirect('/site/success');
         }
     }
     return $this->render('registration', compact('model'));
 }
Ejemplo n.º 5
0
 public function actionCreate($date)
 {
     $model = new Orders();
     $clients = new Clients();
     if ($model->load(Yii::$app->request->post())) {
         $client = $clients->findOne($model->clientId);
         $model->date = $date;
         $model->managerName = Yii::$app->user->identity->full_name;
         $model->driverId = $client->driverId;
         $model->save();
         return true;
     }
     return $this->renderAjax('form', ['model' => $model, 'clients' => $clients, 'delivery' => ArrayHelper::map(Delivery::find()->all(), 'id', 'name'), 'action' => 'create']);
 }
Ejemplo n.º 6
0
 /**
  * Creates a new Orders model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($tour_id)
 {
     $model = new Orders();
     $tour_meta = new ToursMeta();
     $tour_meta = $tour_meta->getFields($tour_id);
     $tour = Tours::findOne($tour_id);
     $model->created = date('d.m.Y');
     $model->tour_id = $tour_id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         foreach ($_POST['Meta'] as $meta => $val) {
             $order_meta = new OrderMeta();
             $order_meta->order_id = $model->id;
             $order_meta->meta_id = $meta;
             $order_meta->meta_val = $val;
             if (!$order_meta->save()) {
                 return $this->render('create', ['model' => $model, 'tour_meta' => $tour_meta, 'tour' => $tour]);
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'tour_meta' => $tour_meta, 'tour' => $tour]);
     }
 }