• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/discount/migration/orderdiscountmigrator.php
  • Класс: BitrixSaleDiscountMigrationOrderDiscountMigrator
  • Вызов: OrderDiscountMigrator::checkMigrateDiscount
static function checkMigrateDiscount(&$discountData)
{
	if (self::$catalogIncluded === null)
		self::$catalogIncluded = MainLoader::includeModule('catalog');
	if (!self::$catalogIncluded)
		return;

	$coupon = $discountData['COUPON'];
	$hash = md5($discountData['DISCOUNT_ID'].'|'.$discountData['NAME']);
	if (!isset(self::$catalogDiscountsCache[$hash]))
	{
		$discountIterator = CatalogDiscountTable::getList(array(
			'select' => array('*'),
			'filter' => array('=ID' => $discountData['DISCOUNT_ID'], '=NAME' => $discountData['NAME'])
		));
		$existDiscount = $discountIterator->fetch();
		unset($discountIterator);
		if (!empty($existDiscount))
		{
			if ($existDiscount['NAME'] != $discountData['NAME'])
			{
				self::createEmptyDiscount($discountData);
			}
			else
			{
				if ($existDiscount['TYPE'] == CatalogDiscountTable::TYPE_DISCOUNT_SAVE)
				{
					self::createEmptyDiscount($discountData, true);
				}
				else
				{
					$existDiscount['COUPON'] = $discountData['COUPON'];
					$discountData = CatalogDiscountDiscountManager::prepareData(
						$existDiscount, SaleOrderDiscount::getManagerConfig()
					);
				}
			}
		}
		else
		{
			self::createEmptyDiscount($discountData);
		}
		unset($existDiscount);
		self::$catalogDiscountsCache[$hash] = $discountData;
	}
	else
	{
		$discountData = self::$catalogDiscountsCache[$hash];
	}
	$discountData['COUPON'] = $coupon;
}