Exemplo n.º 1
0
 public function actionTryNow($objectId, $modelClass)
 {
     if (self::TrialExist()) {
         Yii::$app->session->setFlash('error', 'Sorry, You already have a trial hybrizy code');
         return $this->redirect(['/#packages']);
     }
     $order = new OrderForm(['scenario' => OrderForm::SCENARIO_TRIAL]);
     $order->user_id = Yii::$app->user->id;
     $request = Yii::$app->request;
     if ($request->isPost) {
         if ($order->load($request->post()) && $order->validate()) {
             $result = $order->save();
             $result = Yii::$app->controller->run('/api/process-order/process', ['objectId' => $objectId, 'modelClass' => $modelClass, 'orderId' => $result->id]);
             if ($result) {
                 return $this->redirect(['/profile/index']);
             }
         }
         $package = Package::findOne($objectId);
         return $this->render('index', ['model' => $order, 'package' => $package]);
     }
     $package = Package::findOne($objectId);
     $profile = Yii::$app->user->identity->profile;
     $order->firstname = $profile->firstname;
     $order->lastname = $profile->lastname;
     $order->email = Yii::$app->user->identity->email;
     return $this->render('index', ['model' => $order, 'package' => $package]);
 }
Exemplo n.º 2
0
 public function actionIndex()
 {
     $model = new OrderForm();
     if ($model->load(Yii::$app->request->post()) && $model->makeOrder()) {
         $model->good_id++;
         // create a new order
         $order = new Order();
         // set total price
         $model->total_price = Good::findAll($model->good_id)[0]->price * $model->goods_count;
         // fill order props
         foreach ($model as $key => $value) {
             $order->setAttribute($key, $value);
         }
         // save the order
         $order->save();
         return $this->redirect('/index.php?r=order%2Forders');
     }
     return $this->render('index', ['model' => $model, 'good_names' => HelperComponent::array_pluck('name', Good::find()->select('name')->all())]);
 }
Exemplo n.º 3
0
 public function actionPurchaseNow()
 {
     $MOLPayInfo = [];
     $order = new Order();
     $order->loadDefaultValues();
     $orderForm = new OrderForm();
     $orderForm->load(\Yii::$app->request->post());
     $order->invoice_no = 0;
     $order->invoice_prefix = date("Y-m-d") . '-00';
     $order->store_name = 'Hybrizy';
     $order->payment_method = "MOLPay";
     $order->payment_code = "molpay";
     $order->store_url = Url::base(true);
     $order->user_id = \Yii::$app->user->id;
     $order->firstname = $orderForm->payment_firstname;
     $order->lastname = $orderForm->payment_lastname;
     $order->email = $orderForm->email;
     $order->telephone = $orderForm->payment_telephone;
     $order->fax = "";
     $order->payment_firstname = $orderForm->payment_firstname;
     $order->payment_lastname = $orderForm->payment_lastname;
     $order->payment_company = "";
     $order->payment_address_1 = $orderForm->payment_address_1;
     $order->payment_address_2 = $orderForm->payment_address_2;
     $order->payment_city = $orderForm->payment_city;
     $order->payment_postcode = $orderForm->payment_postcode;
     $order->payment_country = "";
     $order->payment_zone = "";
     $order->payment_address_format = "";
     if ($orderForm->BillingInfoAsShippingAddress === '1') {
         $order->shipping_firstname = $orderForm->payment_firstname;
         $order->shipping_lastname = $orderForm->payment_lastname;
         $order->shipping_address_1 = $orderForm->payment_address_1;
         $order->shipping_address_2 = $orderForm->payment_address_2;
         $order->shipping_city = $orderForm->payment_city;
         $order->shipping_code = $orderForm->payment_code;
         $order->shipping_postcode = $orderForm->shipping_postcode;
     } else {
         $order->shipping_firstname = $orderForm->shipping_firstname;
         $order->shipping_lastname = $orderForm->shipping_lastname;
         $order->shipping_address_1 = $orderForm->shipping_address_1;
         $order->shipping_address_2 = $orderForm->shipping_address_2;
         $order->shipping_city = $orderForm->shipping_city;
         $order->shipping_code = $orderForm->shipping_code;
         $order->shipping_postcode = $orderForm->shipping_postcode;
     }
     // MOL Pay info
     $MOLPayInfo['bill_name'] = $order->payment_firstname . ' ' . $order->payment_lastname;
     $MOLPayInfo['bill_desc'] = $orderForm->BillDescription();
     $order->shipping_zone = "";
     $order->shipping_address_format = "";
     $order->shipping_method = "";
     $order->shipping_code = "";
     $order->comment = "";
     $order->order_status_id;
     $order->currency_code = "";
     $order->ip = "";
     $order->forwarded_ip = "";
     $order->user_agent = "";
     $order->accept_language = "";
     $order->user_id = \Yii::$app->user->id;
     $cart = unserialize(\Yii::$app->db->createCommand('select cart from user where id=:id')->bindValue(':id', \Yii::$app->user->id)->queryColumn()[0]);
     $order->total = $cart['grandTotal'];
     if ($order->save()) {
         $tempOrderId = $order->invoice_prefix . '-' . $order->id;
         $MOLPayInfo['orderid'] = $tempOrderId;
         $MOLPayInfo['amount'] = $order->total;
         $MOLPayInfo['bill_email'] = $order->email;
         $MOLPayInfo['bill_mobile'] = $order->telephone;
         $form = \Yii::$app->controller->renderPartial('@frontend/views/site/_molpay_progress', ['model' => $MOLPayInfo, 'merchantId' => \Yii::$app->params['merchantId']], true);
         return ['data' => $MOLPayInfo, 'result' => 1, 'merchantId' => \Yii::$app->params['merchantId'], 'html' => $form];
     } else {
         return ['data' => [], 'result' => 0];
     }
 }
Exemplo n.º 4
0
 public function actionCheckout($force_step = null)
 {
     $step = isset($force_step) ? $force_step : '1';
     $form = '';
     $request = Yii::$app->request;
     $orderForm = new OrderForm();
     $cart = unserialize(Yii::$app->user->identity->cart);
     $orderForm->scenario = OrderForm::SCENARIO_CHECKOUT;
     if ($request->isPost) {
         $orderForm->load($request->post());
         if ($orderForm->validate()) {
             $step = "3";
             $orderForm->total = $cart['grandTotal'];
             $order = $orderForm->save();
             if ($order !== false) {
                 $form = Yii::$app->controller->renderPartial('_molpay_progress', ['model' => $orderForm->getMolPayTxData()]);
             }
         } else {
             $step = "2";
         }
     } else {
         $userProfile = Yii::$app->user->identity->profile;
         $orderForm->attributes = $userProfile->toArray();
     }
     return $this->render('checkout', ['cart' => $cart, 'order' => $orderForm, 'step' => $step, 'form' => $form]);
 }