/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Order(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Order'])) { $model->attributes = $_POST['Order']; $model->id = F::get_order_id(); $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) { $OrderItem = new OrderItem(); $OrderItem->order_id = $model->order_id; $OrderItem->item_id = $mc['id']; $OrderItem->title = $mc['title']; $OrderItem->pic_url = serialize($mc['pic_url']); $OrderItem->sn = $mc['sn']; $OrderItem->num = $mc['qty']; $OrderItem->save(); } $cart->destroy(); $this->redirect(array('success')); } } // $this->render('create', array( // 'model' => $model, // )); }
/** * Creates a new model associated with an Order. * If creation is successful, the browser will be redirected to the Order 'view' page. */ public function actionCreateItemToOrder($order_id) { $model = new OrderItem(); $model->order_id = $order_id; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['OrderItem'])) { $model->attributes = $_POST['OrderItem']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('createItemToOrder', array('model' => $model)); }
/** * 添加一个商品到订单商品明细表中 * @param $goods 商品ActiveRecord 或 商品id * @param $number 商品数量 * @param $orderid 订单id * @return OrderItem|bool */ public function addOne($goods = 0, $number = 1, $orderid = null) { $orderItem = new OrderItem(); if (is_integer($goods)) { $goods = Goods::findOne(['goods_id' => $goods]); } $orderItem->item_name = $goods['goods_name']; $orderItem->item_price = $goods['goods_price']; $orderItem->item_unit = $goods['goods_unit']; $orderItem->goods_id = $goods['goods_id']; $orderItem->item_number = $number; $orderItem->subtotal = $goods['goods_price'] * $number; $orderItem->order_id = $orderid; return $orderItem->save() ? $orderItem : false; }
public function make() { $this->statusId = self::STATUS_NEW; $this->dateCreate = date(DATE_FORMAT_DB); $this->secretKey = $this->generateSecretKey(); $this->save(); foreach ($this->products as $k => $product) { $model = new OrderItem(); $model->attributes = $product; $model->orderId = $this->id; $model->save(); $this->products[$k] = $model; } return $this; }
public function addOrderItem($productId, $count = 1, $orderProp = array(), $orderItemProp = array()) { if (!m('social')->user()) { return false; } $product = null; //Find and get product by id if (dbQuery($this->productClass)->id($productId)->first($product)) { //If product don't have field companyId then set it manually if (!isset($product[$this->productCompanyField])) { $product[$this->productCompanyField] = 0; } $order = null; //If data on session not exists then create new order manually and save it in db if (!isset($_SESSION[$this->sessionKey][$product[$this->productCompanyField]])) { $order = $this->getOrderIfExists($_SESSION[$this->sessionKey][$product[$this->productCompanyField]], $orderProp); } else { $order = $this->getOrderIfExists($_SESSION[$this->sessionKey][$product[$this->productCompanyField]], $orderProp); } //If order exists add new item into OrderItem if (isset($order)) { $orderItem = null; $orderItemQuery = dbQuery('\\samsonos\\commerce\\OrderItem')->MaterialId($productId)->OrderId($order->id); //In OrderItem row not exists create item else add count if (!$orderItemQuery->first($orderItem)) { $orderItem = new OrderItem(false); $orderItem->OrderId = isset($orderItemProp['OrderId']) ? $orderItemProp['OrderId'] : $order->id; $orderItem->MaterialId = isset($orderItemProp['MaterialId']) ? $orderItemProp['MaterialId'] : $productId; } //Increase quantity $orderItem->Quantity += $count; if (isset($orderProp['Quantity'])) { $orderItem->Quantity = $orderProp['Quantity']; } //Get price from product $orderItem->Price = isset($orderItemProp['Price']) ? $orderItemProp['Price'] : $product[$this->productPriceField]; $orderItem->save(); return $order; } } return false; }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); $Item = Item::model()->with('orderItems')->findAll(new CDbCriteria(array('condition' => "order_id='{$id}'"))); foreach ($Item as $key1 => $items) { foreach ($items->orderItems as $key2 => $orderItem) { $ItemSku[$key1][$key2] = Sku::model()->findByAttributes(array('item_id' => $orderItem->item_id, 'props_name' => $orderItem->props_name)); } } if (isset($_POST['Order']) && isset($_POST['Sku'])) { $transaction = $model->dbConnection->beginTransaction(); try { $model->attributes = $_POST['Order']; $model->update_time = time(); if ($model->save()) { $flag = array(); $OrderItem = OrderItem::model()->findAllByAttributes(array('order_id' => $id)); foreach ($OrderItem as $key => $original) { $criteria = new CDbCriteria(); $criteria->addCondition('item_id=:item_id'); // $criteria->addCondition('price=:price'); $criteria->addCondition('props_name=:props_name'); $criteria->params[':item_id'] = $original->item_id; // $criteria->params[':price']=$original->price; $criteria->params[':props_name'] = $original->props_name; $sku = Sku::model()->find($criteria); $sku->stock += $original->quantity; $sku->save(); foreach ($_POST['Sku']['sku_id'] as $skuId) { if ($sku->sku_id == $skuId) { $flag[$key] = 1; } } } foreach ($OrderItem as $key => $original) { if ($flag[$key] != 1) { $original->delete(); } } foreach ($_POST['Sku']['item_id'] as $key => $itemId) { $item = Item::model()->findByPk($itemId); $sku = Sku::model()->findByPk($_POST['Sku']['sku_id'][$key]); if ($sku->stock < $_POST['Item-number'][$key]) { throw new Exception('Stock is not enough'); } $criteria = new CDbCriteria(); $criteria->addCondition('item_id=:item_id'); $criteria->addCondition('price=:price'); $criteria->addCondition('props_name=:props_name'); $criteria->params[':item_id'] = $sku->item_id; $criteria->params[':price'] = $sku->price; $criteria->params[':props_name'] = $sku->props_name; $orderItem = OrderItem::model()->find($criteria); if (!isset($orderItem)) { $orderItem = new OrderItem(); $orderItem->item_id = $itemId; $orderItem->title = $item->title; $orderItem->desc = $item->desc; $orderItem->pic = $item->getMainPic(); } $orderItem->props_name = $sku->props_name; $orderItem->price = $sku->price; $orderItem->quantity = $_POST['Item-number'][$key]; $sku->stock -= $_POST['Item-number'][$key]; if (!$sku->save()) { throw new Exception('Cut down stock fail'); } $orderItem->total_price = $orderItem->price * $orderItem->quantity; $orderItem->order_id = $model->order_id; if (!$orderItem->save()) { throw new Exception('save order item fail'); } } } else { throw new Exception('save order fail'); } $transaction->commit(); $this->redirect(array('view', 'id' => $model->order_id)); } catch (Exception $e) { $transaction->rollBack(); } } $this->render('update', array('model' => $model, 'Item' => $Item, 'ItemSku' => $ItemSku)); }
function saveOrder() { $userId = Session::get('user_id'); if (!isset($userId)) { return json_encode(array('message' => 'not logged')); } $order = new Order(); $order->status = 'active'; $order->user_id = Session::get('user_id'); $order->created_at = date('Y-m-d h:i:s'); $order->save(); $orderId = $order->id; $cart = Session::get('cart'); if (isset($cart) && count($cart) > 0) { foreach ($cart as $item) { $orderItem = new OrderItem(); $order->item_id = $item['item_id']; $order->item_type = $item['item_type']; $order->quantity = $item['quantity']; $order->status = 'active'; $orderItem->order_id = $orderId; $orderItem->created_at = date('Y-m-d h:i:s'); $orderItem->save(); } Session::forget('cart'); return json_encode(array('message' => 'done')); } else { return json_encode(array('message' => 'empty')); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Order(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (!$_POST['delivery_address'] && !Yii::app()->user->isGuest) { echo '<script>alert("您还没有添加收货地址!")</script>'; echo '<script type="text/javascript">history.go(-1)</script>'; } else { if (isset($_POST)) { $transaction = $model->dbConnection->beginTransaction(); try { $cart = Yii::app()->cart; if (!Yii::app()->user->isGuest) { $model->attributes = $_POST; $model->user_id = Yii::app()->user->id ? Yii::app()->user->id : '0'; $cri = new CDbCriteria(array('condition' => 'contact_id =' . $_POST['delivery_address'] . ' AND user_id = ' . Yii::app()->user->id)); $address = AddressResult::model()->find($cri); $model->receiver_country = $address->country; $model->receiver_name = $address->contact_name; $model->receiver_state = $address->state; $model->receiver_city = $address->city; $model->receiver_district = $address->district; $model->receiver_address = $address->address; $model->receiver_zip = $address->zipcode; $model->receiver_mobile = $address->mobile_phone; $model->receiver_phone = $address->phone; } else { $address = $_POST['AddressResult']; $model->user_id = '0'; $model->receiver_name = $address['contact_name']; $model->receiver_state = $address['state']; $model->receiver_city = $address['city']; $model->receiver_district = $address['district']; $model->receiver_address = $address['address']; $model->receiver_zip = $address['zipcode']; $model->receiver_mobile = $address['mobile_phone']; $model->receiver_phone = $address['phone']; $model->payment_method_id = $_POST['payment_method_id']; $model->memo = $_POST['memo']; } $model->create_time = time(); $model->order_id = F::get_order_id(); $model->total_fee = 0; if (isset($_POST['keys'])) { foreach ($_POST['keys'] as $key) { $item = $cart->itemAt($key); $model->total_fee += $item['quantity'] * $item['price']; } } else { $item = Item::model()->findBypk($_POST['item_id']); $model->total_fee = $item->price * $_POST['quantity']; } if ($model->save()) { if (empty($_POST['keys'])) { $item = Item::model()->findBypk($_POST['item_id']); $sku = Sku::model()->findByPk($_POST['sku_id']); if ($sku->stock < $_POST['quantity']) { throw new Exception('stock is not enough!'); } $OrderItem = new OrderItem(); // $OrderItem->order_id = $model->order_id; // $OrderItem->item_id = $item->item_id; // $OrderItem->title = $item->title; // $OrderItem->desc = $item->desc; // $OrderItem->pic = $item->getMainPic(); // $OrderItem->props_name = $sku->props_name; // $OrderItem->price = $item->price; // $OrderItem->quantity = $_POST['quantity']; // $OrderItem->total_price = $OrderItem->quantity * $OrderItem->price; if (!$OrderItem::model()->saveOrderItem($OrderItem, $model->order_id, $item, $sku->props_name, $_POST['quantity'])) { throw new Exception('save order item fail'); } } else { foreach ($_POST['keys'] as $key) { $item = $cart->itemAt($key); $sku = Sku::model()->findByPk($item['sku']['sku_id']); if ($sku->stock < $item['quantity']) { throw new Exception('stock is not enough!'); } $sku->stock -= $item['quantity']; if (!$sku->save()) { throw new Exception('cut down stock fail'); } $OrderItem = new OrderItem(); $OrderItem->order_id = $model->order_id; $OrderItem->item_id = $item['item_id']; $OrderItem->title = $item['title']; $OrderItem->desc = $item['desc']; $OrderItem->pic = $item->getMainPic(); $OrderItem->props_name = $sku['props_name']; $OrderItem->price = $item['price']; $OrderItem->quantity = $item['quantity']; $OrderItem->total_price = $OrderItem->quantity * $OrderItem->price; if (!$OrderItem->save()) { throw new Exception('save order item fail'); } $cart->remove($key); } } } else { throw new Exception('save order fail'); } $transaction->commit(); $this->redirect(array('success')); } catch (Exception $e) { $transaction->rollBack(); $this->redirect(array('fail')); } } } }
public function saveOrder() { $user_id = Session::get('user_id'); $cart = Session::get('cart'); if (isset($cart)) { $orderId = Session::get('order_id'); $exists = false; if (isset($orderId)) { $order = Order::find($orderId); if (isset($order)) { $exists = true; } } if (!$exists) { $order = new Order(); $total = 0; foreach ($cart as $cartItem) { $discounted_price = $cartItem['discounted_price'] * $cartItem['quantity']; $total += $discounted_price; } $discount_on_total = 0; $net_total = $total - $discount_on_total; $order->amount = $total; $order->user_id = $user_id; //2/7/16 userid added first it was not there $order->discount = 0; $order->discount_details = ''; $order->net_amount = $net_total; $order->status = 'inactive'; // let us complete order items first $order->created_at = date('Y-m-d h:i:s'); $order->save(); foreach ($cart as $cartItem) { $orderItem = new OrderItem(); $orderItem->order_id = $order->id; if (isset($cartItem['bookId'])) { $orderItem->product_id = $cartItem['bookId']; } if (isset($cartItem['accessoryId'])) { $orderItem->product_id = $cartItem['accessoryId']; } $orderItem->quantity = $cartItem['quantity']; $orderItem->price = $cartItem['price']; $orderItem->discounted_price = $cartItem['discounted_price']; $orderItem->created_at = date('Y-m-d h:i:s'); $orderItem->status = 'active'; $orderItem->save(); } $order->status = 'pending'; $order->save(); Session::put('order_id', $order->id); echo json_encode(array('message' => 'done')); } else { echo json_encode(array('message' => 'exists')); } } else { echo json_encode(array('message' => 'invalid')); } }
/** * Manages all models. */ public function actionOrder($date = null, $cat = null, $show = 5, $location = null) { if (!$cat) { $cat = SnapUtil::config('boxomatic/supplier_product_feature_category'); } $customerId = Yii::app()->user->user_id; $Customer = Customer::model()->findByPk($customerId); $deadlineDays = SnapUtil::config('boxomatic/orderDeadlineDays'); if (!$date) { $date = DeliveryDate::getCurrentDeliveryDateId(); } $updatedExtras = array(); $updatedOrders = array(); $Category = Category::model()->findByPk($cat); $DeliveryDate = DeliveryDate::model()->findByPk($date); $AllDeliveryDates = false; $pastDeadline = false; $CustDeliveryDate = false; if ($Customer) { $CustDeliveryDate = Order::model()->findByAttributes(array('delivery_date_id' => $date, 'user_id' => $customerId)); if (!$CustDeliveryDate) { $CustDeliveryDate = new Order(); $CustDeliveryDate->delivery_date_id = $date; $CustDeliveryDate->user_id = $customerId; $CustDeliveryDate->location_id = $Customer->location_id; $CustDeliveryDate->save(); } $AllDeliveryDates = DeliveryDate::model()->with('Locations')->findAll("Locations.location_id = " . $CustDeliveryDate->location_id); $deadline = strtotime('+' . $deadlineDays . ' days'); $pastDeadline = strtotime($DeliveryDate->date) < $deadline; if ($pastDeadline) { Yii::app()->user->setFlash('warning', 'Order deadline has passed, order cannot be changed.'); } } if (!$Customer && (isset($_POST['supplier_purchases']) || isset($_POST['boxes']))) { Yii::app()->user->setFlash('error', 'You must register to make an order.'); $this->redirect(array('site/register')); } if ($location) { $locationId = $location; $custLocationId = new CDbExpression('NULL'); if (strpos($locationId, '-')) { //has a customer location $parts = explode('-', $locationId); $locationId = $parts[1]; $custLocationId = $parts[0]; } //$Location=Location::model()->findByPk($locationId); $CustDeliveryDate->location_id = $locationId; $CustDeliveryDate->customer_location_id = $custLocationId; $CustDeliveryDate->save(); $CustDeliveryDate->refresh(); } if (isset($_POST['btn_recurring'])) { $monthsAdvance = (int) $_POST['months_advance']; $startingFrom = $_POST['starting_from']; $every = $_POST['every']; $locationId = $_POST['Order']['delivery_location_key']; $custLocationId = new CDbExpression('NULL'); if (strpos($locationId, '-')) { //has a customer location $parts = explode('-', $locationId); $locationId = $parts[1]; $custLocationId = $parts[0]; } $dayOfWeek = date('N', strtotime($CustDeliveryDate->DeliveryDate->date)) + 1; if ($dayOfWeek == 8) { $dayOfWeek = 1; } $orderedExtras = OrderItem::findCustomerExtras($customerId, $date); $orderedBoxes = UserBox::model()->with('Box')->findAllByAttributes(array('user_id' => $Customer->user_id), 'delivery_date_id=' . $date); $DeliveryDates = DeliveryDate::model()->findAll("\n\t\t\t\t\tdate >= '{$startingFrom}' AND\n\t\t\t\t\tdate <= DATE_ADD('{$startingFrom}', interval {$monthsAdvance} MONTH) AND\n\t\t\t\t\tdate_sub(date, interval {$deadlineDays} day) > NOW() AND\n\t\t\t\t\tDAYOFWEEK(date) = '" . $dayOfWeek . "'"); $n = 0; foreach ($DeliveryDates as $DD) { $CustDD = Order::model()->findByAttributes(array('delivery_date_id' => $DD->id, 'user_id' => $customerId)); if (!$CustDD) { $CustDD = new Order(); $CustDD->delivery_date_id = $DD->id; $CustDD->user_id = $customerId; $CustDD->location_id = $CustDeliveryDate->location_id; $CustDD->save(); } //Delete any extras already ordered $TBDExtras = OrderItem::findCustomerExtras($customerId, $DD->id); foreach ($TBDExtras as $TBDExtra) { $TBDExtra->delete(); } //Delete any extras already ordered $TBDBoxes = UserBox::model()->with('Box')->findAllByAttributes(array('user_id' => $Customer->user_id), 'delivery_date_id=' . $CustDD->delivery_date_id); foreach ($TBDBoxes as $TBDBox) { $TBDBox->delete(); } $n++; if ($n % 2 == 0 && $every == 'fortnight') { continue; } //Copy current days order foreach ($orderedExtras as $orderedExt) { $extra = new OrderItem(); //give the customer the extra $extra->quantity = $orderedExt->quantity; $extra->order_id = $CustDD->id; $extra->supplier_purchase_id = $orderedExt->supplier_purchase_id; $extra->price = $orderedExt->price; $extra->packing_station_id = $orderedExt->packing_station_id; $extra->name = $orderedExt->name; $extra->unit = $orderedExt->unit; $extra->save(); } //Copy current days boxxes foreach ($orderedBoxes as $orderedBox) { $EquivBox = Box::model()->findByAttributes(array('size_id' => $orderedBox->Box->size_id, 'delivery_date_id' => $DD->id)); $box = new UserBox(); $box->attributes = $orderedBox->attributes; $box->user_box_id = null; $box->box_id = $EquivBox->box_id; $box->save(); } } Yii::app()->user->setFlash('success', 'Recurring order set.'); } if (isset($_POST['btn_clear_orders'])) { $orderedExtras = OrderItem::model()->with(array('Order' => array('with' => 'DeliveryDate')))->findAll("DATE_SUB(date, INTERVAL {$deadlineDays} DAY) > NOW() AND user_id = " . $Customer->user_id); foreach ($orderedExtras as $ext) { $ext->delete(); } //Get all boxes beyond the deadline date $Boxes = Box::model()->with('DeliveryDate')->findAll("DATE_SUB(date, interval {$deadlineDays} day) > NOW()"); foreach ($Boxes as $Box) { $CustBox = UserBox::model()->findByAttributes(array('user_id' => $Customer->user_id, 'box_id' => $Box->box_id)); if ($CustBox) { $CustBox->delete(); } } } if (isset($_POST['extras'])) { foreach ($_POST['extras'] as $id => $quantity) { $model = $this->loadModel($id); if ($model->Order->user_id == Yii::app()->user->user_id) { if ($quantity == 0) { $model->delete(); } else { $model->quantity = $quantity; $model->save(); $updatedOrders[$model->id] = $model; } } } } if (isset($_POST['supplier_purchases'])) { foreach ($_POST['supplier_purchases'] as $purchaseId => $quantity) { if ($quantity == 0) { continue; } $extra = OrderItem::model()->with('Order')->findByAttributes(array('supplier_purchase_id' => $purchaseId, 'order_id' => $CustDeliveryDate->id)); if (!$extra) { $extra = new OrderItem(); } $Purchase = SupplierPurchase::model()->findByPk($purchaseId); $SupplierProduct = $Purchase->supplierProduct; //give the customer the extra $extra->quantity += $quantity; $extra->order_id = $CustDeliveryDate->id; $extra->supplier_purchase_id = $purchaseId; $extra->price = $Purchase->item_sales_price; $extra->packing_station_id = $SupplierProduct->packing_station_id; $extra->name = $SupplierProduct->name; $extra->unit = $SupplierProduct->unit; $updatedExtras[$extra->supplier_purchase_id] = $extra; $extra->save(); } } if (isset($_POST['boxes'])) { foreach ($_POST['boxes'] as $boxId => $quantity) { $Box = Box::model()->findByPk($boxId); $CustBoxes = UserBox::model()->with('Box')->findAll(array('condition' => 'user_id=:customerId AND size_id=:sizeId AND delivery_date_id=:deliveryDateId', 'params' => array(':customerId' => $customerId, ':sizeId' => $Box->size_id, ':deliveryDateId' => $Box->delivery_date_id))); $curQuantity = count($CustBoxes); $diff = $quantity - $curQuantity; if ($diff > 0) { //Create extra customer box rows for ($i = 0; $i < $diff; $i++) { $CustBox = new UserBox(); $CustBox->user_id = $customerId; $CustBox->box_id = $boxId; $CustBox->quantity = 1; $CustBox->delivery_cost = $Customer->Location->location_delivery_value; $CustBox->save(); } } if ($diff < 0) { //Remove any boxes the customer no longer wants; $diff = abs($diff); for ($i = 0; $i < $diff; $i++) { $CustBoxes[$i]->delete(); } } } } $orderedExtras = OrderItem::findCustomerExtras($customerId, $date); $dpOrderedExtras = new CActiveDataProvider('OrderItem'); $dpOrderedExtras->setData($orderedExtras); $DeliveryDates = DeliveryDate::model()->with('Boxes')->findAll(array('condition' => 'DATE_SUB(date, INTERVAL -1 week) > NOW() AND date < DATE_ADD(NOW(), INTERVAL 1 MONTH)')); $this->render('order', array('pastDeadline' => $pastDeadline, 'orderedExtras' => $dpOrderedExtras, 'updatedExtras' => $updatedExtras, 'updatedOrders' => $updatedOrders, 'DeliveryDate' => $DeliveryDate, 'DeliveryDates' => $DeliveryDates, 'AllDeliveryDates' => $AllDeliveryDates, 'model' => new OrderItem(), 'Category' => $Category, 'Customer' => $Customer, 'CustDeliveryDate' => $CustDeliveryDate, 'curCat' => $cat)); }
public function checkout(Request $request) { $token = $request->input('stripeToken'); //Retriieve cart information $cart = Cart::where('user_id', Auth::user()->id)->first(); $items = $cart->cartItems; $total = 0; foreach ($items as $item) { $total += $item->product->price; } if (Auth::user()->charge($total * 100, ['source' => $token, 'receipt_email' => Auth::user()->email])) { $order = new Order(); $order->total_paid = $total; $order->user_id = Auth::user()->id; $order->save(); foreach ($items as $item) { $orderItem = new OrderItem(); $orderItem->order_id = $order->id; $orderItem->product_id = $item->product->id; $orderItem->file_id = $item->product->file->id; $orderItem->save(); CartItem::destroy($item->id); } return redirect('/order/' . $order->id); } else { return redirect('/cart'); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Order(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); // print_r($_POST); // exit; if (!$_POST['delivery_address']) { echo '<script>alert("您还没有添加收货地址!")</script>'; echo '<script type="text/javascript">history.go(-1)</script>'; die; } else { if (isset($_POST)) { $model->attributes = $_POST; $model->order_id = F::get_order_id(); $model->user_id = Yii::app()->user->id ? Yii::app()->user->id : '0'; $model->create_time = time(); $cri = new CDbCriteria(array('condition' => 'contact_id =' . $_POST['delivery_address'] . ' AND user_id = ' . Yii::app()->user->id)); $address = AddressResult::model()->find($cri); $model->receiver_name = $address->contact_name; $model->receiver_country = $address->country; $model->receiver_state = $address->state; $model->receiver_city = $address->city; $model->receiver_district = $address->district; $model->receiver_address = $address->address; $model->receiver_zip = $address->zipcode; $model->receiver_mobile = $address->mobile_phone; $model->receiver_phone = $address->phone; if ($model->save()) { $cart = Yii::app()->cart; $mycart = $cart->contents(); foreach ($mycart as $mc) { $OrderItem = new OrderItem(); $OrderItem->order_id = $model->order_id; $OrderItem->item_id = $mc['id']; $OrderItem->title = $mc['title']; $OrderItem->pic_url = serialize($mc['pic_url']); $OrderItem->sn = $mc['sn']; $OrderItem->num = $mc['qty']; $OrderItem->price = $mc['price']; $OrderItem->amount = $mc['subtotal']; $OrderItem->save(); } $cart->destroy(); $this->redirect(array('success')); } } } // $this->render('create', array( // 'model' => $model, // )); }