/** * Filling the shipment collection data from request * * @internal * * @param Sale\ShipmentCollection $shipmentCollection Entity shipment collection. * @param array $fields An array of request data. * @param Sale\ShipmentCollection $shipmentCollection * @param array $fields * * @return Sale\Result * @throws Main\ArgumentNullException * @throws Main\ArgumentOutOfRangeException * @throws Main\NotSupportedException * @throws Main\ObjectNotFoundException */ public function fillShipmentCollectionFromRequest(Sale\ShipmentCollection $shipmentCollection, array $fields) { $result = new Sale\Result(); /** @var Sale\Order $order */ if (!($order = $shipmentCollection->getOrder())) { throw new Main\ObjectNotFoundException('Entity "Order" not found'); } $shipment = null; $deliveryId = null; $deliveryCode = isset($fields['DELIVERY_ID']) && strval(trim($fields['DELIVERY_ID'])) != '' ? trim($fields['DELIVERY_ID']) : null; if (strval(trim($deliveryCode)) != '') { $deliveryId = \Bitrix\Sale\Delivery\Services\Table::getIdByCode($deliveryCode); } if ($order->getId() > 0) { //todo: check $deliveryId if (count($shipmentCollection) == 2 && $shipmentCollection->isExistsSystemShipment() && $deliveryId > 0) { /** @var Sale\Shipment $shipment */ foreach ($shipmentCollection as $shipment) { if ($shipment->isSystem()) { continue; } unset($fields['DELIVERY_ID']); if ($deliveryId != $shipment->getDeliveryId()) { /** @var Sale\Result $r */ $r = $shipment->setField('DELIVERY_ID', $deliveryId); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); } } if (!empty($fields['PRICE_DELIVERY']) && (double) $fields['PRICE_DELIVERY'] != $shipment->getField('PRICE_DELIVERY')) { $fields['BASE_PRICE_DELIVERY'] = (double) $fields['PRICE_DELIVERY'] + (!empty($fields['PRICE_DELIVERY']) ? floatval($fields['PRICE_DELIVERY']) : 0); unset($fields['PRICE_DELIVERY']); } $shipmentFields = static::convertDateFields($fields, static::getShipmentDateFields()); unset($shipmentFields['ALLOW_DELIVERY']); unset($shipmentFields['DEDUCTED']); /** @var Sale\Result $r */ $r = $shipment->setFields(static::clearFields($shipmentFields, static::getShipmentAvailableFields())); if ($r->isSuccess()) { $orderFields = array(); foreach (static::getShipmentFieldsToConvert() as $checkField) { $checkOrderField = $order->getField($checkField); $isDate = false; if (array_key_exists($checkField, static::getShipmentDateFields())) { $isDate = true; $checkOrderField = static::convertDateFieldToOldFormat($order->getField($checkField)); } if (!empty($fields[$checkField]) && $checkOrderField != trim($fields[$checkField])) { $setValue = $shipment->getField($checkField); if ($isDate) { $setValue = static::convertDateField($checkOrderField, $shipment->getField($checkField), static::getShipmentDateFields()); } if (in_array($checkField, $this->getAvailableFields())) { $order->setFieldNoDemand($checkField, $setValue); } } } } else { $result->addErrors($r->getErrors()); } if ($shipment !== null) { DiscountCompatibility::setShipment($order->getId(), $shipment->getId()); } } } } else { if (intval($deliveryId) == 0) { $deliveryId = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId(); } if (intval($deliveryId) > 0) { /** @var Sale\Shipment $shipment */ if ($shipment = static::createShipmentFromRequest($shipmentCollection, $deliveryId, $fields)) { if (isset($fields['TRACKING_NUMBER']) && strval($fields['TRACKING_NUMBER']) != '') { $shipment->setField('TRACKING_NUMBER', $fields['TRACKING_NUMBER']); } if (isset($fields['DELIVERY_EXTRA_SERVICES']) && is_array($fields['DELIVERY_EXTRA_SERVICES'])) { $shipment->setExtraServices($fields['DELIVERY_EXTRA_SERVICES']); } if (isset($fields['STORE_ID']) && intval($fields['STORE_ID']) > 0) { $shipment->setStoreId($fields['STORE_ID']); } if ($shipment !== null) { DiscountCompatibility::setShipment($order->getId(), $shipment->getId()); } } } } if ($basket = $order->getBasket()) { /** @var Sale\Result $r */ $r = BasketCompatibility::syncShipmentCollectionAndBasket($shipmentCollection, $basket); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); return $result; } } /** @var Sale\Result $r */ $r = static::syncShipmentCollectionFromRequest($shipmentCollection, $fields); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); return $result; } if ($basket) { /** @var Sale\Shipment $shipment */ foreach ($shipmentCollection as $shipment) { if ($shipment->isSystem()) { continue; } /** @var Sale\ShipmentItemCollection $shipmentItemCollection */ if (!($shipmentItemCollection = $shipment->getShipmentItemCollection())) { throw new Main\ObjectNotFoundException('Entity "ShipmentItemCollection" not found'); } if (!empty($fields['BARCODE_LIST']) && is_array($fields['BARCODE_LIST'])) { /** @var Sale\Result $r */ $r = static::fillShipmentItemCollectionFromRequest($shipmentItemCollection, $fields['BARCODE_LIST'], $basket); if (!$r->isSuccess()) { $result->addErrors($r->getErrors()); return $result; } } } } return $result; }
} } $end = microtime(true); file_put_contents($_SERVER["DOCUMENT_ROOT"] . '/bitrix/modules/sale_convert.txt', 'insert into b_sale_order_payment = ' . ($end - $start) . "\n", FILE_APPEND); if (empty($error)) { $message = Loc::getMessage('SALE_CONVERTER_AJAX_STEP_INSERT_SHIPMENT'); $result['NEXT_STEP'] = ++$ajax_step; } else { $message = Loc::getMessage('SALE_CONVERTER_AJAX_STEP_INSERT_PAYMENT'); $result['ERROR'] = true; $message .= "<br>" . $error; } $result['DATA'] = $message; break; case 17: $id = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId(); if ($id <= 0) { $fields["NAME"] = Loc::getMessage('SALE_CONVERTER_EMPTY_DELIVERY_SERVICE'); $fields["CLASS_NAME"] = '\\Bitrix\\Sale\\Delivery\\Services\\EmptyDeliveryService'; $fields["PARENT_ID"] = 0; $fields["CURRENCY"] = 'RUB'; $fields["ACTIVE"] = "Y"; $fields["CONFIG"] = array('MAIN' => array('CURRENCY' => 'RUB', 'PRICE' => 0, 'PERIOD' => array('FROM' => 0, 'TO' => 0, 'TYPE' => 'D'))); $fields["SORT"] = 100; $res = \Bitrix\Sale\Delivery\Services\Table::add($fields); $id = $res->getId(); $fields = array('SORT' => 100, 'DELIVERY_ID' => $id, 'PARAMS' => array('PUBLIC_SHOW' => 'N')); $rstrPM = new \Bitrix\Sale\Delivery\Restrictions\ByPublicMode(); $rstrPM->save($fields); } $start = microtime(true);
/** * @return string * @throws Exception * @internal */ public static function createNoDeliveryServiceAgent() { $id = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId(); if ($id <= 0) { Bitrix\Main\Localization\Loc::loadLanguageFile($_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/sale/lib/delivery/helper.php', 'ru'); $fields = array(); $fields["NAME"] = \Bitrix\Main\Localization\Loc::getMessage('SALE_DELIVERY_HELPER_NO_DELIVERY_SERVICE'); $fields["CLASS_NAME"] = '\\Bitrix\\Sale\\Delivery\\Services\\EmptyDeliveryService'; $fields["CURRENCY"] = 'RUB'; $fields["ACTIVE"] = "Y"; $fields["CONFIG"] = array('MAIN' => array('CURRENCY' => 'RUB', 'PRICE' => 0, 'PERIOD' => array('FROM' => 0, 'TO' => 0, 'TYPE' => 'D'))); $res = \Bitrix\Sale\Delivery\Services\Table::add($fields); $id = $res->getId(); $fields = array('SORT' => 100, 'DELIVERY_ID' => $id, 'PARAMS' => array('PUBLIC_SHOW' => 'N')); $rstrPM = new \Bitrix\Sale\Delivery\Restrictions\ByPublicMode(); $rstrPM->save($fields); } return ""; }
function NextPayment($ID) { global $DB; global $USER; $ID = IntVal($ID); if ($ID <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGR_NO_RECID"), "NO_RECORD_ID"); return False; } $arRecur = CSaleRecurring::GetByID($ID); if (!$arRecur) { $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $ID, GetMessage("SKGR_NO_RECID1")), "NO_RECORD"); return False; } $arOrder = CSaleOrder::GetByID($arRecur["ORDER_ID"]); if (!$arOrder) { $GLOBALS["APPLICATION"]->ThrowException(str_replace("#ID#", $arRecur["ORDER_ID"], GetMessage("SKGR_NO_ORDER1")), "NO_ORDER"); return False; } $bSuccess = True; $newOrderID = IntVal($arRecur["ORDER_ID"]); /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider($arRecur)) { $arProduct = $productProvider::RecurringOrderProduct(array("PRODUCT_ID" => $arRecur["PRODUCT_ID"], "USER_ID" => $arOrder["USER_ID"])); } else { $arProduct = CSaleRecurring::ExecuteCallbackFunction($arRecur["CALLBACK_FUNC"], $arRecur["MODULE"], $arRecur["PRODUCT_ID"], $arOrder["USER_ID"]); } if (!$arProduct || !is_array($arProduct) || empty($arProduct)) { CSaleRecurring::CancelRecurring($arRecur["ID"], "Y", "Product is not found"); return true; } if ($arProduct["WITHOUT_ORDER"] == "Y" || $arRecur["SUCCESS_PAYMENT"] == "Y") { $baseSiteCurrency = CSaleLang::GetLangCurrency($arOrder["LID"]); $productPrice = \Bitrix\Sale\PriceMaths::roundPrecision(CCurrencyRates::ConvertCurrency($arProduct["PRICE"], $arProduct["CURRENCY"], $baseSiteCurrency)); // Delivery $deliveryPrice = 0; $deliveryID = 0; $arOrder["DELIVERY_ID"] = IntVal($arOrder["DELIVERY_ID"]); if ($arOrder["DELIVERY_ID"] > 0) { $deliveryLocation = 0; $dbOrderPropValues = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $arRecur["ORDER_ID"], "PROP_IS_LOCATION" => "Y"), false, false, array("VALUE")); if ($arOrderPropValues = $dbOrderPropValues->Fetch()) { $deliveryLocation = IntVal($arOrderPropValues["VALUE"]); } $dbDelivery = CSaleDelivery::GetList(array("SORT" => "ASC", "NAME" => "ASC"), array("LID" => $arOrder["LID"], "WEIGHT" => DoubleVal($arProduct["WEIGHT"]) * DoubleVal($arProduct["QUANTITY"]), "ORDER_PRICE" => $productPrice * DoubleVal($arProduct["QUANTITY"]), "ACTIVE" => "Y", "LOCATION" => $deliveryLocation)); while ($arDelivery = $dbDelivery->Fetch()) { $deliveryPriceTmp = \Bitrix\Sale\PriceMaths::roundPrecision(CCurrencyRates::ConvertCurrency($arDelivery["PRICE"], $arDelivery["CURRENCY"], $baseSiteCurrency)); if (IntVal($arDelivery["ID"]) == $arOrder["DELIVERY_ID"]) { $deliveryID = IntVal($arDelivery["ID"]); $deliveryPrice = $deliveryPriceTmp; break; } if ($deliveryPriceTmp < $deliveryPrice || $deliveryID <= 0) { $deliveryID = IntVal($arDelivery["ID"]); $deliveryPrice = $deliveryPriceTmp; } } if ($deliveryID <= 0) { $deliveryID = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId(); if ($deliveryID > 0) { $deliveryID = \CSaleDelivery::getCodeById($deliveryID); } } if ($deliveryID <= 0) { $GLOBALS["APPLICATION"]->ThrowException(GetMessage("SKGR_NO_DELIVERY"), "NO_DELIVERY"); return False; } } // Sale discounts $discount = 0; $discountPrice = $productPrice; $discountProduct = 0; $dbDiscount = CSaleDiscount::GetList(array("SORT" => "ASC"), array("LID" => $arOrder["LID"], "ACTIVE" => "Y", "!>ACTIVE_FROM" => Date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL"))), "!<ACTIVE_TO" => Date($DB->DateFormatToPHP(CSite::GetDateFormat("FULL"))), "<=PRICE_FROM" => $productPrice, ">=PRICE_TO" => $productPrice, "USER_GROUPS" => $USER->GetUserGroup($arOrder['USER_ID']))); if ($arDiscount = $dbDiscount->Fetch()) { if ($arDiscount["DISCOUNT_TYPE"] == "P") { $discountProduct = \Bitrix\Sale\PriceMaths::roundPrecision($productPrice * $arDiscount["DISCOUNT_VALUE"] / 100); $discount = \Bitrix\Sale\PriceMaths::roundPrecision($discountProduct * DoubleVal($arProduct["QUANTITY"])); // Changed by Sigurd, 2007-08-16 $discountPrice = $productPrice - $discountProduct; } else { $discountValue = CCurrencyRates::ConvertCurrency($arDiscount["DISCOUNT_VALUE"], $arDiscount["CURRENCY"], $baseSiteCurrency); $discountValue = \Bitrix\Sale\PriceMaths::roundPrecision($discountValue); $discountProduct = \Bitrix\Sale\PriceMaths::roundPrecision(1.0 * $discountValue / DoubleVal($arProduct["QUANTITY"])); // Changed by Sigurd, 2007-08-16 $discount = \Bitrix\Sale\PriceMaths::roundPrecision($curDiscount * DoubleVal($arProduct["QUANTITY"])); $discountPrice = $productPrice - $discountProduct; } } $bUseVat = false; $vatRate = 0; if (DoubleVal($arProduct["VAT_RATE"]) > 0) { $bUseVat = true; $vatRate = $arProduct["VAT_RATE"]; } // Tax $arTaxExempt = array(); $dbUserGroups = CUser::GetUserGroupEx($arOrder["USER_ID"]); while ($arUserGroups = $dbUserGroups->Fetch()) { $dbTaxExemptTmp = CSaleTax::GetExemptList(array("GROUP_ID" => $arUserGroups["GROUP_ID"])); while ($arTaxExemptTmp = $dbTaxExemptTmp->Fetch()) { $arTaxExemptTmp["TAX_ID"] = IntVal($arTaxExemptTmp["TAX_ID"]); if (!in_array($arTaxExemptTmp["TAX_ID"], $arTaxExempt)) { $arTaxExempt[] = $arTaxExemptTmp["TAX_ID"]; } } } $taxPrice = 0; $taxVatPrice = 0; if (!$bUseVat) { $taxLocation = 0; $dbOrderPropValues = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $arRecur["ORDER_ID"], "PROP_IS_LOCATION4TAX" => "Y"), false, false, array("VALUE")); if ($arOrderPropValues = $dbOrderPropValues->Fetch()) { $taxLocation = IntVal($arOrderPropValues["VALUE"]); } $arTaxList = array(); $dbTaxRateTmp = CSaleTaxRate::GetList(array("APPLY_ORDER" => "ASC"), array("LID" => $arOrder["LID"], "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"], "ACTIVE" => "Y", "LOCATION" => $taxLocation)); while ($arTaxRateTmp = $dbTaxRateTmp->Fetch()) { if (!in_array(IntVal($arTaxRateTmp["TAX_ID"]), $arTaxExempt)) { $arTaxList[] = $arTaxRateTmp; } } } else { $arTaxList[] = array("ID" => 0, "TAX_NAME" => GetMessage("SKGR_VAT"), "IS_PERCENT" => "Y", "VALUE" => $vatRate * 100, "VALUE_MONEY" => 0, "APPLY_ORDER" => 100, "IS_IN_PRICE" => "Y", "CODE" => "VAT"); } $arTaxSums = array(); if (!empty($arTaxList)) { if (!$bUseVat) { $taxPriceTmp = CSaleOrderTax::CountTaxes($discountPrice * DoubleVal($arProduct["QUANTITY"]), $arTaxList, $baseSiteCurrency); for ($di = 0, $intCount = count($arTaxList); $di < $intCount; $di++) { $arTaxList[$di]["VALUE_MONEY"] += $arTaxList[$di]["TAX_VAL"]; } for ($di = 0, $intCount = count($arTaxList); $di < $intCount; $di++) { $arTaxSums[$arTaxList[$di]["TAX_ID"]]["VALUE"] = $arTaxList[$di]["VALUE_MONEY"]; $arTaxSums[$arTaxList[$di]["TAX_ID"]]["NAME"] = $arTaxList[$di]["NAME"]; if ($arTaxList[$di]["IS_IN_PRICE"] != "Y") { $taxPrice += $arTaxList[$di]["VALUE_MONEY"]; } } } else { $arTaxList[0]["VALUE_MONEY"] = \Bitrix\Sale\PriceMaths::roundPrecision($discountPrice / ($vatRate + 1) * $vatRate * DoubleVal($arProduct["QUANTITY"])); $taxVatPrice = $arTaxList[0]["VALUE_MONEY"]; } } // Changed by Sigurd, 2007-08-16 $totalOrderPrice = $discountPrice * DoubleVal($arProduct["QUANTITY"]) + $deliveryPrice + $taxPrice; $arProduct["WITHOUT_ORDER"] = $arProduct["WITHOUT_ORDER"] == "Y" ? "Y" : "N"; if ($arProduct["WITHOUT_ORDER"] == "N") { $DB->StartTransaction(); // Saving $arSaleUser = CSaleUser::GetList(array(), array("USER_ID" => $arOrder["USER_ID"])); if (!empty($arSaleUser)) { $currentFUser = $arSaleUser["ID"]; } else { $currentFUser = CSaleUser::_Add(array("=DATE_INSERT" => $DB->GetNowFunction(), "=DATE_UPDATE" => $DB->GetNowFunction(), "USER_ID" => $arOrder["USER_ID"])); } $arFields = array("FUSER_ID" => $currentFUser, "PRODUCT_ID" => $arProduct["PRODUCT_ID"], "PRODUCT_NAME" => $arProduct["PRODUCT_NAME"], "PRODUCT_URL" => $arProduct["PRODUCT_URL"], "PRODUCT_PRICE_ID" => $arProduct["PRODUCT_PRICE_ID"], "PRICE" => $arProduct["PRICE"], "CURRENCY" => $arProduct["CURRENCY"], "WEIGHT" => $arProduct["WEIGHT"], "QUANTITY" => $arProduct["QUANTITY"], "LID" => $arOrder["LID"], "DELAY" => "N", "CAN_BUY" => "Y", "NAME" => $arProduct["NAME"], "CALLBACK_FUNC" => $arProduct["CALLBACK_FUNC"], "ORDER_CALLBACK_FUNC" => $arProduct["ORDER_CALLBACK_FUNC"], "CANCEL_CALLBACK_FUNC" => $arProduct["CANCEL_CALLBACK_FUNC"], "PAY_CALLBACK_FUNC" => $arProduct["PAY_CALLBACK_FUNC"], "PRODUCT_PROVIDER_CLASS" => $arProduct["PRODUCT_PROVIDER_CLASS"], "MODULE" => $arRecur["MODULE"], "NOTES" => $arProduct["CATALOG_GROUP_NAME"], "DETAIL_PAGE_URL" => $arProduct["DETAIL_PAGE_URL"], "VATE_RATE" => $arProduct["VATE_RATE"], "PRODUCT_XML_ID" => $arProduct["PRODUCT_XML_ID"], "TYPE" => $arProduct["TYPE"], "RENEWAL" => "Y"); $basketID = CSaleBasket::Add($arFields); $basketID = IntVal($basketID); if ($basketID <= 0) { $bSuccess = False; } if ($bSuccess) { if (CModule::IncludeModule("statistic")) { CStatistic::Set_Event("eStore", "add2basket", $arFields["PRODUCT_ID"]); } $arFields = array("LID" => $arOrder["LID"], "PERSON_TYPE_ID" => $arOrder["PERSON_TYPE_ID"], "PAYED" => "N", "CANCELED" => "N", "STATUS_ID" => "N", "PRICE_DELIVERY" => $deliveryPrice, "ALLOW_DELIVERY" => "N", "PRICE" => $totalOrderPrice, "CURRENCY" => $baseSiteCurrency, "DISCOUNT_VALUE" => $discount, "USER_ID" => $arOrder["USER_ID"], "PAY_SYSTEM_ID" => $arOrder["PAY_SYSTEM_ID"], "DELIVERY_ID" => $deliveryID, "USER_DESCRIPTION" => $arOrder["USER_DESCRIPTION"], "TAX_VALUE" => $bUseVat ? $taxVatPrice : $taxPrice, "STAT_GID" => $arOrder["STAT_GID"], "RECURRING_ID" => $arRecur["ID"]); $newOrderID = CSaleOrder::Add($arFields); $newOrderID = IntVal($newOrderID); if ($newOrderID <= 0) { $bSuccess = False; } } if ($bSuccess) { $arDiscounts = array(); $arDiscounts[$basketID] = $discountProduct; CSaleBasket::OrderBasket($newOrderID, $currentFUser, $arOrder["LID"], $arDiscounts); } if ($bSuccess) { for ($it = 0, $intCount = count($arTaxList); $it < $intCount; $it++) { $arFields = array("ORDER_ID" => $newOrderID, "TAX_NAME" => $arTaxList[$it]["TAX_NAME"], "IS_PERCENT" => $arTaxList[$it]["IS_PERCENT"], "VALUE" => $arTaxList[$it]["IS_PERCENT"] == "Y" ? $arTaxList[$it]["VALUE"] : RoundEx(CCurrencyRates::ConvertCurrency($arTaxList[$it]["VALUE"], $arTaxList[$it]["CURRENCY"], $baseSiteCurrency), 2), "VALUE_MONEY" => $arTaxList[$it]["VALUE_MONEY"], "APPLY_ORDER" => $arTaxList[$it]["APPLY_ORDER"], "IS_IN_PRICE" => $arTaxList[$it]["IS_IN_PRICE"], "CODE" => $arTaxList[$it]["CODE"]); CSaleOrderTax::Add($arFields); } $dbOrderPropValues = CSaleOrderPropsValue::GetList(array(), array("ORDER_ID" => $arRecur["ORDER_ID"]), false, false, array("ORDER_PROPS_ID", "NAME", "CODE", "VALUE", "PROP_IS_PAYER", "PROP_IS_EMAIL")); while ($arOrderPropValues = $dbOrderPropValues->Fetch()) { $arFields = array("ORDER_ID" => $newOrderID, "ORDER_PROPS_ID" => $arOrderPropValues["ORDER_PROPS_ID"], "NAME" => $arOrderPropValues["NAME"], "CODE" => $arOrderPropValues["CODE"], "VALUE" => $arOrderPropValues["VALUE"]); CSaleOrderPropsValue::Add($arFields); if ($arOrderPropValues["PROP_IS_PAYER"] == "Y") { $payerName = $arOrderPropValues["VALUE"]; } if ($arOrderPropValues["PROP_IS_EMAIL"] == "Y") { $payerEMail = $arOrderPropValues["VALUE"]; } } } if ($bSuccess) { if (CModule::IncludeModule("statistic")) { CStatistic::Set_Event("eStore", "order_create", $newOrderID); } } if ($bSuccess) { $strOrderList = ""; $dbBasketTmp = CSaleBasket::GetList(array("NAME" => "ASC"), array("ORDER_ID" => $newOrderID)); while ($arBasketTmp = $dbBasketTmp->Fetch()) { $strOrderList .= $arBasketTmp["NAME"] . " - " . $arBasketTmp["QUANTITY"] . " " . GetMessage("SALE_QUANTITY_UNIT"); $strOrderList .= "\n"; } if (strlen($payerName) <= 0 || strlen($payerEMail) <= 0) { $dbUser = CUser::GetByID($arOrder["USER_ID"]); if ($arUser = $dbUser->Fetch()) { if (strlen($payerName) <= 0) { $payerName = $arUser["NAME"] . (strlen($arUser["NAME"]) <= 0 || strlen($arUser["LAST_NAME"]) <= 0 ? "" : " ") . $arUser["LAST_NAME"]; } if (strlen($payerEMail) <= 0) { $payerEMail = $arUser["EMAIL"]; } } } $arFields = array("ORDER_ID" => $newOrderID, "ORDER_DATE" => Date($DB->DateFormatToPHP(CLang::GetDateFormat("SHORT", $arOrder["LID"]))), "ORDER_USER" => $payerName, "PRICE" => SaleFormatCurrency($totalOrderPrice, $baseSiteCurrency), "BCC" => COption::GetOptionString("sale", "order_email", "order@" . $SERVER_NAME), "EMAIL" => $payerEMail, "ORDER_LIST" => $strOrderList, "SALE_EMAIL" => COption::GetOptionString("sale", "order_email", "order@" . $SERVER_NAME)); $eventName = "SALE_NEW_ORDER_RECURRING"; $bSend = true; foreach (GetModuleEvents("sale", "OnOrderRecurringSendEmail", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array($newOrderID, &$eventName, &$arFields)) === false) { $bSend = false; } } if ($bSend) { $event = new CEvent(); $event->Send($eventName, $arOrder["LID"], $arFields, "N"); } } if ($bSuccess) { $DB->Commit(); } else { $DB->Rollback(); } } } else { $totalOrderPrice = $arOrder["PRICE"]; $baseSiteCurrency = $arOrder["CURRENCY"]; } $res = False; if ($bSuccess) { $res = CSaleUserAccount::Pay($arOrder["USER_ID"], $totalOrderPrice, $baseSiteCurrency, $newOrderID, True); if ($res) { if ($arProduct["WITHOUT_ORDER"] == "N") { CSaleOrder::PayOrder($newOrderID, "Y", False, False, $arRecur["ID"]); CSaleOrder::DeliverOrder($newOrderID, "Y", $arRecur["ID"]); CSaleOrder::DeductOrder($newOrderID, "Y", "", true, array(), $arRecur["ID"]); } else { /** @var $productProvider IBXSaleProductProvider */ if ($productProvider = CSaleBasket::GetProductProvider($arProduct)) { $r = $productProvider::DeliverProduct(array("PRODUCT_ID" => $arProduct["PRODUCT_ID"], "USER_ID" => $arOrder["USER_ID"], "PAID" => true, 'BASKET_ID' => $basketID)); } else { $r = CSaleBasket::ExecuteCallbackFunction($arProduct["PAY_CALLBACK_FUNC"], $arRecur["MODULE"], $arProduct["PRODUCT_ID"], $arOrder["USER_ID"], true); } } $arFields = array("ORDER_ID" => $newOrderID, "PRODUCT_NAME" => $arProduct["PRODUCT_NAME"], "PRODUCT_URL" => $arProduct["PRODUCT_URL"], "PRICE_TYPE" => $arProduct["PRICE_TYPE"], "RECUR_SCHEME_TYPE" => $arProduct["RECUR_SCHEME_TYPE"], "RECUR_SCHEME_LENGTH" => $arProduct["RECUR_SCHEME_LENGTH"], "WITHOUT_ORDER" => $arProduct["WITHOUT_ORDER"], "PRIOR_DATE" => Date($GLOBALS["DB"]->DateFormatToPHP(CLang::GetDateFormat("FULL", SITE_ID))), "NEXT_DATE" => $arProduct["NEXT_DATE"], "REMAINING_ATTEMPTS" => Defined("SALE_PROC_REC_ATTEMPTS") ? SALE_PROC_REC_ATTEMPTS : 3, "SUCCESS_PAYMENT" => "Y"); CSaleRecurring::Update($arRecur["ID"], $arFields); } else { $arFields = array("ORDER_ID" => $newOrderID, "PRODUCT_NAME" => $arProduct["PRODUCT_NAME"], "PRODUCT_URL" => $arProduct["PRODUCT_URL"], "PRICE_TYPE" => $arProduct["PRICE_TYPE"], "RECUR_SCHEME_LENGTH" => $arProduct["RECUR_SCHEME_LENGTH"], "RECUR_SCHEME_TYPE" => $arProduct["RECUR_SCHEME_TYPE"], "WITHOUT_ORDER" => $arProduct["WITHOUT_ORDER"], "NEXT_DATE" => Date($GLOBALS["DB"]->DateFormatToPHP(CLang::GetDateFormat("FULL", SITE_ID)), time() + SALE_PROC_REC_TIME + CTimeZone::GetOffset()), "REMAINING_ATTEMPTS" => IntVal($arRecur["REMAINING_ATTEMPTS"]) - 1, "SUCCESS_PAYMENT" => "N"); CSaleRecurring::Update($arRecur["ID"], $arFields); if (IntVal($arRecur["REMAINING_ATTEMPTS"]) - 1 <= 0) { CSaleRecurring::CancelRecurring($arRecur["ID"], "Y", "Can't pay order"); /* $arFields["CANCELED"] = "Y"; $arFields["DATE_CANCELED"] = Date(CDatabase::DateFormatToPHP(CLang::GetDateFormat("FULL", LANG))); $arFields["CANCELED_REASON"] = "Can't pay order"; */ } } } return $res; }