25 public static function create(array $params)
27 if(empty($params[
'CURRENCY']))
30 if($params[
'SITE_ID'] ==
'')
33 if(intval($params[
'PERSON_TYPE_ID']) <= 0)
36 if(empty($params[
'CART_ITEMS']))
39 if(empty($params[
'IS_ACCEPT_OLD_PRICE']))
40 $params[
'IS_ACCEPT_OLD_PRICE'] = \CSaleYMHandler::NOT_ACCEPT_OLD_PRICE;
43 $currencyList = \Bitrix\Currency\CurrencyManager::getCurrencyList();
45 if($params[
'CURRENCY'] ==
'RUR' && empty($currencyList[
'RUR']) && !empty($currencyList[
'RUB']))
48 $currency = $params[
'CURRENCY'];
50 if(empty($currencyList[$currency]))
52 $result->addError(
new Error(
Loc::getMessage(
'SALE_YMARKET_ORDER_CURRENCY_NOT_SUPPORTED', array(
'#CURRENCY#' => $currency))));
58 $orderClass = $registry->getOrderClassName();
60 $order = $orderClass::create($params[
'SITE_ID'], \CSaleUser::GetAnonymousUserID(), $currency);
62 $res = $order->setPersonTypeId(intval($params[
'PERSON_TYPE_ID']));
64 if (!$res->isSuccess())
65 $result->addErrors($res->getErrors());
67 if(!empty($params[
'PROPERTIES']))
69 $propCollection = $order->getPropertyCollection();
70 $res = $propCollection->setValuesFromPost(array(
'PROPERTIES' => $params[
'PROPERTIES']), array());
72 if (!$res->isSuccess())
73 $result->addErrors($res->getErrors());
76 $fUserId = $order->getUserId() > 0 ? \Bitrix\Sale\Fuser::getIdByUserId($order->getUserId()) :
null;
77 $isStartField = $order->isStartField();
80 $basketClass = $registry->getBasketClassName();
82 $basket = $basketClass::create($params[
'SITE_ID']);
83 $res = $order->setBasket($basket);
85 if (!$res->isSuccess())
86 $result->addErrors($res->getErrors());
88 $basket->setFUserId($fUserId);
89 $discount = $order->getDiscount();
94 Loader::includeModule(
'catalog');
98 foreach ($params[
'CART_ITEMS'] as $itemKey => $item)
100 $basketItemFields = array(
101 'PRODUCT_ID' => $item[
'offerId'],
102 'QUANTITY' => $item[
'count'],
103 'PRODUCT_PROVIDER_CLASS' =>
'\Bitrix\Catalog\Product\CatalogProvider'
107 'SITE_ID' => $params[
'SITE_ID'],
108 'CURRENCY' => $params[
'CURRENCY'],
111 if ($order->getUserId() > 0)
113 $context[
'USER_ID'] = $order->getUserId();
118 $res = Catalog\Product\Basket::addProductToBasket($basket, $basketItemFields, $context);
119 $resultData = $res->getData();
121 if (!empty($resultData[
'BASKET_ITEM']))
124 $basketItem = $resultData[
'BASKET_ITEM'];
127 if (!$res->isSuccess())
131 $basketItem->setField(
"QUANTITY", 0);
137 $itemsMap[$basketItem->getBasketCode()] = $itemKey;
153 $r = $basket->refreshData();
154 if (!$r->isSuccess())
160 foreach($basket as $basketItem)
162 $basketCode = $basketItem->getBasketCode();
163 $item = $params[
'CART_ITEMS'][$itemsMap[$basketCode]];
165 $basketItem->setField(
"NAME", $item[
'offerName']);
171 if($basket->count() == 0)
179 $hasMeaningfulFields = $order->hasMeaningfulField();
180 $res = $order->doFinalAction($hasMeaningfulFields);
182 if (!$res->isSuccess())
183 $result->addErrors($res->getErrors());
189 'ITEMS_MAP' => $itemsMap
196 public static function createShipment(\
Bitrix\
Sale\
Order &$order, $deliveryId = 0, $deliveryPrice =
false)
198 $shipments = $order->getShipmentCollection();
201 if($shipments->count() > 0)
202 foreach ($shipments as $shipment)
203 if(!$shipment->isSystem())
206 $shipment = $shipments->createItem();
208 if(intval($deliveryId) > 0)
212 $dlvName = $dlvSrv->getNameWithParent();
214 $dlvName =
'Not found ('.$deliveryId.
')';
216 $shipment->setField(
'DELIVERY_ID', $deliveryId);
217 $shipment->setField(
'DELIVERY_NAME', $dlvName);
220 if($deliveryPrice !==
false)
222 $shipment->setBasePriceDelivery(floatval($deliveryPrice),
true);
225 $basket = $order->getBasket();
229 $shipmentItemCollection = $shipment->getShipmentItemCollection();
230 $basketItems = $basket->getBasketItems();
233 foreach ($basketItems as $basketItem)
236 $shipmentItem = $shipmentItemCollection->createItem($basketItem);
237 $shipmentItem->setQuantity($basketItem->getField(
'QUANTITY'));
243 public static function createPayment(\
Bitrix\
Sale\
Order &$order, $paySystemId = 0)
245 $payments = $order->getPaymentCollection();
248 if($payments->count() > 0)
250 foreach ($payments as $payment)
252 if($payment->isPaid())
253 $payment->setPaid(
"N");
259 $payment = $payments->createItem();
261 if(intval($paySystemId) > 0)
263 $psName =
'Not found ('.$paySystemId.
')';
265 if($ps = PaySystem\Manager::getById($paySystemId))
266 $psName = $ps[
'NAME'];
268 $payment->setField(
'PAY_SYSTEM_ID', $paySystemId);
269 $payment->setField(
'PAY_SYSTEM_NAME', $psName);
272 $payment->setField(
"SUM", $order->getPrice());
static getMessage($code, $replace=null, $language=null)