public function actionThank() { $user_id = Yii::app()->user->id; //check the billing / shipping values coresponding to this user $chkBillExist = Billing::model()->find('user_id = :user_id', array(':user_id' => $user_id)); //echo "<pre>"; //print_r($chkBillExist); if (empty($chkBillExist)) { //redirect back to checkout page Yii::app()->user->setFlash('showMsg', 'Your billing details are empty.'); $this->redirect(array('shoppingCart/checkout')); } $chkShipExist = Shipping::model()->find('user_id = :user_id', array(':user_id' => $user_id)); if (empty($chkShipExist)) { Yii::app()->user->setFlash('showMsg', 'Please fill your shipping details.'); $this->redirect(array('shoppingCart/checkout')); } //end $model = new Reward(); $orderModel = new Order(); //check the session exist //check billing/ shipping session exist //finally placed the order //insert the cart in order table if (count($_SESSION['items']) > 0) { //get billing/shipping ids of login user $chkBillExist = Billing::model()->find('user_id = :user_id', array(':user_id' => $user_id)); if (empty($chkBillExist)) { } else { $billAddId = $chkBillExist['id']; } //get shipping ids of login user $chkShipExist = Shipping::model()->find('user_id = :user_id', array(':user_id' => $user_id)); if (empty($chkShipExist)) { } else { $shipAddId = $chkShipExist['id']; } $insertOrders = Yii::app()->db->createCommand()->insert('shop_order', array('user_id' => $user_id, 'shipping_address_id' => $billAddId, 'billing_address_id' => $shipAddId, 'ordering_done' => 1, 'grandtotal' => $_SESSION['grandTotalFinal'])); $order_id = Yii::app()->db->getLastInsertID(); foreach ($_SESSION['items'] as $key => $data) { //insert into order detail table $insertOrders = Yii::app()->db->createCommand()->insert('shop_order_detail', array('order_id' => $order_id, 'reward_id' => $data['id'], 'quantity' => $data['quantity'])); $productRewardId = $data['id']; //get the existing quantity from db and add the posted quanity in it $getQuantity = "SELECT instock from reward where id = {$productRewardId}"; $getQtyValue = Yii::app()->db->createCommand($getQuantity)->queryRow(); $finalQuantity = $getQtyValue['instock'] - $data['quantity']; //update the quantity of each product shop by user $getResult = Yii::app()->db->createCommand()->update('reward', array('instock' => $finalQuantity), 'id=' . $data['id']); } //send email to admin and user $this->sendEmailToAll($order_id, $user_id); //end if (isset($_SESSION['items'])) { unset($_SESSION['items']); unset($_SESSION['grandTotalFinal']); } } else { Yii::app()->user->setFlash('showMsg', 'Shopping cart is empty.'); $this->redirect(array('shoppingCart/view')); } //echo Yii::app()->db->lastInsertID; //echo "----"; //echo $last_id = Yii::app()->db->getLastInsertID(); $this->render('thank', array('model' => $orderModel)); }
<tr> <td><span class="extra bold totalamout">Total :</span></td> <td><span class="bold totalamout"><?php echo Yii::app()->params['adminCurrency']; echo $grandTotalFinal; ?> </span></td> </tr> </tbody> </table> <?php if (Yii::app()->user->id != '') { $user_id = Yii::app()->user->id; $chkBillExist = Billing::model()->find('user_id = :user_id', array(':user_id' => $user_id)); if (empty($chkBillExist)) { //dont show the place order button, flash msg to add billing address } else { ?> <?php } } ?> <input type="submit" onclick="window.location.href='index.php?r=shoppingCart/thank'" value="Place Order" class="btn btn-orange pull-right"> <input type="submit" onclick="window.location.href='index.php'" value="Continue Shopping" class="btn btn-orange pull-right mr10">