public static function SetTaxRateLocation($ID, $arFields, $arOptions = array()) { if (CSaleLocation::isLocationProMigrated()) { Helper::resetLocationsForEntity($ID, $arFields, self::CONN_ENTITY_NAME, !!$arOptions['EXPECT_LOCATION_CODES']); } else { global $DB; $ID = intval($ID); if (0 >= $ID) { return; } $DB->Query("DELETE FROM b_sale_tax2location WHERE TAX_RATE_ID = " . $ID); if (is_array($arFields)) { $countField = count($arFields); for ($i = 0; $i < $countField; $i++) { $arFields[$i]["LOCATION_ID"] = intval($arFields[$i]["LOCATION_ID"]); if ($arFields[$i]["LOCATION_TYPE"] != "G") { $arFields[$i]["LOCATION_TYPE"] = "L"; } if ($arFields[$i]["LOCATION_ID"] > 0) { $strSql = "INSERT INTO b_sale_tax2location(TAX_RATE_ID, LOCATION_CODE, LOCATION_TYPE) " . "VALUES(" . $ID . ", " . $arFields[$i]["LOCATION_ID"] . ", '" . $arFields[$i]["LOCATION_TYPE"] . "')"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } } } }
function Update($ID, $arFields, $arOptions = array()) { global $DB; $ID = intval($ID); if ($ID <= 0 || !CSaleDelivery::CheckFields("UPDATE", $arFields)) return false; if (array_key_exists("LOGOTIP", $arFields) && is_array($arFields["LOGOTIP"])) $arFields["LOGOTIP"]["MODULE_ID"] = "sale"; CFile::SaveForDB($arFields, "LOGOTIP", "sale/delivery/logotip"); $strUpdate = $DB->PrepareUpdate("b_sale_delivery", $arFields); $strSql = "UPDATE b_sale_delivery SET ".$strUpdate." WHERE ID = ".$ID.""; $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); if (is_set($arFields, "LOCATIONS")) { if(CSaleLocation::isLocationProMigrated()) { Helper::resetLocationsForEntity($ID, $arFields['LOCATIONS'], self::CONN_ENTITY_NAME, !!$arOptions['EXPECT_LOCATION_CODES']); } else { $DB->Query("DELETE FROM b_sale_delivery2location WHERE DELIVERY_ID = ".$ID.""); $countarFieldLoc = count($arFields["LOCATIONS"]); for ($i = 0; $i < $countarFieldLoc; $i++) { // change location id to location code $arFields["LOCATIONS"][$i]['LOCATION_CODE'] = $arFields["LOCATIONS"][$i]['LOCATION_ID']; unset($arFields["LOCATIONS"][$i]['LOCATION_ID']); $arInsert = $DB->PrepareInsert("b_sale_delivery2location", $arFields["LOCATIONS"][$i]); $strSql = "INSERT INTO b_sale_delivery2location(DELIVERY_ID, ".$arInsert[0].") ". "VALUES(".$ID.", ".$arInsert[1].")"; $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); } } } if (is_set($arFields, "PAY_SYSTEM")) { CSaleDelivery::UpdateDeliveryPay($ID, $arFields["PAY_SYSTEM"]); } return $ID; }
/** * @param $arFields * @param array $arOptions * @return bool|int * @throws Exception * @deprecated */ static function Add($arFields, $arOptions = array()) { $fields = array_intersect_key($arFields, Bitrix\Sale\Delivery\Services\Table::getMap()); if (array_key_exists("LOGOTIP", $arFields) && is_array($arFields["LOGOTIP"])) { $arFields["LOGOTIP"]["MODULE_ID"] = "sale"; CFile::SaveForDB($arFields, "LOGOTIP", "sale/delivery/logotip"); $fields["LOGOTIP"] = $arFields["LOGOTIP"]; } $fields["CODE"] = isset($arFields["CODE"]) ? $arFields["CODE"] : strval(mktime()); $fields["PARENT_ID"] = 0; $fields["CLASS_NAME"] = '\\Bitrix\\Sale\\Delivery\\Services\\Configurable'; $fields["CONFIG"] = array("MAIN" => array("PRICE" => $arFields["PRICE"], "PERIOD" => array("FROM" => $arFields["PERIOD_FROM"], "TO" => $arFields["PERIOD_TO"], "TYPE" => $arFields["PERIOD_TYPE"]))); $res = \Bitrix\Sale\Delivery\Services\Table::add($fields); if (!$res->isSuccess()) { return false; } $newId = $res->getId(); $res = \Bitrix\Sale\Delivery\Restrictions\Table::add(array("DELIVERY_ID" => $newId, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\BySite', "PARAMS" => array("SITE_ID" => array($arFields["LID"])))); if (intval($arFields["WEIGHT_FROM"]) > 0 || intval($arFields["WEIGHT_TO"]) > 0) { $res = \Bitrix\Sale\Delivery\Restrictions\Table::add(array("DELIVERY_ID" => $newId, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByWeight', "PARAMS" => array("MIN_WEIGHT" => $arFields["WEIGHT_FROM"], "MAX_WEIGHT" => $arFields["WEIGHT_TO"]))); } if (intval($arFields["ORDER_PRICE_FROM"]) > 0 || intval($arFields["ORDER_PRICE_TO"]) > 0) { $res = \Bitrix\Sale\Delivery\Restrictions\Table::add(array("DELIVERY_ID" => $newId, "CLASS_NAME" => '\\Bitrix\\Sale\\Delivery\\Restrictions\\ByPrice', "PARAMS" => array("MIN_PRICE" => $arFields["ORDER_PRICE_FROM"], "MAX_PRICE" => $arFields["ORDER_PRICE_TO"], "CURRENCY" => $arFields["ORDER_CURRENCY"]))); } if (isset($arFields["LOCATIONS"]) && is_array($arFields["LOCATIONS"])) { Helper::resetLocationsForEntity($newId, $arFields['LOCATIONS'], self::CONN_ENTITY_NAME, !!$arOptions['EXPECT_LOCATION_CODES']); } if (isset($arFields["PAY_SYSTEM"])) { CSaleDelivery::UpdateDeliveryPay($newId, $arFields["PAY_SYSTEM"]); } if (isset($arFields["STORE"])) { $stores = unserialize($arFields["STORE"]); if ($stores) { \Bitrix\Sale\Delivery\ExtraServices\Manager::saveStores($newId, $stores); } } return $newId; }
function Add($arFields, $arOptions = array()) { global $DB; if (!CSaleDelivery::CheckFields("ADD", $arFields)) { return false; } if (array_key_exists("LOGOTIP", $arFields) && is_array($arFields["LOGOTIP"])) { $arFields["LOGOTIP"]["MODULE_ID"] = "sale"; } CFile::SaveForDB($arFields, "LOGOTIP", "sale/delivery/logotip"); $arInsert = $DB->PrepareInsert("b_sale_delivery", $arFields); $strSql = "INSERT INTO b_sale_delivery(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); $ID = IntVal($DB->LastID()); if (CSaleLocation::isLocationProMigrated()) { Helper::resetLocationsForEntity($ID, $arFields['LOCATIONS'], self::CONN_ENTITY_NAME, !!$arOptions['EXPECT_LOCATION_CODES']); } else { foreach ($arFields["LOCATIONS"] as $location) { // change location id to location code $location['LOCATION_CODE'] = $location['LOCATION_ID']; unset($location['LOCATION_ID']); $arInsert = $DB->PrepareInsert("b_sale_delivery2location", $location); $strSql = "INSERT INTO b_sale_delivery2location(DELIVERY_ID, " . $arInsert[0] . ") " . "VALUES(" . $ID . ", " . $arInsert[1] . ")"; $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } } if (is_set($arFields, "PAY_SYSTEM")) { CSaleDelivery::UpdateDeliveryPay($ID, $arFields["PAY_SYSTEM"]); } return $ID; }