コード例 #1
0
<?php

//Добавление группы(есть подозрение):
use Bitrix\Sale\Delivery\Services;
$res = Services\Manager::add($fields);
if ($res->isSuccess()) {
    $ID = $res->getId();
} else {
    $srvStrError = $res->getErrorMessages();
}
コード例 #2
0
 /** @deprecated */
 public static function Set($code, $arData, $siteId = false)
 {
     global $APPLICATION;
     $serviceParams = self::getServiceParams($code, $siteId);
     $id = isset($serviceParams["ID"]) ? $serviceParams["ID"] : false;
     $update = intval($id) > 0;
     $fields = array_intersect_key($arData, Bitrix\Sale\Delivery\Services\Table::getMap());
     if (!$update) {
         $fields["CODE"] = $code;
         if (!isset($arData["CLASS_NAME"])) {
             $fields["CLASS_NAME"] = '\\Bitrix\\Sale\\Delivery\\Services\\Automatic';
         } else {
             $fields["CLASS_NAME"] = $arData["CLASS_NAME"];
         }
     }
     if (isset($arData["PARENT_ID"])) {
         $fields["PARENT_ID"] = $arData["PARENT_ID"];
     } elseif (!$update) {
         $fields["PARENT_ID"] = 0;
     }
     if (!defined('SALE_DH_INITIALIZED')) {
         CSaleDeliveryHandler::Initialize();
     }
     $handlers = self::__getRegisteredHandlers();
     if (isset($serviceParams["CONFIG"])) {
         $fields["CONFIG"] = $serviceParams["CONFIG"];
     } else {
         $fields["CONFIG"] = array();
     }
     if (isset($arData["CONFIG"])) {
         if (isset($handlers[$code]["DBSETSETTINGS"]) && is_callable($handlers[$code]["DBSETSETTINGS"])) {
             if (!($strOldSettings = call_user_func($handlers[$code]["DBSETSETTINGS"], $arData["CONFIG"]))) {
                 $APPLICATION->ThrowException("Can't save delivery services's old settings");
                 return false;
             }
         } else {
             $strOldSettings = $arData["CONFIG"];
         }
         $strOldSettings = serialize($strOldSettings);
         $fields["CONFIG"]["MAIN"]["OLD_SETTINGS"] = $strOldSettings;
     }
     if (!empty($arData["BASE_CURRENCY"])) {
         $fields["CURRENCY"] = $arData["BASE_CURRENCY"];
     } elseif (!empty($serviceParams["CURRENCY"])) {
         $fields["CURRENCY"] = $serviceParams["CURRENCY"];
     } elseif (!empty($handlers[$code]["BASE_CURRENCY"])) {
         $fields["CURRENCY"] = $handlers[$code]["BASE_CURRENCY"];
     } else {
         $fields["CURRENCY"] = COption::GetOptionString('sale', 'default_currency', 'RUB');
     }
     if (!empty($arData["SID"])) {
         $fields["CONFIG"]["MAIN"]["SID"] = $arData["SID"];
     }
     if (isset($arData["TAX_RATE"]) && floatval($arData["TAX_RATE"]) > 0) {
         $fields["CONFIG"]["MAIN"]["MARGIN_VALUE"] = $arData["TAX_RATE"];
         $fields["CONFIG"]["MAIN"]["MARGIN_TYPE"] = "%";
     } elseif (!$update) {
         $fields["CONFIG"]["MAIN"]["MARGIN"] = 0;
     }
     if (!empty($arData["PROFILE_ID"])) {
         $fields["CONFIG"]["MAIN"]["PROFILE_ID"] = $arData["PROFILE_ID"];
     }
     if (isset($arData["LOGOTIP"]) && is_array($arData["LOGOTIP"])) {
         $fields["LOGOTIP"] = $arData["LOGOTIP"];
         $fields["LOGOTIP"]["MODULE_ID"] = "sale";
         CFile::SaveForDB($fields, "LOGOTIP", "sale/delivery/logotip");
     }
     if ($update) {
         $res = \Bitrix\Sale\Delivery\Services\Manager::update($id, $fields);
     } else {
         $res = \Bitrix\Sale\Delivery\Services\Manager::add($fields);
     }
     if (!$res->isSuccess()) {
         throw new \Bitrix\Main\SystemException(implode("\n", $res->getErrorMessages()));
     }
     if (!$update) {
         $id = $res->getId();
     }
     if (is_array($arData["PROFILES"])) {
         foreach ($arData["PROFILES"] as $profileCode => $profileData) {
             if (strlen($profileData["TITLE"]) > 0) {
                 $name = $profileData["TITLE"];
             } elseif (strlen($handlers[$code]['PROFILES'][$profileCode]['TITLE']) > 0) {
                 $name = $handlers[$code]['PROFILES'][$profileCode]['TITLE'];
             } else {
                 $name = "-";
             }
             self::Set($code . ":" . $profileCode, array("NAME" => $name, "DESCRIPTION" => isset($profileData["DESCRIPTION"]) ? $profileData["DESCRIPTION"] : '', "ACTIVE" => isset($profileData["ACTIVE"]) ? $profileData["ACTIVE"] : "N", "TAX_RATE" => isset($profileData["TAX_RATE"]) ? $profileData["TAX_RATE"] : 0, "PARENT_ID" => isset($profileData["PARENT_ID"]) ? $profileData["PARENT_ID"] : $id, "SORT" => isset($arData["SORT"]) ? $arData["SORT"] : 100, "RESTRICTIONS_WEIGHT" => isset($profileData["RESTRICTIONS_WEIGHT"]) ? $profileData["RESTRICTIONS_WEIGHT"] : false, "RESTRICTIONS_SUM" => isset($profileData["RESTRICTIONS_SUM"]) ? $profileData["RESTRICTIONS_SUM"] : false, "RESTRICTIONS_DIMENSIONS" => isset($profileData["RESTRICTIONS_DIMENSIONS"]) ? $profileData["RESTRICTIONS_DIMENSIONS"] : false, "RESTRICTIONS_MAX_SIZE" => isset($profileData["RESTRICTIONS_MAX_SIZE"]) ? $profileData["RESTRICTIONS_MAX_SIZE"] : 0, "RESTRICTIONS_DIMENSIONS_SUM" => isset($profileData["RESTRICTIONS_DIMENSIONS_SUM"]) ? $profileData["RESTRICTIONS_DIMENSIONS_SUM"] : 0, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Services\\AutomaticProfile', "PROFILE_ID" => $profileCode), strlen($siteId) > 0 ? $siteId : "");
         }
     }
     if (strlen($siteId) > 0) {
         if (!self::saveRestrictionBySiteId($id, $siteId, $update)) {
             $APPLICATION->ThrowException("Can't save delivery restriction by site", "SITE_ID");
             return false;
         }
     } elseif ($update) {
         \Bitrix\Sale\Delivery\Restrictions\Manager::deleteByDeliveryIdClassName($id, '\\Bitrix\\Sale\\Delivery\\Restrictions\\BySite');
     }
     if (is_array($arData["RESTRICTIONS_WEIGHT"]) && (floatval($arData["RESTRICTIONS_WEIGHT"][0]) > 0 || floatval($arData["RESTRICTIONS_WEIGHT"][1]) > 0)) {
         if (!self::saveRestrictionByWeight($id, $arData["RESTRICTIONS_WEIGHT"], $update)) {
             $APPLICATION->ThrowException("Can't save delivery restriction by weight", "RESTRICTIONS_WEIGHT");
             return false;
         }
     } elseif ($update) {
         \Bitrix\Sale\Delivery\Restrictions\Manager::deleteByDeliveryIdClassName($id, '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByWeight');
     }
     if (is_array($arData["RESTRICTIONS_SUM"]) && (floatval($arData["RESTRICTIONS_SUM"][0]) > 0 || floatval($arData["RESTRICTIONS_SUM"][1]) > 0)) {
         if (!self::saveRestrictionByPrice($id, $arData["RESTRICTIONS_SUM"], $fields["CURRENCY"], $update)) {
             $APPLICATION->ThrowException("Can't save delivery restriction by sum", "RESTRICTIONS_SUM");
             return false;
         }
     } elseif ($update) {
         \Bitrix\Sale\Delivery\Restrictions\Manager::deleteByDeliveryIdClassName($id, '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByPrice');
     }
     if (is_array($arData["RESTRICTIONS_DIMENSIONS"]) && (floatval($arData["RESTRICTIONS_DIMENSIONS"][0]) > 0 || floatval($arData["RESTRICTIONS_DIMENSIONS"][1]) > 0 || floatval($arData["RESTRICTIONS_DIMENSIONS"][3]) > 0)) {
         if (!self::saveRestrictionByDimensions($id, array("LENGTH" => count($arData["RESTRICTIONS_DIMENSIONS"][0]) > 0 ? $arData["RESTRICTIONS_DIMENSIONS"][0] : 0, "WIDTH" => isset($arData["RESTRICTIONS_DIMENSIONS"][1]) ? $arData["RESTRICTIONS_DIMENSIONS"][1] : 0, "HEIGHT" => isset($arData["RESTRICTIONS_DIMENSIONS"][2]) ? $arData["RESTRICTIONS_DIMENSIONS"][2] : 0), $update)) {
             $APPLICATION->ThrowException("Can't save delivery restriction by dimensions");
             return false;
         }
     } elseif ($update) {
         \Bitrix\Sale\Delivery\Restrictions\Manager::deleteByDeliveryIdClassName($id, '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByDimensions');
     }
     if (floatval($arData["RESTRICTIONS_MAX_SIZE"]) > 0) {
         if (!self::saveRestrictionByMaxSize($id, $arData["RESTRICTIONS_MAX_SIZE"], $update)) {
             $APPLICATION->ThrowException("Can't save delivery restriction by maxx size", "RESTRICTIONS_MAX_SIZE");
             return false;
         }
     } elseif ($update) {
         \Bitrix\Sale\Delivery\Restrictions\Manager::deleteByDeliveryIdClassName($id, '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByMaxSize');
     }
     return $id;
 }
コード例 #3
0
ファイル: delivery.php プロジェクト: akniyev/itprom_dobrohost
 /**
  * @return string
  * @throws Exception
  * @internal
  */
 public static function createNoDeliveryServiceAgent()
 {
     $id = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId();
     if ($id <= 0) {
         Bitrix\Main\Localization\Loc::loadLanguageFile($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/sale/lib/delivery/helper.php', 'ru');
         $fields = array();
         $fields["NAME"] = \Bitrix\Main\Localization\Loc::getMessage('SALE_DELIVERY_HELPER_NO_DELIVERY_SERVICE');
         $fields["CLASS_NAME"] = '\\Bitrix\\Sale\\Delivery\\Services\\EmptyDeliveryService';
         $fields["CURRENCY"] = 'RUB';
         $fields["ACTIVE"] = "Y";
         $fields["CONFIG"] = array('MAIN' => array('CURRENCY' => 'RUB', 'PRICE' => 0, 'PERIOD' => array('FROM' => 0, 'TO' => 0, 'TYPE' => 'D')));
         $res = \Bitrix\Sale\Delivery\Services\Manager::add($fields);
         $id = $res->getId();
         $fields = array('SORT' => 100, 'SERVICE_ID' => $id, 'SERVICE_TYPE' => \Bitrix\Sale\Delivery\Restrictions\Manager::SERVICE_TYPE_SHIPMENT, 'PARAMS' => array('PUBLIC_SHOW' => 'N'));
         $rstrPM = new \Bitrix\Sale\Delivery\Restrictions\ByPublicMode();
         $rstrPM->save($fields);
     }
     return "";
 }