- Модуль: crm
- Путь к файлу: ~/bitrix/modules/crm/lib/order/manager.php
- Класс: Bitrix\Crm\Order\Manager
- Вызов: Manager::copyOrderProductsToDeal
static function copyOrderProductsToDeal(Order $order, $dealId)
{
$result = [];
$sort = 0;
/** @var BasketItem $basketItem */
foreach ($order->getBasket() as $basketItem)
{
$basePriceWithoutVat = $basketItem->getBasePrice();
if ($basketItem->isVatInPrice())
{
$basePriceWithoutVat -= $basketItem->getVat();
}
$taxValue = $basketItem->getVatRate();
if ($taxValue !== null)
{
$taxValue *= 100;
}
$item = [
'PRODUCT_ID' => $basketItem->getField('PRODUCT_ID'),
'PRODUCT_NAME' => $basketItem->getField('NAME'),
'PRICE' => $basketItem->getBasePrice(),
'PRICE_ACCOUNT' => $basketItem->getBasePrice(),
'PRICE_EXCLUSIVE' => $basePriceWithoutVat,
'PRICE_NETTO' => $basePriceWithoutVat,
'PRICE_BRUTTO' => $basketItem->getBasePrice(),
'QUANTITY' => $basketItem->getQuantity(),
'MEASURE_CODE' => $basketItem->getField('MEASURE_CODE'),
'MEASURE_NAME' => $basketItem->getField('MEASURE_NAME'),
'TAX_RATE' => $taxValue,
'DISCOUNT_SUM' => 0,
'TAX_INCLUDED' => $basketItem->isVatInPrice() ? 'Y' : 'N',
'SORT' => $sort,
];
if ($basketItem->getDiscountPrice() !== 0)
{
$item['DISCOUNT_TYPE_ID'] = \Bitrix\Crm\Discount::MONETARY;
$item['DISCOUNT_SUM'] = $basketItem->getDiscountPrice();
}
$item['PRICE'] -= $item['DISCOUNT_SUM'];
$item['PRICE_ACCOUNT'] -= $item['DISCOUNT_SUM'];
$item['PRICE_EXCLUSIVE'] -= $item['DISCOUNT_SUM'];
$result[] = $item;
$sort += 10;
}
if ($result)
{
\CCrmDeal::SaveProductRows($dealId, $result, false);
}
}