- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/invoice/internals/invoicediscount.php
- Класс: Bitrix\Crm\Invoice\Internals\InvoiceRulesTable
- Вызов: InvoiceRulesTable::clear
static function clear($filter)
{
if (empty($filter) || !is_array($filter))
return;
$ruleList = array();
$orderDiscountList = array();
$orderCouponList = array();
$ruleIterator = self::getList(array(
'select' => array('ID', 'ORDER_DISCOUNT_ID', 'COUPON_ID'),
'filter' => $filter
));
while ($rule = $ruleIterator->fetch())
{
$rule['ID'] = (int)$rule['ID'];
$rule['ORDER_DISCOUNT_ID'] = (int)$rule['ORDER_DISCOUNT_ID'];
$rule['COUPON_ID'] = (int)$rule['COUPON_ID'];
$ruleList[] = $rule['ID'];
}
unset($rule, $ruleIterator);
if (empty($ruleList))
return;
$conn = Main\Application::getConnection();
$helper = $conn->getSqlHelper();
$ruleRows = array_chunk($ruleList, 500);
$mainQuery = 'delete from '.$helper->quote(self::getTableName()).' where '.$helper->quote('ID');
$descrQuery = 'delete from '.$helper->quote(InvoiceRulesDescrTable::getTableName()).' where '.$helper->quote('RULE_ID');
foreach ($ruleRows as &$row)
{
$conn->queryExecute($mainQuery.' in ('.implode(', ', $row).')');
$conn->queryExecute($descrQuery.' in ('.implode(', ', $row).')');
}
unset($row, $descrQuery, $mainQuery, $ruleRows, $ruleList);
unset($helper, $conn);
if (!empty($orderDiscountList))
InvoiceDiscountTable::clearList($orderDiscountList);
unset($orderDiscountList);
if (!empty($orderCouponList))
InvoiceCouponsTable::clearList($orderCouponList);
unset($orderCouponList);
}