• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/tradingplatform/vk/map.php
  • Класс: BitrixSaleTradingPlatformVkMap
  • Вызов: Map::checkMappingMatches
static function checkMappingMatches(array $data, array $dataFromVk, $exportId, $type, $isAgressive)
{
//		todo: diff methods for albums and product, wrap over this method
	switch ($type)
	{
		case 'ALBUMS':
			$bxKey = "SECTION_ID";
			$vkKey = "ALBUM_VK_ID";
			$deleteMapMethod = "removeAlbumMapping";
			$dataFromMapping = self::getMappedAlbums($exportId);
			break;
		
		case 'PRODUCTS':
			$bxKey = "BX_ID";
			$vkKey = "VK_ID";
			$deleteMapMethod = "removeProductMapping";
			$dataFromMapping = self::getMappedProducts($exportId);
			break;
		
		default:
			throw new SystemException("Wrong VK-mapping type");
	}

//		FIND items, which exist in VK and map, but not exist on site (was be deleted, changed settings etc)
//		todo: now we can check only current data-chunk (about 25 items) and can't find element,
// 		todo: which exist in VK and MAP, but not added in VK. Must do this function for preserve duplication 
//		todo: old code see in the repo


//		MATCH items between VK and mapping
	$dataMappedToRemove = array();
	foreach ($data as &$item)
	{
		$itemMapped = $dataFromMapping[$item[$bxKey]];
		if (isset($itemMapped))
		{
			if (isset($dataFromVk[$itemMapped[$vkKey]]))
			{
				if ($isAgressive)
				{
//						editing albums/products which exists in VK
					$item[$vkKey] = $dataFromMapping[$item[$bxKey]][$vkKey];
					$item["FLAG_EDIT"] = true;
				}
				else
				{
//						if not agressive export we not editing products/albums
					unset($data[$item[$bxKey]]);
				}
			}
			
			else
			{
//				delete from map albums which not exist in vk
				$item["FLAG_EDIT"] = false;
				$dataMappedToRemove[] = array("VALUE_EXTERNAL" => $itemMapped[$vkKey]);
			}
		}
//			other albums not delete from map and not edit - only adding
		else
			$item["FLAG_EDIT"] = false;
	}

//		DELETE from mapping items which not exist in VK
	if (!empty($dataMappedToRemove))
		self::$deleteMapMethod($dataMappedToRemove, $exportId);
	
	return $data;
}