Answer the question
In order to leave comments, you need to log in
How to apply Cart Rules for an order on D7?
This code creates an order, but does not count discounts. How to calculate discounts correctly?
$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();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question