• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/providerbase.php
  • Класс: BitrixSaleProviderBase
  • Вызов: ProviderBase::refreshMarkers
static function refreshMarkers(Order $order)
{
	if ($order->getId() == 0)
	{
		return;
	}

	if (!$shipmentCollection = $order->getShipmentCollection())
	{
		throw new ObjectNotFoundException('Entity "ShipmentCollection" not found');
	}

	if (!$paymentCollection = $order->getPaymentCollection())
	{
		throw new ObjectNotFoundException('Entity "PaymentCollection" not found');
	}

	if (!$basket = $order->getBasket())
	{
		throw new ObjectNotFoundException('Entity "Basket" not found');
	}

	$markList = array();

	$markerEntityList = array();

	$filter = array(
		'filter' => array(
			'=ORDER_ID' => $order->getId(),
			'!=SUCCESS' => EntityMarker::ENTITY_SUCCESS_CODE_DONE
		),
		'select' => array('ID', 'ENTITY_TYPE', 'ENTITY_ID', 'CODE', 'SUCCESS'),
		'order' => array('ID' => 'DESC')
	);
	$res = EntityMarker::getList($filter);
	while($markerData = $res->fetch())
	{
		if (!empty($markList[$markerData['ENTITY_TYPE']])
			&& !empty($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']])
			&& $markerData['CODE'] == $markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']]
		)
		{
			continue;
		}

		if ($markerData['SUCCESS'] != EntityMarker::ENTITY_SUCCESS_CODE_DONE)
		{
			$markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']][] = $markerData['CODE'];
		}

		if ($poolItemSuccess = EntityMarker::getPoolItemSuccess($order, $markerData['ID'], $markerData['ENTITY_TYPE'], $markerData['ENTITY_ID'], $markerData['CODE']))
		{
			if ($poolItemSuccess == EntityMarker::ENTITY_SUCCESS_CODE_DONE)
			{
				foreach ($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']] as $markerIndex => $markerCode)
				{
					if ($markerData['CODE'] == $markerCode)
					{
						unset($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']][$markerIndex]);
					}
				}

				if (empty($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']]))
				{
					unset($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']]);
				}
			}
		}

		if (empty($markList[$markerData['ENTITY_TYPE']]))
		{
			unset($markList[$markerData['ENTITY_TYPE']]);
		}
	}

	if (!empty($markList))
	{
		foreach ($markList as $markEntityType => $markEntityList)
		{
			foreach ($markEntityList as $markEntityId => $markEntityCodeList)
			{
				if (empty($markEntityCodeList))
				{
					if (($entity = EntityMarker::getEntity($order, $markEntityType, $markEntityId)) && ($entity instanceof IEntityMarker))
					{
						if ($entity->canMarked())
						{
							$markedField = $entity->getMarkField();
							$entity->setField($markedField, 'N');
						}
					}
				}
			}
		}
	}

	if (empty($markList) && !EntityMarker::hasErrors($order))
	{
		if ($shipmentCollection->isMarked())
		{
			/** @var Shipment $shipment */
			foreach ($shipmentCollection as $shipment)
			{
				if ($shipment->isMarked())
				{
					$shipment->setField('MARKED', 'N');
				}
			}
		}
		if ($paymentCollection->isMarked())
		{
			/** @var Payment $payment */
			foreach ($paymentCollection as $payment)
			{
				if ($payment->isMarked())
				{
					$payment->setField('MARKED', 'N');
				}
			}
		}

		$order->setField('MARKED', 'N');
	}
}