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


PHP Order::save方法代码示例

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


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

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

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

示例3: actionCheckout

 public function actionCheckout()
 {
     if ($postData = Yii::$app->request->post()) {
         $model = new Product();
         $order = new Order();
         $order->shipping_address = $postData['address'];
         $order->city = $postData['city'];
         $order->country = $postData['country'];
         $order->postal_code = $postData['postal_code'];
         $order->status = 0;
         $order->save();
         $order_id = $order->order_id;
         $items = [];
         foreach ($postData['qty'] as $key => $val) {
             $order_detail = new OrderDetail();
             $order_detail->order_id = $order_id;
             $order_detail->prod_id = $postData['prod_id'][$key];
             $order_detail->quantity = $postData['qty'][$key];
             $order_detail->unit_price = $postData['prod_price'][$key];
             $order_detail->unit_sum = $postData['prod_price'][$key] * $order_detail->quantity;
             $order_detail->save();
             $item = new Item();
             $item->setName($postData['prod_name'][$key])->setCurrency('USD')->setQuantity($val)->setPrice($postData['prod_price'][$key]);
             $items[] = $item;
         }
         $itemList = new ItemList();
         $itemList->setItems($items);
         $payment = preparePaypal($itemList);
         print_r($items);
     }
     exit;
 }
开发者ID:syedmaaz,项目名称:marxmall-,代码行数:32,代码来源:CartController.php

示例4: actionIndexadd

 public function actionIndexadd()
 {
     if (Yii::$app->user->isGuest) {
         $model = new LoginForm();
         if ($model->load(Yii::$app->request->post()) && $model->login()) {
             return $this->goBack();
         } else {
             return $this->render('/site/login', ['model' => $model]);
         }
     } else {
         $Order = new Order();
         $Order->user_id = Yii::$app->user->identity->id;
         $Order->date_time = date('Y-m-d H:i:s');
         $Order->status_id = '1';
         $Order->save();
         $Card = new CardList();
         $Products = $Card->getCardAndCardList(Yii::$app->user->identity->id);
         $Ord = new Order();
         $order_id = $Ord->GetOrderId(Yii::$app->user->identity->id);
         for ($i = 0; $i < sizeof($Products); $i++) {
             $Orderlist = new Orderlist();
             $Orderlist->order_id = $order_id[0]['MAX(`order_id`)'];
             $Orderlist->product_id = $Products[$i]['product_id'];
             $Orderlist->quantity = $Products[$i]['quantity'];
             $Orderlist->save();
         }
         $card = new Card();
         $card->DeleteCardId(Yii::$app->user->identity->id);
         $order = $Ord->GetOrdersFromID(Yii::$app->user->identity->id);
         $user = User::find()->where(['id' => Yii::$app->user->identity->id])->one();
         return $this->render('index', ['user' => $user, 'order' => $order]);
     }
 }
开发者ID:przemek207,项目名称:Nzi_Project,代码行数:33,代码来源:AccountController.php

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

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

示例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()
 {
     $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

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

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

示例10: saveOrder

 /**
  * Сохраняем наш заказ и отправляем письмо пользователю.
  */
 public function saveOrder($user, $product, $post)
 {
     $order = new Order();
     $order->user_id = $user->id;
     $order->summ = $product['price'];
     $order->created_datetime = date('Y-m-d H:i:s');
     $order->finished_datetime = date('Y-m-d H:i:s');
     if ($order->save(false)) {
         \Yii::$app->mailer->compose(['html' => 'order-html', 'text' => 'order-text'], ['user' => $user, 'product' => $product, 'post' => $post])->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name . ' робот'])->setTo($user->email)->setSubject('Заказ товара - ' . \Yii::$app->name)->send();
         return true;
     }
     return false;
 }
开发者ID:kibercoder,项目名称:bilious-octo-fibula,代码行数:16,代码来源:OrderForm.php

示例11: actionIndex

 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())]);
 }
开发者ID:viktornord,项目名称:gh-php-project,代码行数:19,代码来源:OrderController.php

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

示例13: save

 public function save()
 {
     $order = new Order();
     $order->loadDefaultValues();
     $order->invoice_no = 0;
     $order->invoice_prefix = date("Y-m-d") . '-00';
     $order->store_name = 'Hybrizy';
     if ($this->scenario == self::SCENARIO_TRIAL) {
         $order->payment_method = "Trial";
         $order->payment_code = "Trial";
         $order->firstname = $this->firstname;
         $order->lastname = $this->lastname;
     } elseif ($this->scenario === self::SCENARIO_CHECKOUT) {
         $order->payment_method = "MOLPay";
         $order->payment_code = "molpay";
         $order->telephone = $this->telephone;
         $order->firstname = Yii::$app->user->identity->profile->firstname;
         $order->lastname = Yii::$app->user->identity->profile->lastname;
         $order->payment_firstname = $this->payment_firstname;
         $order->payment_lastname = $this->payment_lastname;
         $order->lastname = $this->payment_lastname;
         $order->email = $this->email;
         $order->total = $this->total;
     }
     $order->store_url = Url::base(true);
     $order->user_id = Yii::$app->user->id;
     if ($order->save()) {
         if ($this->scenario === self::SCENARIO_CHECKOUT) {
             // Generate VCode
             $amount = $order->total;
             $merchantID = Yii::$app->params['merchantID'];
             $orderid = $order->invoice_prefix . '-' . $order->id;
             $vcode = md5($amount . $merchantID . $orderid . Yii::$app->params['verifyKey']);
             // MOLPay Tx Data setup
             $this->_mol_pay_tx_data['bill_name'] = $order->payment_firstname . ' ' . $order->payment_lastname;
             $this->_mol_pay_tx_data['bill_desc'] = $this->BillDescription();
             $this->_mol_pay_tx_data['orderid'] = $orderid;
             $this->_mol_pay_tx_data['amount'] = $order->total;
             $this->_mol_pay_tx_data['bill_email'] = $order->email;
             $this->_mol_pay_tx_data['currency'] = 'MYR';
             $this->_mol_pay_tx_data['country'] = 'MY';
             $this->_mol_pay_tx_data['bill_mobile'] = $order->telephone;
             $this->_mol_pay_tx_data['vcode'] = $vcode;
         }
         return $order;
     } else {
         return false;
     }
 }
开发者ID:fnoorman,项目名称:dev,代码行数:49,代码来源:OrderForm.php

示例14: actionCreateOrder

 /**
  * @return array
  */
 public function actionCreateOrder()
 {
     $result = 0;
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     $id = Yii::$app->request->post('id');
     $user_id = Yii::$app->request->post('user_id');
     if ($id && $user_id) {
         $order = new Order();
         $order->goods_id = $id;
         $order->user_id = $user_id;
         $order->active = 1;
         $result = $order->save();
     }
     return ['success' => $result];
 }
开发者ID:RStuffGit,项目名称:mebel,代码行数:18,代码来源:GoodsController.php

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