From c37b05c6d24969a8b9af654a3700bb2a6d7006de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=A7=D0=B0=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2?= <45812598+Chazovs@users.noreply.github.com> Date: Mon, 31 May 2021 11:14:02 +0300 Subject: [PATCH] fix custom prices (#204) --- .../classes/general/Model/CustomerAddress.php | 5 ++- .../general/order/RetailCrmOrder_v5.php | 43 +++++++++++++++---- 2 files changed, 37 insertions(+), 11 deletions(-) diff --git a/intaro.retailcrm/classes/general/Model/CustomerAddress.php b/intaro.retailcrm/classes/general/Model/CustomerAddress.php index 47501eaf..d94ecad1 100644 --- a/intaro.retailcrm/classes/general/Model/CustomerAddress.php +++ b/intaro.retailcrm/classes/general/Model/CustomerAddress.php @@ -146,10 +146,11 @@ class CustomerAddress extends BaseModel } /** - * @param string $floor + * @param string|null $floor + * * @return $this */ - public function setFloor(string $floor) + public function setFloor(?string $floor): CustomerAddress { $this->floor = $floor; diff --git a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php index 068cfc4a..b2d12387 100644 --- a/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php +++ b/intaro.retailcrm/classes/general/order/RetailCrmOrder_v5.php @@ -1,4 +1,8 @@ 0 && $discount <= 0) { - $discount = $dpItem; - } - $item['discountManualPercent'] = 0; - $item['discountManualAmount'] = $discount; - $item['initialPrice'] = (double) $product['BASE_PRICE']; + + if ($product['BASE_PRICE'] >= $product['PRICE']) { + $item['discountManualAmount'] = self::getDiscountManualAmount($product); + $item['initialPrice'] = (double) $product['BASE_PRICE']; + } else { + $item['discountManualAmount'] = 0; + $item['initialPrice'] = $product['PRICE']; + } $order['items'][] = $item; @@ -756,4 +759,26 @@ class RetailCrmOrder return $arOrder; } + + /** + * @param \Bitrix\Sale\Internals\Fields $product + * + * @return float + */ + public static function getDiscountManualAmount(Fields $product): float + { + if ($product->get('CUSTOM_PRICE') === 'Y') { + $sumDifference = $product->get('BASE_PRICE') - $product->get('PRICE'); + return $sumDifference > 0 ? $sumDifference : 0.0; + } + + $discount = (double) $product->get('DISCOUNT_PRICE'); + $dpItem = $product->get('BASE_PRICE') - $product->get('PRICE'); + + if ($dpItem > 0 && $discount <= 0) { + return $dpItem; + } + + return $discount; + } }