public function actionEdit() { $this->layout = '//layouts/admin'; $success = false; $id = $_REQUEST['id']; $model = Orders::model()->findByPk($id); $this->pageTitle = is_object($model) ? "Заказ #" . $model->id : 'Новый заказ'; $this->breadcrumbs = array('Заказы' => array('/admin/orders'), is_object($model) ? "Заказ #" . $model->id : 'Новый заказ'); if (isset($_POST['data']) && is_object($model)) { $dataArray = $_POST['data']; $dataArray['timestamp'] = isset($dataArray['timestamp']) ? strtotime($dataArray['timestamp']) : time(); $orderItems = json_decode($dataArray['order_items'], true); unset($dataArray['order_items']); $model->setAttributes($dataArray); if ($model->save()) { $success = true; $oldItems = OrderItems::model()->findAllByAttributes(array("order_id" => $model->id)); if (is_array($oldItems) && count($oldItems)) { foreach ($oldItems as $item) { $item->delete(); } } if (is_array($orderItems) && count($orderItems)) { foreach ($orderItems as $oItem) { foreach ($oItem as $oId => $amount) { $object = CatalogObjects::model()->findByPk($oId); if (is_object($object) && $amount) { $oItemModel = new OrderItems(); $attributes = array(); $attributes['order_id'] = $model->id; $attributes['name'] = $object->name; $attributes['product_id'] = $object->id; $attributes['price'] = $object->price; $attributes['amount'] = $amount; $oItemModel->setAttributes($attributes); $oItemModel->save(); } } } } } } $this->render('edit', array('model' => $model, 'success' => $success, 'errors' => $model->errors)); }
/** * 顾客留言 */ public function actionMsg() { $order_id = $_POST['order_id']; Yii::import('application.modules.member.models.Comments'); //商品信息 $product_list = OrderItems::model()->findAll('order_id = :order_id', array(':order_id' => $order_id)); //评论信息 $comment = Comments::model()->findAll('order_id = :order_id', array(':order_id' => $order_id)); echo $this->renderPartial('_order_msg', array('comment' => $comment, 'product_list' => $product_list), true); }
foreach ($errors as $error) { ?> <li><?php echo $error; ?> </li> <?php } ?> </ul> </div> <?php } $orderItemsValue = ""; $itemsArr = array(); $orderItems = OrderItems::model()->findAllByAttributes(array("order_id" => $model->id)); if (is_array($orderItems) && count($orderItems)) { foreach ($orderItems as $item) { $itemsArr[] = array($item->product_id => $item->amount); } $orderItemsValue = json_encode($itemsArr); } ?> <div class="row"> <div class="col-lg-4"> <input type="hidden" name="data[order_items]" value="<?php echo CHtml::encode($orderItemsValue); ?> " /> <div class="form-group"> <label>Покупатель</label>
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = OrderItems::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }