CCrmExternalSaleImport::ParseOrderData

  1. Bitrix24 API (v. 23.675.0)
  2. crm
  3. CCrmExternalSaleImport
  4. ParseOrderData
  • Модуль: crm
  • Путь к файлу: ~/bitrix/modules/crm/classes/general/crm_external_sale_import.php
  • Класс: \CCrmExternalSaleImport
  • Вызов: CCrmExternalSaleImport::ParseOrderData
private function ParseOrderData($orderData, &$modificationLabel, &$arErrors)
{
	if (empty($orderData))
	{
		$arErrors[] = array("PD1", GetMessage("CRM_EXT_SALE_IMPORT_EMPTY_ANSW"));
		return null;
	}

	if (mb_substr(ltrim($orderData), 0, mb_strlen(']+?encoding=[\"']([^>\"']+)[\"'][^>]*\?".">/i", $orderData, $matches))
		$charset = trim($matches[1]);
	if (!empty($charset) && (mb_strtoupper($charset) != mb_strtoupper(SITE_CHARSET)))
		$orderData = CharsetConverter::ConvertCharset($orderData, $charset, SITE_CHARSET);

	$objXML = new CDataXML();
	if ($objXML->LoadString($orderData))
	{
		$arOrderData = $objXML->GetArray();
	}
	else
	{
		$arErrors[] = array("XL1", GetMessage("CRM_EXT_SALE_IMPORT_ERROR_XML"));
		return null;
	}

	$arSettings = array();
	foreach ($arOrderData["CommerceInformation"]["@"] as $key => $value)
	{
		$arSettings[$key] = array();

		$ar1 = explode(";", $value);
		foreach ($ar1 as $v1)
		{
			$ar2 = explode("=", $v1);
			if (count($ar2) == 2)
				$arSettings[$key][trim($ar2[0])] = $ar2[1];
		}

		if (count($arSettings[$key]) <= 0)
			$arSettings[$key] = $value;
	}
	if (!isset($arSettings["SumFormat"]["CRD"]))
		$arSettings["SumFormat"]["CRD"] = '.';
	if (!isset($arSettings["QuantityFormat"]["CRD"]))
		$arSettings["QuantityFormat"]["CRD"] = '.';
	if (!isset($arSettings["DateFormat"]["DF"]))
		$arSettings["DateFormat"]["DF"] = 'yyyy-MM-dd';
	$arSettings["DateFormat"]["DF"] = mb_strtoupper($arSettings["DateFormat"]["DF"]);
	if (!isset($arSettings["TimeFormat"]["DF"]))
		$arSettings["TimeFormat"]["DF"] = 'HH:MM:SS';
	$arSettings["TimeFormat"]["DF"] = str_replace("MM", "MI", $arSettings["TimeFormat"]["DF"]);

	$arOrders = array();

	if (is_array($arOrderData["CommerceInformation"]["#"]) && is_array($arOrderData["CommerceInformation"]["#"]["Document"]))
	{
		foreach ($arOrderData["CommerceInformation"]["#"]["Document"] as $arDocument)
		{
			if ($arDocument["#"]["BusinessTransaction"][0]["#"] == "ItemOrder")
			{
				$v = $this->ParseOrderDataOrder($arDocument, $arSettings);
				if (is_array($v))
				{
					$arOrders[] = $v;
					if (isset($v["DATE_UPDATE"]))
					{
						$modificationLabelTmp = MakeTimeStamp($v["DATE_UPDATE"]);
						if ($modificationLabelTmp > $modificationLabel)
							$modificationLabel = $modificationLabelTmp;
					}
				}
			}
		}
	}

	return $arOrders;
}

Добавить комментарий