From 686548ab6382767d5274042b69316432443a8bd6 Mon Sep 17 00:00:00 2001 From: gorokh Date: Wed, 12 Feb 2020 12:25:39 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BA=D0=B8=D0=B4=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../classes/general/order/RetailCrmOrder_v5.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index 7dba46e4..da3a3a95 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -212,6 +212,12 @@ class RetailCrmOrder $item['discountManualPercent'] = 0; $item['initialPrice'] = $initialPrice; + $dpItem = $product['BASE_PRICE'] - $product['PRICE']; + if ( $dpItem > 0) { + $item['discountManualAmount'] = $dpItem; + $item['initialPrice'] = (double)$product['BASE_PRICE']; + } + $order['items'][] = $item; if ($send && $dimensionsSetting == 'Y') { From 594feae948d749c46426d14d221d472d91e3f711 Mon Sep 17 00:00:00 2001 From: gorokh Date: Tue, 18 Feb 2020 10:54:42 +0300 Subject: [PATCH 2/4] fix discount --- .../general/history/RetailCrmHistory_v5.php | 90 +- .../general/order/RetailCrmOrder_v5.php | 18 +- intaro.retailcrm/options.php | 1572 +++++++++-------- 3 files changed, 869 insertions(+), 811 deletions(-) diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index 8eef60b7..98d97e59 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -23,6 +23,7 @@ class RetailCrmHistory public static $CRM_ORDER_NUMBERS = 'order_numbers'; public static $CRM_CANSEL_ORDER = 'cansel_order'; public static $CRM_CURRENCY = 'currency'; + public static $CRM_DISCOUNT_ROUND = 'discount_round'; const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED'; @@ -652,22 +653,34 @@ class RetailCrmHistory $response = RCrmActions::apiMethod($api, 'orderGet', __METHOD__, $order['id']); if (isset($response['order'])) { $orderTemp = $response['order']; - $ditems = []; + + $duplicateItems = []; foreach ($orderTemp['items'] as $item) { - $ditems[$item['offer']['externalId']]['quantity'] += $item['quantity']; - $ditems[$item['offer']['externalId']]['discountTotal'] += $item['quantity'] * $item['discountTotal']; - $ditems[$item['offer']['externalId']]['initialPrice'] = (float)$item['initialPrice']; - $ditems[$item['offer']['externalId']]['price_sum'] = $ditems[$item['offer']['externalId']]['initialPrice'] * $ditems[$item['offer']['externalId']]['quantity'] - $ditems[$item['offer']['externalId']]['discountTotal']; - $ditems[$item['offer']['externalId']]['price_item'] = $ditems[$item['offer']['externalId']]['price_sum'] / $ditems[$item['offer']['externalId']]['quantity']; + $duplicateItems[$item['id']]['externalId'] += $item['offer']['externalId']; + $duplicateItems[$item['id']]['quantity'] += $item['quantity']; + $duplicateItems[$item['id']]['discountTotal'] += $item['quantity'] * $item['discountTotal']; + $duplicateItems[$item['id']]['initialPrice'] = (float)$item['initialPrice']; + $duplicateItems[$item['id']]['price_sum'] = ($item['quantity'] * $item['initialPrice']) - ($item['quantity'] * $item['discountTotal']); + } unset($orderTemp); } - $log->write($ditems, 'duplicateItemsOrderHistory'); + $collectItems = []; + foreach ($duplicateItems as $it) { + $collectItems[$it['externalId']]['quantity'] += $it['quantity']; + $collectItems[$it['externalId']]['price_sum'] += $it['price_sum']; + $collectItems[$it['externalId']]['discountTotal_sum'] += $it['discountTotal']; + $collectItems[$it['externalId']]['initialPrice_sum'] += $it['quantity'] * $it['initialPrice']; + } + + $log->write($duplicateItems, 'duplicateItemsOrderHistory'); + $log->write($collectItems, 'collectItemsOrderHistory'); + $optionDiscRound = COption::GetOptionString(self::$MODULE_ID, self::$CRM_DISCOUNT_ROUND, 0); foreach ($order['items'] as $product) { - if($ditems[$product['offer']['externalId']]['quantity']){ - $product['quantity'] = $ditems[$product['offer']['externalId']]['quantity']; + if ($collectItems[$product['offer']['externalId']]['quantity']) { + $product['quantity'] = $collectItems[$product['offer']['externalId']]['quantity']; } $item = self::getExistsItem($basket, 'catalog', $product['offer']['externalId']); @@ -685,7 +698,7 @@ class RetailCrmHistory $item->setFields(array( 'CURRENCY' => $newOrder->getCurrency(), 'LID' => $site, - 'BASE_PRICE' => $product['initialPrice'], + 'BASE_PRICE' => $collectItems[$product['offer']['externalId']]['initialPrice_sum'] / $collectItems[$product['offer']['externalId']]['quantity'], 'NAME' => $product['offer']['name'] ? RCrmActions::fromJSON($product['offer']['name']) : $elem['NAME'], 'DETAIL_PAGE_URL' => $elem['URL'], 'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider', @@ -703,7 +716,7 @@ class RetailCrmHistory } if ($product['delete']) { - if ($ditems[$product['offer']['externalId']]['quantity'] <= 0) { + if ($collectItems[$product['offer']['externalId']]['quantity'] <= 0) { $item->delete(); continue; @@ -712,36 +725,22 @@ class RetailCrmHistory if ($product['quantity']) { $item->setFieldNoDemand('QUANTITY', $product['quantity']); + $item->setField('PRICE', $collectItems[$product['offer']['externalId']]['initialPrice_sum'] / $collectItems[$product['offer']['externalId']]['quantity']); } - if (array_key_exists('discountTotal', $product)) { - $itemCost = $item->getField('PRICE'); + if (array_key_exists('discountTotal_sum', $collectItems[$product['offer']['externalId']])) { + $item->setField('CUSTOM_PRICE', 'Y'); + $item->setField('DISCOUNT_NAME', ''); + $item->setField('DISCOUNT_VALUE', ''); + $item->setField('DISCOUNT_PRICE', $product['discountTotal_sum']); - if (empty($itemCost)) { - $itemCost = $item->getField('BASE_PRICE'); + $price = $collectItems[$product['offer']['externalId']]['price_sum'] / $collectItems[$product['offer']['externalId']]['quantity']; + + if ('Y' == $optionDiscRound) { + $price = self::truncate($price, 2); } - $discount = (double) $item->getField('DISCOUNT_PRICE'); - - if (isset($itemCost) && $itemCost >= 0) { - if ($discount < 0) { - $resultDiscount = $product['discountTotal'] + $discount; - } else { - $resultDiscount = $product['discountTotal']; - } - - $item->setField('CUSTOM_PRICE', 'Y'); - $item->setField('DISCOUNT_NAME', ''); - $item->setField('DISCOUNT_VALUE', ''); - $item->setField('DISCOUNT_PRICE', $resultDiscount); - $item->setField('PRICE', $itemCost - $resultDiscount); - - //set price dublicate item - if ($ditems[$product['offer']['externalId']]['price_item']) { - $item->setField('PRICE', $ditems[$product['offer']['externalId']]['price_item']); - $item->setField('DISCOUNT_PRICE', ''); - } - } + $item->setField('PRICE', $price); } } } @@ -1378,6 +1377,25 @@ class RetailCrmHistory return false; } } + + /** + * Truncate a float number + * + * @param float $val + * @param int f Number of precision + * + * @return float + */ + public static function truncate($val, $precision = "0") + { + if(($p = strpos($val, '.')) !== false + || ($p = strpos($val, ',')) !== false + ) { + $val = floatval(substr($val, 0, $p + 1 + $precision)); + } + + return $val; + } } class RetailUser extends CUser diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index da3a3a95..a883c7e5 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -201,23 +201,23 @@ class RetailCrmOrder $discount = (double) $product['DISCOUNT_PRICE']; - if ($discount < 0) { + //discount + $dpItem = $product['BASE_PRICE'] - $product['PRICE']; + if ( $dpItem > 0 && $discount <= 0) { + $discount = $dpItem; + } + + if ($discount <= 0) { $item['discountManualAmount'] = 0; $initialPrice = (double) $product['PRICE']; } else { - $item['discountManualAmount'] = (double) $product['DISCOUNT_PRICE']; - $initialPrice = (double) $product['PRICE'] + (double) $product['DISCOUNT_PRICE']; + $item['discountManualAmount'] = $discount; + $initialPrice = (double) $product['PRICE'] + $discount; } $item['discountManualPercent'] = 0; $item['initialPrice'] = $initialPrice; - $dpItem = $product['BASE_PRICE'] - $product['PRICE']; - if ( $dpItem > 0) { - $item['discountManualAmount'] = $dpItem; - $item['initialPrice'] = (double)$product['BASE_PRICE']; - } - $order['items'][] = $item; if ($send && $dimensionsSetting == 'Y') { diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 11ff85c4..fb995d66 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -45,6 +45,8 @@ $CRM_ADDRESS_OPTIONS = 'address_options'; $CRM_DIMENSIONS = 'order_dimensions'; $PROTOCOL = 'protocol'; +$CRM_DISCOUNT_ROUND = 'discount_round'; + if(!CModule::IncludeModule('intaro.retailcrm') || !CModule::IncludeModule('sale') || !CModule::IncludeModule('iblock') || !CModule::IncludeModule('catalog')) return; @@ -440,6 +442,15 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { UnRegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmUa", "add"); } + //discount_round + if (htmlspecialchars(trim($_POST['discount_round'])) == 'Y') { + $discount_round = 'Y'; + RegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmDc", "add"); + } else { + $discount_round = 'N'; + UnRegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmDc", "add"); + } + //version $version = COption::GetOptionString($mid, $CRM_API_VERSION); @@ -514,6 +525,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { COption::SetOptionString($mid, $CRM_UA_KEYS, serialize(RCrmActions::clearArr($uaKeys))); COption::SetOptionString($mid, $CRM_DIMENSIONS, $orderDimensions); + COption::SetOptionString($mid, $CRM_DISCOUNT_ROUND, $discount_round); + $request = \Bitrix\Main\Application::getInstance()->getContext()->getRequest(); if ($request->isHttps() === true) { @@ -620,6 +633,8 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $optionUa = COption::GetOptionString($mid, $CRM_UA, 0); $optionUaKeys = unserialize(COption::GetOptionString($mid, $CRM_UA_KEYS)); + $optionDiscRound = COption::GetOptionString($mid, $CRM_DISCOUNT_ROUND, 0); + $version = COption::GetOptionString($mid, $CRM_API_VERSION, 0); //currency @@ -658,807 +673,832 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { ); $tabControl = new CAdminTabControl("tabControl", $aTabs); $tabControl->Begin(); -?> -AddHeadString(''); ?> -'); ?> + - -
-BeginNextTab(); -?> - - - - - - - - - - - - - 1):?> - - - - - - - - - - - - - - - - - -BeginNextTab(); ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - -
- - - value="Y" type="checkbox" /> -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -BeginNextTab(); ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - 4) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 4) && ($addressOptions[$bitrixOrderType['ID']] == 0)) echo 'style="display:none;"';?>> - - - - - - - - - 0):?> - - - - - - - - - - - - - - - - - - - > - - - - - - - - > - - - - - - - - - - -BeginNextTab(); ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 0) :?> - - - - - - - - > - - - - - - > - - - - - - - > - - - - - - - - > - - - - - - > - - - - - - - - > - - - - - - - 0) :?> - - - - - - - - > - - - - - - - - > - - - - - - - > - - - - - - - - > - - - - - - > - - - - - - - - > - - - - - - - - - - - - - - - > - - - - - - > - () - - - - - - - - - - - - - - > - - () - - - > - - - - - - > - - - - - - - -Buttons(); ?> - - -End(); ?> -
- - - - - - - -
-
- -
- - + + + + BeginNextTab(); + ?> + + + + + + + + + + + + + 1):?> + + + + + + + + + + + + BeginNextTab(); ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + BeginNextTab(); ?> + + + + + + + + + + + + + + + + + + + 4) echo 'class="address-detail-' . $bitrixOrderType['ID'] . '"'; if(($countProps > 4) && ($addressOptions[$bitrixOrderType['ID']] == 0)) echo 'style="display:none;"';?>> + + + + + 0):?> + + + + + + + + + + + > + + + + > + + + + + + + BeginNextTab(); ?> + + + + + + + + + + + + + + + + + + + + + + + + + + 0) :?> + + + + > + + + + > + + + + + > + + + + > + + + + > + + + + > + + + + + 0) :?> + + + + > + + + + > + + + + + > + + + + > + + + + > + + + + > + + + + + + + + + > + + + + > + + + + + + + + + + > + + + + + + + + > + + + > + + + + > + + + + + + Buttons(); ?> + + + End(); ?> + + + + + + + + +
+ + +
+
+ + + +
+ +
+ + + +
+ +
+ + + +
+ + + + + +
+
+ + + + + + + +
+ + + value="Y" type="checkbox" /> +
+
+ + + +
+ + + +
+ + + +
+ + + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + + +
+ +
+ +
+ + + +
+ +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
+ + + +
+ +
() + +
+ + + +
+ +
+ + + +
+ () +
+ +
+ +
+ - -
-
-
+ + +
+
-
-
-
-
0%
+
+
+
+
0%
+
+ 0%
- 0% +
+
+
+
+
+
-
-
-
- -
-
-
- + From d47709ba87c0e47b7632bdb0ea5c519cafbe1580 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 19 Feb 2020 14:35:56 +0300 Subject: [PATCH 3/4] fix discounts for multiple positions & annotations --- .../classes/general/events/RetailCrmEvent.php | 4 +- .../general/history/RetailCrmHistory_v5.php | 63 +++++++++++++++---- .../general/order/RetailCrmOrder_v5.php | 48 ++++++++------ 3 files changed, 85 insertions(+), 30 deletions(-) diff --git a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php index da2ffcd1..6902d052 100644 --- a/intaro.retailcrm/classes/general/events/RetailCrmEvent.php +++ b/intaro.retailcrm/classes/general/events/RetailCrmEvent.php @@ -91,7 +91,9 @@ class RetailCrmEvent * @param $event * * @return bool - * @throws InvalidArgumentException + * @throws \Bitrix\Main\ObjectPropertyException + * @throws \Bitrix\Main\SystemException + * @throws \Bitrix\Main\ArgumentException */ function orderSave($event) { diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index 98d97e59..1b86a3cc 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -434,7 +434,7 @@ class RetailCrmHistory } } - if ($newOrder === null) { + if (!isset($newOrder) || $newOrder === null) { RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'Bitrix\Sale\Order::load', 'Error order load number=' . $order['number']); continue; @@ -649,29 +649,59 @@ class RetailCrmHistory if (isset($order['items'])) { $itemUpdate = true; - $response = RCrmActions::apiMethod($api, 'orderGet', __METHOD__, $order['id']); + if (isset($response['order'])) { $orderTemp = $response['order']; - $duplicateItems = []; + foreach ($orderTemp['items'] as $item) { $duplicateItems[$item['id']]['externalId'] += $item['offer']['externalId']; $duplicateItems[$item['id']]['quantity'] += $item['quantity']; - $duplicateItems[$item['id']]['discountTotal'] += $item['quantity'] * $item['discountTotal']; - $duplicateItems[$item['id']]['initialPrice'] = (float)$item['initialPrice']; - $duplicateItems[$item['id']]['price_sum'] = ($item['quantity'] * $item['initialPrice']) - ($item['quantity'] * $item['discountTotal']); - + $duplicateItems[$item['id']]['discountTotal'] += + $item['quantity'] * $item['discountTotal']; + $duplicateItems[$item['id']]['initialPrice'] = (float) $item['initialPrice']; + $duplicateItems[$item['id']]['price_sum'] = ($item['quantity'] * $item['initialPrice']) + - ($item['quantity'] * $item['discountTotal']); } + unset($orderTemp); + } else { + continue; } $collectItems = []; + foreach ($duplicateItems as $it) { $collectItems[$it['externalId']]['quantity'] += $it['quantity']; $collectItems[$it['externalId']]['price_sum'] += $it['price_sum']; $collectItems[$it['externalId']]['discountTotal_sum'] += $it['discountTotal']; - $collectItems[$it['externalId']]['initialPrice_sum'] += $it['quantity'] * $it['initialPrice']; + + if (isset($collectItems[$it['externalId']]['initialPrice_max'])) { + if ($collectItems[$it['externalId']]['initialPrice_max'] < $it['initialPrice']) { + $collectItems[$it['externalId']]['initialPrice_max'] = $it['initialPrice']; + } + } else { + $collectItems[$it['externalId']]['initialPrice_max'] = $it['initialPrice']; + } + + $collectItems[$it['externalId']]['initialPricesList'][] = $it['initialPrice']; + } + + foreach ($collectItems as $key => $itemData) { + if (count($itemData['initialPricesList']) > 1) { + $discountDelta = 0; + + foreach ($itemData['initialPrices'] as $initialPriceItem) { + $delta = $itemData['initialPrice_max'] - (float) $initialPriceItem; + + if ($delta !== 0) { + $discountDelta += $delta; + } + } + + $collectItems[$key]['discountTotal_sum'] += $discountDelta; + } } $log->write($duplicateItems, 'duplicateItemsOrderHistory'); @@ -695,10 +725,11 @@ class RetailCrmHistory if ($item instanceof \Bitrix\Sale\BasketItem) { $elem = self::getInfoElement($product['offer']['externalId']); + $item->setFields(array( 'CURRENCY' => $newOrder->getCurrency(), 'LID' => $site, - 'BASE_PRICE' => $collectItems[$product['offer']['externalId']]['initialPrice_sum'] / $collectItems[$product['offer']['externalId']]['quantity'], + 'BASE_PRICE' => $collectItems[$product['offer']['externalId']]['initialPrice_max'], 'NAME' => $product['offer']['name'] ? RCrmActions::fromJSON($product['offer']['name']) : $elem['NAME'], 'DETAIL_PAGE_URL' => $elem['URL'], 'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider', @@ -725,7 +756,13 @@ class RetailCrmHistory if ($product['quantity']) { $item->setFieldNoDemand('QUANTITY', $product['quantity']); - $item->setField('PRICE', $collectItems[$product['offer']['externalId']]['initialPrice_sum'] / $collectItems[$product['offer']['externalId']]['quantity']); + } + + if (array_key_exists('initialPrice_max', $collectItems[$product['offer']['externalId']])) { + $item->setField( + 'BASE_PRICE', + $collectItems[$product['offer']['externalId']]['initialPrice_max'] + ); } if (array_key_exists('discountTotal_sum', $collectItems[$product['offer']['externalId']])) { @@ -734,7 +771,11 @@ class RetailCrmHistory $item->setField('DISCOUNT_VALUE', ''); $item->setField('DISCOUNT_PRICE', $product['discountTotal_sum']); - $price = $collectItems[$product['offer']['externalId']]['price_sum'] / $collectItems[$product['offer']['externalId']]['quantity']; + // Полную цену позиции с учётом скидок делим на количество - получаем цену каждой единицы + // товара с учётом скидок. + $price = $collectItems[ + $product['offer']['externalId'] + ]['price_sum'] / $collectItems[$product['offer']['externalId']]['quantity']; if ('Y' == $optionDiscRound) { $price = self::truncate($price, 2); diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index a883c7e5..eae98ebf 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -29,12 +29,17 @@ class RetailCrmOrder * * Creates order or returns order for mass upload * - * @param array $arFields - * @param $api - * @param $arParams - * @param $send + * @param array $arFields + * @param $api + * @param $arParams + * @param bool $send + * @param null $site + * @param string $methodApi + * * @return boolean - * @return array - array('order' = $order, 'customer' => $customer) + * @throws \Bitrix\Main\ArgumentException + * @throws \Bitrix\Main\ObjectPropertyException + * @throws \Bitrix\Main\SystemException */ public static function orderSend($arFields, $api, $arParams, $send = false, $site = null, $methodApi = 'ordersEdit') { @@ -200,23 +205,15 @@ class RetailCrmOrder } $discount = (double) $product['DISCOUNT_PRICE']; - - //discount $dpItem = $product['BASE_PRICE'] - $product['PRICE']; + if ( $dpItem > 0 && $discount <= 0) { $discount = $dpItem; } - if ($discount <= 0) { - $item['discountManualAmount'] = 0; - $initialPrice = (double) $product['PRICE']; - } else { - $item['discountManualAmount'] = $discount; - $initialPrice = (double) $product['PRICE'] + $discount; - } - $item['discountManualPercent'] = 0; - $item['initialPrice'] = $initialPrice; + $item['discountManualAmount'] = $discount; + $item['initialPrice'] = (double) $product['BASE_PRICE']; $order['items'][] = $item; @@ -304,9 +301,16 @@ class RetailCrmOrder /** * Mass order uploading, without repeating; always returns true, but writes error log - * @param $pSize - * @param $failed -- flag to export failed orders + * + * @param int $pSize + * @param bool $failed -- flag to export failed orders + * @param bool $orderList + * * @return boolean + * @throws \Bitrix\Main\ArgumentNullException + * @throws \Bitrix\Main\ObjectPropertyException + * @throws \Bitrix\Main\SystemException + * @throws \Bitrix\Main\ArgumentException */ public static function uploadOrders($pSize = 50, $failed = false, $orderList = false) { @@ -446,6 +450,14 @@ class RetailCrmOrder return true; } + /** + * Converts order object to array + * + * @param \Bitrix\Sale\Order $obOrder + * + * @return array + * @throws \Bitrix\Main\SystemException + */ public static function orderObjToArr($obOrder) { $culture = new \Bitrix\Main\Context\Culture(array("FORMAT_DATETIME" => "Y-m-d HH:i:s")); From 0e67c1d93d68c77f53eb8a7984efadffaf93d5d9 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 19 Feb 2020 14:57:03 +0300 Subject: [PATCH 4/4] don't write in DISCOUNT_PRICE --- intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php | 1 - 1 file changed, 1 deletion(-) diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index 1b86a3cc..4622d78f 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -769,7 +769,6 @@ class RetailCrmHistory $item->setField('CUSTOM_PRICE', 'Y'); $item->setField('DISCOUNT_NAME', ''); $item->setField('DISCOUNT_VALUE', ''); - $item->setField('DISCOUNT_PRICE', $product['discountTotal_sum']); // Полную цену позиции с учётом скидок делим на количество - получаем цену каждой единицы // товара с учётом скидок.