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


PHP Order::load方法代码示例

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


在下文中一共展示了Order::load方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
 {
     $session = Yii::$app->getSession();
     $cart = $session->has('cart') ? $session->get('cart') : [];
     if (!$cart) {
         return $this->redirect(['index']);
     }
     $model = new Order();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (is_array($cart)) {
             foreach ($cart as $one_goods) {
                 $order_goods = new OrderGoods();
                 $order_goods->goods_id = $one_goods['id'];
                 $order_goods->count = $one_goods['count'];
                 $order_goods->order_id = $model->id;
                 $order_goods->save();
             }
         }
         Yii::$app->session->remove('cart');
         return $this->redirect(['index']);
     } else {
         $goods_id = ArrayHelper::getColumn($cart, 'id');
         $goods = Goods::find()->where(['id' => $goods_id])->asArray()->indexBy('id')->all();
         $amount = 0;
         foreach ($cart as $one_goods) {
             $amount += $one_goods['count'] * $goods[$one_goods['id']]['price'];
         }
         $model->price = $amount;
         return $this->render('order', ['cart' => $cart, 'model' => $model, 'amount' => $amount]);
     }
 }
开发者ID:RStuffGit,项目名称:furniture,代码行数:31,代码来源:GoodsController.php

示例4: actionCreate

 /**
  * Creates a new Order model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Order();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $redirect = yii::$app->request->post('goto') == 'list' ? ['index'] : ['update', 'id' => $model->id];
         return $this->redirect($redirect);
     }
     return $this->render('create', ['model' => $model]);
 }
开发者ID:kibercoder,项目名称:bilious-octo-fibula,代码行数:14,代码来源:OrderController.php

示例5: actionCreate

 /**
  * Creates a new Order model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Order();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:ibrarturi,项目名称:yii2-shop,代码行数:14,代码来源:OrderController.php

示例6: actionCreate

 public function actionCreate()
 {
     $model = new Order();
     $model->send_at = date("Y-m-d H:i:s");
     $model->is_new = 0;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->render('thank');
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:uraankhayayaal,项目名称:aic.s-vfu.ru,代码行数:11,代码来源:OrderController.php

示例7: actionCreate

 /**
  * Creates a new Order model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new Order();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:CTaiDeng,项目名称:funshop,代码行数:16,代码来源:OrderController.php

示例8: 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

示例9: 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

示例10: 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

示例11: actionCheckout

 public function actionCheckout()
 {
     Yii::$app->session['step'] = 2;
     $userId = Yii::$app->user->id;
     $addresses = Address::find()->where(['user_id' => $userId])->all();
     $model = new Order();
     if ($model->load(Yii::$app->request->post())) {
         if (!Yii::$app->request->post('address_id')) {
             return $this->goBack();
         }
         // 使用优惠券
         $feeCouponUser = $feeCouponCode = $feePoint = 0.0;
         $couponId = Yii::$app->request->post('coupon');
         if ($couponId && Yii::$app->request->post('checkbox-coupon')) {
             $couponUser = Coupon::findOne($couponId);
             if (!$couponUser || $couponUser->used_at > 0 || $couponUser->ended_at < time() || $couponUser->user_id != Yii::$app->user->id) {
                 return $this->goBack();
             }
             $feeCouponUser = $couponUser->money;
         }
         // 使用优惠码
         $sn = Yii::$app->request->post('sn');
         if ($sn) {
             $couponCode = Coupon::find()->where(['sn' => $sn])->one();
             if (!$couponCode || $couponCode->used_at > 0 || $couponCode->ended_at < time()) {
                 return $this->goBack();
             }
             $feeCouponCode = $couponCode->money;
         }
         // 使用积分
         $point = Yii::$app->request->post('point');
         if ($point && Yii::$app->request->post('checkbox-point')) {
             if ($point > Yii::$app->user->identity->point) {
                 return $this->goBack();
             }
             $feePoint = intval($point) / 100;
         }
         $address = Address::find()->where(['id' => Yii::$app->request->post('address_id'), 'user_id' => $userId])->one();
         $model->user_id = $userId;
         $model->sn = date('YmdHis') . rand(1000, 9999);
         $model->consignee = $address->consignee;
         $model->country = $address->country;
         $model->province = $address->province;
         $model->city = $address->city;
         $model->district = $address->district;
         $model->address = $address->address;
         $model->zipcode = $address->zipcode;
         $model->phone = $address->phone;
         $model->mobile = $address->mobile;
         $model->email = $address->email ? $address->email : Yii::$app->user->identity->email;
         if ($model->payment_method == Order::PAYMENT_METHOD_COD) {
             $model->payment_status = Order::PAYMENT_STATUS_COD;
         } else {
             $model->payment_status = Order::PAYMENT_STATUS_UNPAID;
         }
         $model->status = $model->payment_status;
         $products = Cart::find()->where(['session_id' => Yii::$app->session->id])->all();
         if (count($products)) {
             foreach ($products as $product) {
                 $model->amount += $product->number * $product->price;
             }
         } else {
             $this->redirect('/cart');
         }
         $model->amount += floatval($model->shipment_fee) - $feeCouponUser - $feeCouponCode - $feePoint;
         if ($model->save()) {
             // insert order_product and clear cart
             foreach ($products as $product) {
                 $orderProduct = new OrderProduct();
                 $orderProduct->order_id = $model->id;
                 $orderProduct->product_id = $product->product_id;
                 $orderProduct->sku = $product->sku;
                 $orderProduct->name = $product->name;
                 $orderProduct->number = $product->number;
                 $orderProduct->market_price = $product->market_price;
                 $orderProduct->price = $product->price;
                 $orderProduct->thumb = $product->thumb;
                 $orderProduct->type = $product->type;
                 $orderProduct->save();
                 // 减少商品的库存
                 Product::updateAllCounters(['stock' => -$product->number], ['id' => $product->product_id]);
             }
             // 生成订单后,清空购物车,设置优惠码,更新积分和积分记录
             Cart::deleteAll(['session_id' => Yii::$app->session->id]);
             if (isset($couponUser) && Yii::$app->request->post('checkbox-coupon')) {
                 $couponUser->used_at = time();
                 $couponUser->order_id = $model->id;
                 $couponUser->save();
             }
             if (isset($couponCode) && Yii::$app->request->post('checkbox-coupon')) {
                 $couponCode->user_id = Yii::$app->user->id;
                 $couponCode->used_at = time();
                 $couponCode->order_id = $model->id;
                 $couponCode->save();
             }
             if (isset($point) && Yii::$app->request->post('checkbox-point')) {
                 $balance = Yii::$app->user->identity->point - $point;
                 User::updateAllCounters(['point' => -$point], ['id' => Yii::$app->user->id]);
                 $pointLog = new PointLog(['user_id' => Yii::$app->user->id, 'type' => PointLog::POINT_TYPE_BUYING, 'point' => -$point, 'balance' => $balance]);
                 $pointLog->save();
//.........这里部分代码省略.........
开发者ID:CTaiDeng,项目名称:funshop,代码行数:101,代码来源:CartController.php


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