コード例 #1
0
ファイル: calculator.php プロジェクト: webgksupport/alpina
 protected function parseCalcResult($jsonInfo)
 {
     global $APPLICATION;
     $arInfo = json_decode($jsonInfo, true);
     if (is_array($arInfo) && !empty($arInfo)) {
         if (strtolower(SITE_CHARSET) != 'utf-8') {
             $arInfo = \Bitrix\Main\Text\Encoding::convertEncodingArray($arInfo, 'UTF-8', SITE_CHARSET);
         }
         if (isset($arInfo[$this->profileId][2])) {
             $price = 0;
             $price += intval($arInfo[$this->profileId][2]);
             if (isset($arInfo["take"][2]) && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_TAKE_ENABLED')) {
                 $price += intval($arInfo["take"][2]);
             }
             if (isset($arInfo["deliver"][2]) && \CDeliveryPecom::isConfCheckedVal($this->arConfig, 'SERVICE_DELIVERY_ENABLED')) {
                 $price += intval($arInfo["deliver"][2]);
             }
             foreach ($arInfo as $key => $value) {
                 if (substr($key, 0, 3) == "ADD") {
                     $price += intval($arInfo[$key][2]);
                 }
             }
             $arResult = array('RESULT' => 'OK', 'VALUE' => $price, 'PACKS_COUNT' => $this->packsCount);
             $period = "";
             if ($this->profileId == "auto" && !empty($arInfo["periods"])) {
                 $period = $arInfo["periods"];
             } elseif ($this->profileId == "avia" && !empty($arInfo["aperiods"])) {
                 $period = $arInfo["aperiods"];
             }
             if (strlen($period) > 0) {
                 $pos = strpos($period, ':');
                 if ($pos !== false) {
                     $CBXSanitizer = new \CBXSanitizer();
                     $CBXSanitizer->DelAllTags();
                     $arResult["TRANSIT"] = " (" . GetMessage("SALE_DH_PECOM_PERIOD_DAYS") . ") " . $CBXSanitizer->SanitizeHtml(substr($period, $pos + 1));
                 }
             }
         } else {
             if (isset($arInfo["error"])) {
                 $error = implode("<br>", $arInfo["error"]);
                 if (strtolower(SITE_CHARSET) != 'utf-8') {
                     $error = $APPLICATION->ConvertCharset($error, 'utf-8', SITE_CHARSET);
                 }
             } else {
                 $error = GetMessage("SALE_DH_PECOM_ERROR");
             }
             $arResult = array('RESULT' => 'ERROR', 'TEXT' => $error);
         }
     } else {
         $arResult = array('RESULT' => 'ERROR', 'TEXT' => GetMessage("SALE_DH_PECOM_ERROR_NO_RESULTS"));
     }
     return $arResult;
 }