Beispiel #1
0
 public static function convertNewServiceToOld($service, $sid = false)
 {
     if (!isset($service["CONFIG"]["MAIN"]["SID"])) {
         return false;
     }
     self::initHandlers();
     $handlers = self::getRegisteredHandlers("SID");
     if ($sid !== false) {
         $service["SID"] = $sid;
     } else {
         $service["SID"] = $service["CONFIG"]["MAIN"]["SID"];
     }
     $service["TAX_RATE"] = $service["CONFIG"]["MAIN"]["MARGIN_VALUE"];
     //todo: %, CURRENCY
     $service["INSTALLED"] = 'Y';
     $service["BASE_CURRENCY"] = $service["CURRENCY"];
     $service["SETTINGS"] = $service["CONFIG"]["MAIN"]["OLD_SETTINGS"];
     $service["HANDLER"] = $handlers[$service["SID"]]["HANDLER"];
     if (intval($service["LOGOTIP"]) > 0) {
         $service["LOGOTIP"] = \CFile::getFileArray($service["LOGOTIP"]);
     }
     $siteId = false;
     if (isset($service["ID"]) && intval($service["ID"]) > 0) {
         $restrictions = \Bitrix\Sale\Delivery\Services\Manager::getRestrictionsByDeliveryId($service["ID"]);
         foreach ($restrictions as $restriction) {
             if ($restriction["CLASS_NAME"] == '\\Bitrix\\Sale\\Delivery\\Restrictions\\BySite' && !empty($restriction["PARAMS"]["SITE_ID"])) {
                 if (is_array($restriction["PARAMS"]["SITE_ID"])) {
                     reset($restriction["PARAMS"]["SITE_ID"]);
                     $siteId = current($restriction["PARAMS"]["SITE_ID"]);
                 } else {
                     $siteId = $restriction["PARAMS"]["SITE_ID"];
                 }
                 break;
             }
         }
     }
     if (!$siteId) {
         $siteId = Helper::getDefaultSiteId();
     }
     $service["CONFIG"] = self::createConfig($handlers[$service["SID"]], $service["SETTINGS"], $siteId);
     $service["SETTINGS"] = unserialize($service["SETTINGS"]);
     $service["PROFILES"] = array();
     if (isset($service["ID"]) && intval($service["ID"]) > 0) {
         foreach (Manager::getByParentId($service["ID"]) as $profile) {
             $profileId = $profile["CONFIG"]["MAIN"]["PROFILE_ID"];
             $profileParams = array("TITLE" => $profile["NAME"], "DESCRIPTION" => $profile["DESCRIPTION"], "TAX_RATE" => $service["CONFIG"]["MAIN"]["MARGIN_VALUE"], "ACTIVE" => $profile["ACTIVE"]);
             $restrictions = Manager::getRestrictionsByDeliveryId($profile["ID"]);
             foreach ($restrictions as $restriction) {
                 switch ($restriction["CLASS_NAME"]) {
                     case '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByWeight':
                         $profileParams["RESTRICTIONS_WEIGHT"] = array($restriction["PARAMS"]["MIN_WEIGHT"], $restriction["PARAMS"]["MAX_WEIGHT"]);
                         break;
                     case '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByPrice':
                         $profileParams["RESTRICTIONS_SUM"] = array($restriction["PARAMS"]["MIN_PRICE"], $restriction["PARAMS"]["MAX_PRICE"]);
                         break;
                     case '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByDimensions':
                         $profileParams["RESTRICTIONS_DIMENSIONS"] = array($restriction["PARAMS"]["LENGTH"], $restriction["PARAMS"]["WIDTH"], $restriction["PARAMS"]["HEIGHT"]);
                         $profileParams["RESTRICTIONS_MAX_SIZE"] = $restriction["PARAMS"]["MAX_DIMENSION"];
                         $profileParams["RESTRICTIONS_DIMENSIONS_SUM"] = $restriction["PARAMS"]["MAX_DIMENSIONS_SUM"];
                         break;
                     default:
                         break;
                 }
             }
             $service["PROFILES"][$profileId] = $profileParams;
         }
     }
     unset($service["CODE"]);
     if (strlen($service["SID"]) > 0 && isset($handlers[$service["SID"]])) {
         $result = array_merge($handlers[$service["SID"]], $service);
     } else {
         $result = $service;
     }
     return $result;
 }