• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/sender/triggerdontbuy.php
  • Класс: BitrixSaleSenderTriggerDontBuy
  • Вызов: TriggerDontBuy::filter
public function filter()
{
	BitrixMainLoader::includeModule('sale');

	$daysDontBuy = $this->getFieldValue('DAYS_DONT_BUY');
	if(!is_numeric($daysDontBuy))
		$daysDontBuy = 90;

	$dateFrom = new BitrixMainTypeDateTime;
	$dateTo = new BitrixMainTypeDateTime;

	$dateFrom->setTime(0, 0, 0)->add('-' . $daysDontBuy . ' days');
	$dateTo->setTime(0, 0, 0)->add('1 days')->add('-' . $daysDontBuy . ' days');

	if($this->isRunForOldData())
	{
		$filter = array(
			' $dateTo->format(BitrixMainUserFieldTable::MULTIPLE_DATETIME_FORMAT),
		);
	}
	else
	{
		$filter = array(
			'>MAX_DATE_INSERT' => $dateFrom->format(BitrixMainUserFieldTable::MULTIPLE_DATETIME_FORMAT),
			' $dateTo->format(BitrixMainUserFieldTable::MULTIPLE_DATETIME_FORMAT),
		);
	}
	$filter = $filter + array(
		'=LID' => $this->getSiteId()
	);

	$userListDb = BitrixSaleInternalsOrderTable::getList(array(
		'select' => array('BUYER_USER_ID' => 'USER.ID', 'EMAIL' => 'USER.EMAIL', 'BUYER_USER_NAME' => 'USER.NAME'),
		'filter' => $filter,
		'runtime' => array(
			new BitrixMainEntityExpressionField('MAX_DATE_INSERT', 'MAX(%s)', 'DATE_INSERT'),
		),
		'order' => array('USER_ID' => 'ASC')
	));

	if($userListDb->getSelectedRowsCount() > 0)
	{
		$userListDb->addFetchDataModifier(array($this, 'getFetchDataModifier'));
		$this->recipient = $userListDb;
		return true;
	}
	else
		return false;
}