コード例 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Orders();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Orders'])) {
         $model->attributes = $_POST['Orders'];
         $model->order_sn = F::get_order_sn();
         $model->user_id = Yii::app()->user->id ? Yii::app()->user->id : '0';
         if ($model->save()) {
             $cart = Yii::app()->cart;
             $mycart = $cart->contents();
             foreach ($mycart as $mc) {
                 $orderGoods = new OrderGoods();
                 $orderGoods->order_id = $model->order_id;
                 $orderGoods->product_id = $mc['id'];
                 $orderGoods->product_name = $mc['product_name'];
                 $orderGoods->product_image = serialize($mc['product_image']);
                 $orderGoods->product_sn = $mc['product_sn'];
                 $orderGoods->qty = $mc['qty'];
                 $orderGoods->save();
             }
             $cart->destroy();
             $this->redirect(array('success'));
         }
     }
     //
     //        $this->render('create', array(
     //            'model' => $model,
     //        ));
 }