当前位置: 首页>>代码示例>>PHP>>正文


PHP Order::validate方法代码示例

本文整理汇总了PHP中common\models\Order::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::validate方法的具体用法?PHP Order::validate怎么用?PHP Order::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common\models\Order的用法示例。


在下文中一共展示了Order::validate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionOrder

 public function actionOrder()
 {
     $order = new Order();
     /** @var ShoppingCart $cart */
     $cart = \Yii::$app->cart;
     /* @var $products Product[] */
     $products = $cart->getPositions();
     if ($order->load(\Yii::$app->request->post()) && $order->validate()) {
         $transaction = $order->getDb()->beginTransaction();
         $order->save(false);
         // part of the transaction;
         foreach ($products as $product) {
             $orderItem = new OrderItem();
             $orderItem->order_id = $order->id;
             $orderItem->product_id = $product->id;
             $orderItem->title = $product->title;
             $orderItem->price = $product->getPrice();
             $orderItem->quantity = $product->getQuantity();
             if (!$orderItem->save(false)) {
                 $transaction->rollBack();
                 Yii::$app->session->setFlash('error', 'Your order cannot be accepted. Please contact us!');
                 $this->goBack();
             }
         }
         $transaction->commit();
         Yii::$app->cart->removeAll();
         Yii::$app->session->addFlash('message', 'Thanks for your order. We\'ll contact you soon!');
         //            $order->sendEmail();
         $this->redirect('/');
     }
     return $this->render('order', ['order' => $order, 'products' => $products, 'total' => $cart->getCost()]);
 }
开发者ID:Krinnerion,项目名称:shop,代码行数:32,代码来源:CartController.php

示例2: actionOrder

 public function actionOrder()
 {
     $order = new Order();
     /* @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->id;
             $orderItem->title = $product->title;
             $orderItem->price = $product->getPrice();
             $orderItem->product_id = $product->id;
             $orderItem->quantity = $product->getQuantity();
             if (!$orderItem->save(false)) {
                 $transaction->rollBack();
                 \Yii::$app->session->addFlash('error', 'Cannot place your order. Please contact us.');
                 return $this->redirect('catalog/list');
             }
         }
         $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('catalog/list');
     }
     return $this->render('order', ['order' => $order, 'products' => $products, 'total' => $total]);
 }
开发者ID:ibrarturi,项目名称:yii2-shop,代码行数:32,代码来源:CartController.php

示例3: actionOrder

 public function actionOrder()
 {
     $cartPositions = Yii::$app->cart->getPositions();
     if (!$cartPositions or $cartPositions === null) {
         return $this->redirect(['index']);
     }
     $dataProvider = new ArrayDataProvider(['allModels' => $cartPositions]);
     $model = new Order();
     if ($model->load(Yii::$app->request->post())) {
         $model->status = 1;
         $model->total_cost = Yii::$app->cart->getCost();
         $model->date = date('Y-m-d H:i');
         $model->data = Yii::$app->cart->getSerialized();
         if ($model->validate() && $model->save()) {
             Yii::$app->cart->removeAll();
             return $this->render('orderSuccess', ['model' => $model]);
         }
     }
     return $this->render('order', ['model' => $model, 'dataProvider' => $dataProvider]);
 }
开发者ID:cyanofresh,项目名称:yii2shop,代码行数:20,代码来源:CartController.php

示例4: actionCheckout

 public function actionCheckout()
 {
     $user_id = 0;
     if (Yii::$app->user->isGuest) {
         return $this->redirect('/login');
     }
     if (!Yii::$app->user->isGuest) {
         $user_id = Yii::$app->user->identity->id;
     }
     $cart_json = [];
     if (isset($_COOKIE["cart_{$user_id}"])) {
         $cart_json = Json::decode($_COOKIE["cart_{$user_id}"]);
     } elseif (isset($_COOKIE["cart_0"])) {
         $cart_json = Json::decode($_COOKIE["cart_0"]);
     } else {
         return $this->redirect('/shop');
         Yii::$app->end();
     }
     $ar_product_id = array_keys($cart_json);
     $cart_items = Product::find()->where(['in', 'id', $cart_json])->all();
     if (isset($_POST) && !empty($_POST['place_order'])) {
         $grand_total = 0.0;
         $grand_total_purchase_price = 0.0;
         foreach ($cart_items as $ci) {
             $unit_price = floatval($ci->selling_price);
             $qty = intval($cart_json[$ci->id]['qty']);
             $row_total = $unit_price * $qty;
             $grand_total += $row_total;
             $unit_purchase_price = floatval($ci->purchase_price);
             $row_total_purchase_price = $unit_purchase_price * $qty;
             $grand_total_purchase_price += $row_total_purchase_price;
         }
         $order = new Order();
         $order->bill_number = Custom::getUniqueId(0, 6);
         $order->member_id = $user_id;
         $order->total_amount = $grand_total;
         $order->total_payable = $grand_total;
         $order->payment_method = $_POST['payment_method'];
         $order->beforeSave(true);
         if ($order->validate() && $order->insert()) {
             $product = '';
             foreach ($cart_items as $ci) {
                 $unit_price = floatval($ci->selling_price);
                 $qty = intval($cart_json[$ci->id]['qty']);
                 $row_total = $unit_price * $qty;
                 $product .= "{$ci->id},";
                 $cart = new Cart();
                 $cart->order_id = $order->id;
                 $cart->product_id = $ci->id;
                 $cart->unit_selling_price = $ci->selling_price;
                 $cart->quantity_sold = $qty;
                 $cart->subtotal_payable = $row_total;
                 $cart->subtotal_paid = $row_total;
                 $cart->beforeSave(true);
                 $cart->insert();
             }
         }
         $sale_amount = $grand_total - $grand_total_purchase_price;
         $app_root = \Yii::getAlias('@approot');
         include "{$app_root}/affiliate/controller/record-sale.php";
         $cookies = Yii::$app->response->cookies;
         if (isset($_COOKIE['cart_' . $user_id])) {
             $cookies->remove('cart_' . $user_id);
             unset($cookies['cart_' . $user_id]);
         }
         if (isset($_COOKIE['cart_0'])) {
             $cookies->remove('cart_0');
             unset($cookies['cart_0']);
         }
         return $this->redirect(['/member/order', 'id' => $order->id]);
     }
     return $this->render('checkout', ['cart_items' => $cart_items, 'cookie_data' => $cart_json]);
 }
开发者ID:md-nurul-islam,项目名称:simple-ecom,代码行数:73,代码来源:SiteController.php

示例5: actionCartFormSubmit

 public function actionCartFormSubmit()
 {
     if (Yii::$app->request->isPost) {
         $model_form = new Order();
         $model_form->load(Yii::$app->request->post());
         $model_form->scenario = 'submit';
         $model_form->payment_type = Yii::$app->request->post('payment') ? Yii::$app->request->post('payment') : 0;
         //$model_form->validate();
         //vd( $model_form->getErrors());
         $model_form->status = 1;
     }
     if ($model_form->load(Yii::$app->request->post()) && $model_form->validate()) {
         $model_form->save();
         Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         Yii::$app->session->setFlash('success', 'Благодарим за покупку');
         //Todo сохранить заказы !!!
         $iP = Yii::$app->session->id;
         $model = Cart::getAllByIp($iP);
         if ($model) {
             //vd($model_form->created_at);
             $listItemsInOrder = OrderItems::Add($model, $model_form->id, $model_form->created_at);
             //vd($listItemsInOrder);
         }
         //Todo отправка email !!!
         // Todo отправка ел почты
         //$model_Email = Email::find()->where(['id' => 1])->one();
         // $currEmail = $model_Email->email;
         //vd($model->email);
         Yii::$app->mailer->compose(['html' => '@common/mail/order'], ['order_id' => $model_form->id, 'listItemsInOrder' => $listItemsInOrder])->setFrom('kotmonstr@local.com')->setTo('kotmonstr@ukr.net')->setSubject('нОвый заказ')->send();
         //Todo Очистить корзину
         Cart::DeleteAllByIp($iP);
         $this->redirect('/site/index');
     } else {
         // либо страница отображается первый раз, либо есть ошибка в данных
         $data = $this->getCommonDate();
         $model_form = new Order();
         $iP = Yii::$app->session->id;
         $model = Cart::getAllByIp($iP);
     }
     return $this->render('cart', ['data' => $data, 'model' => $model, 'model_form' => $model_form]);
 }
开发者ID:kotmonstr,项目名称:full-shop,代码行数:41,代码来源:DefaultController.php

示例6: actionCreate

 public function actionCreate()
 {
     $out = ['status' => 'err', 'error' => 'Unknown error'];
     $order = new Order();
     $r = new Request();
     if ($order->load($r->post())) {
         $order->price = $order->price * 100;
         // $user = \Yii::$app->user;
         if (\Yii::$app->user->isGuest) {
             if ($user = User::findByEmail($r->post('SignupForm')['email'])) {
                 $order->user_id = $user->getId();
             } else {
                 $signup = new SignupForm();
                 if ($signup->load($r->post())) {
                     $signup->username = $signup->email;
                     $signup->password = User::MakePass(7);
                     if ($user = $signup->signup()) {
                         $order->user_id = $user->getId();
                     } else {
                         $out['error'] = array_values($signup->errors)[0][0];
                     }
                 } else {
                     //vd($signup->errors,1);
                 }
             }
         } else {
             $order->user_id = \Yii::$app->user->getId();
         }
         if ($order->validate() && $order->save()) {
             //vd([$r->post(),$order->attributes]);
             $out = ['status' => 'ok', 'order' => $order->id, 'user' => $order->user_id, 'sum' => $order->price / 100];
         } else {
             $out['error'] = array_values($order->errors)[0][0];
             //vd($order->errors);
         }
     }
     //vd($out);
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return $out;
     //return BaseJson::encode($out,JSON_PRETTY_PRINT);
     /*vd(['get' => $r->getQueryParams() ,
       'post' => $r->post(),
       'order' => $order],1); //*/
 }
开发者ID:pjoger,项目名称:pon4ik,代码行数:44,代码来源:OrderController.php


注:本文中的common\models\Order::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。