示例#1
0
 /**
  * Получает параметры заказа
  */
 public function getOrderData()
 {
     $model = new Models_Order();
     $orderData = $model->getOrder(" id = " . DB::quote($_POST['id']));
     $orderData = $orderData[$_POST['id']];
     if ($orderData['number'] == '') {
         $orderData['number'] = $orderData['id'];
         DB::query("UPDATE `" . PREFIX . "order` SET `number`= " . DB::quote($orderData['number']) . " WHERE `id`=" . DB::quote($orderData['id']) . "");
     }
     $orderData['yur_info'] = unserialize(stripslashes($orderData['yur_info']));
     $orderData['order_content'] = unserialize(stripslashes($orderData['order_content']));
     // Запрос для проверки, существует ли система скидок
     $percent = false;
     $discountSyst = false;
     $res = DB::query('SELECT * FROM `' . PREFIX . 'plugins` WHERE `folderName` = "discount-system"');
     $act = DB::fetchArray($res);
     $result = DB::query('SHOW TABLES LIKE "' . PREFIX . 'discount-system%"');
     if (DB::numRows($result) == 2 && $act['active']) {
         $percent = 0;
         $discountSyst = true;
     }
     if (!empty($orderData['order_content'])) {
         $product = new Models_Product();
         foreach ($orderData['order_content'] as &$item) {
             foreach ($item as &$v) {
                 $v = rawurldecode($v);
             }
         }
         foreach ($orderData['order_content'] as &$items) {
             $res = $product->getProduct($items['id']);
             $items['image_url'] = mgImageProductPath($res['image_url'], $items['id'], 'small');
             $items['property'] = htmlspecialchars_decode(str_replace('&', '&', $items['property']));
             $response['discount'] = $items['discount'];
             $percent = $items['discount'];
             $items['maxCount'] = $res['count'];
             $variants = DB::query("SELECT `id`, `count` FROM `" . PREFIX . "product_variant`\r\n                  WHERE `product_id`=" . DB::quote($items['id']) . " AND `code`=" . DB::quote($items['code']));
             if ($variant = DB::fetchAssoc($variants)) {
                 $items['variant'] = $variant['id'];
                 $items['maxCount'] = $variant['count'];
             }
             $items['notSet'] = $model->notSetGoods($items['id']);
         }
     }
     //заменить на получение скидки
     $codes = array();
     // Запрос для проверки , существуют ли промокоды.
     $result = DB::query('SHOW TABLES LIKE "' . PREFIX . 'promo-code"');
     if (DB::numRows($result)) {
         $res = DB::query('SELECT * FROM `' . PREFIX . 'plugins` WHERE `folderName` = "promo-code"');
         $act = DB::fetchArray($res);
         if ($act['active']) {
             $res = DB::query('SELECT code, percent FROM `' . PREFIX . 'promo-code` 
       WHERE invisible = 1 
       AND now() >= `from_datetime`
       AND now() <= `to_datetime`');
             while ($code = DB::fetchAssoc($res)) {
                 $codes[] = $code['code'];
                 if ($code['code'] == $orderData['order_content'][0]['coupon']) {
                     $percent = $percent == 0 ? $code['percent'] : $percent;
                 }
             }
         }
     }
     $response['order'] = $orderData;
     $response['order']['discountsSystem'] = $discountSyst;
     $response['order']['discontPercent'] = $percent;
     $response['order']['promoCodes'] = $codes;
     $response['order']['date_delivery'] = $orderData['date_delivery'] ? date('d.m.Y', strtotime($orderData['date_delivery'])) : '';
     $deliveryArray = $model->getDeliveryMethod();
     $response['deliveryArray'] = $deliveryArray;
     $paymentArray = array();
     $i = 1;
     while ($payment = $model->getPaymentMethod($i)) {
         $paymentArray[$i] = $payment;
         $i++;
     }
     $response['paymentArray'] = $paymentArray;
     $this->data = $response;
     return true;
 }