Example #1
0
 function __construct($orderID = -1, $proID = -1)
 {
     if (self::$conn == Null) {
         self::$conn = mysqli_connect('localhost', 'root', 'iti', 'eShop');
     }
     if ($orderID != -1 && $proID != -1) {
         $query = "select * from orderItems where oID={$orderID} and pID={$proID} limit 1";
         $result = mysqli_query(self::$conn, $query);
         $orderItem = mysqli_fetch_assoc($result);
         $this->oID = $orderItem['oID'];
         $this->pID = $orderItem['pID'];
     }
 }
Example #2
0
 /**
  * 顾客留言
  */
 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);
 }
Example #3
0
    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;
 }
Example #5
0
 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));
 }
Example #6
0
 mysqli_autocommit($conn, false);
 foreach ($_SESSION['cart'] as $pID => $q) {
     $product = new Product($pID);
     if ($product->pQuantity < $q) {
         echo $responce = "no enough amount of " . $product->pName . " we have only " . $product->pQuantity . " of it. We are sorry for that.";
         exit;
     }
 }
 $order = new Order();
 $order->uID = $_SESSION['user'];
 $order->oDate = date("Y-m-d");
 $oID = $order->insert();
 if ($oID == false) {
     $err = true;
 }
 $orderItem = new OrderItems();
 foreach ($_SESSION['cart'] as $pID => $q) {
     $orderItem->oID = $oID;
     $orderItem->pID = $pID;
     $orderItem->quantity = $q;
     $orderItem->insert();
     if ($orderItem == false) {
         $err = true;
     }
     $product = new product($pID);
     $product->pQuantity = $product->pQuantity - $q;
     $product->update($pID);
     if ($product == false) {
         $err = true;
     }
 }