/** * view data order / detail data order */ public function actionView($id) { /* untuk cek login admin */ IsAuth::Admin(); /* panggil function loadModel() * dan ditampung ke $dataOrder */ $dataOrder = $this->loadModel($id); /* find data confirmpayment berdasarkan order_code */ $dataConfirmPayment = ConfirmPayment::model()->findByAttributes(array('order_code' => $dataOrder->order_code)); /* find data alamat pengiriman berdasarkan id_address */ $dataShippingAddress = AddressBook::model()->findByPk($dataOrder->address_book_id); /* panggil model Orderdetail dan function search */ $model = new Orderdetail('search'); /* clear any default values */ $model->unsetAttributes(); /* set select data order_detail berdasarkan order_code */ $model->order_code = $dataOrder->order_code; /* render ke file views/orders/view */ $this->render('view', array('model' => $dataOrder, 'ordet' => $model, 'dataPayment' => $dataConfirmPayment, 'shippingAddress' => $dataShippingAddress)); }
private function addOrderCleanCart() { /* panggil model Order */ $modelOrder = new Order(); /* set field order_code */ $modelOrder->order_code = $order_code = Yii::app()->user->customerId . '' . $this->orderCode(); /* set field order_date */ $modelOrder->order_date = date('Y-m-d'); /* set field id_address */ $modelOrder->address_book_id = $this->address_book_id; /* set field customer_id */ $modelOrder->customer_id = Yii::app()->user->customerId; /* set field bank_transfer */ $modelOrder->bank_transfer = $this->bank_transfer; /* simpan ke data order */ if ($modelOrder->save()) { /* dapatkan las insert id */ $last_insert_id = Yii::app()->db->getLastInsertID(); /* select semua data yang ada * pada keranjang belanja */ $sql = "SELECT product.product_id as proid, product.product_image,product.product_price,product.product_name,cart.* \n\t\t\t\t\t FROM cart,product\n\t\t\t\t\t WHERE product.product_id=cart.product_id\n\t\t\t\t\t AND cart.cart_code='" . Yii::app()->session['cart_code'] . "'"; /* koneksi ke database */ $connection = Yii::app()->db; /* createCommand */ $command = $connection->cache(1000)->createCommand($sql); /* execute query */ $results = $command->queryAll(); /* simpan ke orderdetail secara looping */ foreach ($results as $detail) { /* panggil model order_detail */ $deor = new Orderdetail(); /* set field order_code */ $deor->order_code = $order_code; /* set field order_id */ $deor->order_id = $last_insert_id; /* set field product_id */ $deor->product_id = $detail['proid']; /* set field qty */ $deor->quantity = $detail['quantity']; /* set field subtotal */ $deor->subtotal = $detail['product_price'] * $detail['quantity']; /* simpan orderdetail */ $deor->save(); } /* delete semua data yang ada di keranjang belanja * berdasarkan user yang belanja */ $del = "DELETE FROM cart WHERE cart_code='" . Yii::app()->session['cart_code'] . "'"; /* create Command */ $del = $connection->createCommand($del); /* execute command */ $del->execute(); /* direct ke halaman utama website */ $this->redirect(array('./')); } }