Этот код создает заказ, но не считает скидки. Как правильно посчитать скидки?
$order = Order::create($siteId, $currentUser["ID"]);
$order->setPersonTypeId($request["PERSON_TYPE"]);
$order->setField('CURRENCY', $currencyCode);
if($request["COMMENT"])
$order->setField('USER_DESCRIPTION', $request["COMMENT"]);
$basket = Basket::loadItemsForFUser($fuserId, $siteId);
$order->setBasket($basket);
$shipmentCollection = $order->getShipmentCollection();
$shipmentService = Delivery\Services\Manager::getById($request["DEVIVERY_TYPE"]);
$shipment = $shipmentCollection->createItem();
$shipment->setFields(array(
'DELIVERY_ID' => $shipmentService['ID'],
'DELIVERY_NAME' => $shipmentService['NAME'],
));
$shipmentItemCollection = $shipment->getShipmentItemCollection();
foreach($basket as $basketItem) {
$shipmentItem = $shipmentItemCollection->createItem($basketItem);
$shipmentItem->setQuantity($basketItem->getQuantity());
}
$paymentCollection = $order->getPaymentCollection();
$paySystemService = PaySystem\Manager::getObjectById($request["PAY_TYPE"]);
$payment = $paymentCollection->createItem($paySystemService);
$payment->setField("SUM", $order->getPrice());
$propertyCollection = $order->getPropertyCollection();
$phoneProp = $propertyCollection->getPhone();
$emailProp = $propertyCollection->getUserEmail();
$nameProp = $propertyCollection->getPayerName();
$addressProp = $propertyCollection->getAddress();
$phoneProp->setValue($currentUser["PERSONAL_PHONE"]);
$emailProp->setValue($currentUser["EMAIL"]);
$nameProp->setValue($currentUser["LAST_NAME"]." ".$currentUser["NAME"]." ".$currentUser["SECOND_NAME"]);
$addressProp->setValue($currentUser["PERSONAL_STREET"]);
if($request["PERSON_TYPE"] == 10) {
$companyProperty = $propertyCollection->getItemByOrderPropertyId(92);
$companyAdrProperty = $propertyCollection->getItemByOrderPropertyId(93);
$innProperty = $propertyCollection->getItemByOrderPropertyId(94);
$kppProperty = $propertyCollection->getItemByOrderPropertyId(95);
$companyProperty->setValue($request["ORDER_PROP_92"]);
$companyAdrProperty->setValue($request["ORDER_PROP_93"]);
$innProperty->setValue($request["ORDER_PROP_94"]);
$kppProperty->setValue($request["ORDER_PROP_95"]);
}
if($request["bonusPay"]) {
$applyBonusesProperty = $propertyCollection->getItemByOrderPropertyId(114);
$applyBonusesProperty->setValue($request["applyBonuses"]);
}
$order->doFinalAction(true);
$order->save();