1
0
mirror of synced 2024-12-01 09:46:06 +03:00

fix custom prices (#204)

This commit is contained in:
Сергей Чазов 2021-05-31 11:14:02 +03:00 committed by GitHub
parent 4f2bc1a1b1
commit c37b05c6d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 11 deletions

View File

@ -146,10 +146,11 @@ class CustomerAddress extends BaseModel
} }
/** /**
* @param string $floor * @param string|null $floor
*
* @return $this * @return $this
*/ */
public function setFloor(string $floor) public function setFloor(?string $floor): CustomerAddress
{ {
$this->floor = $floor; $this->floor = $floor;

View File

@ -1,4 +1,8 @@
<?php <?php
use Bitrix\Sale\Internals\Fields;
use Intaro\RetailCrm\Service\UploadOrderService;
IncludeModuleLangFile(__FILE__); IncludeModuleLangFile(__FILE__);
class RetailCrmOrder class RetailCrmOrder
{ {
@ -220,16 +224,15 @@ class RetailCrmOrder
$item['purchasePrice'] = $purchasePrice; $item['purchasePrice'] = $purchasePrice;
} }
$discount = (double) $product['DISCOUNT_PRICE'];
$dpItem = $product['BASE_PRICE'] - $product['PRICE'];
if ( $dpItem > 0 && $discount <= 0) {
$discount = $dpItem;
}
$item['discountManualPercent'] = 0; $item['discountManualPercent'] = 0;
$item['discountManualAmount'] = $discount;
if ($product['BASE_PRICE'] >= $product['PRICE']) {
$item['discountManualAmount'] = self::getDiscountManualAmount($product);
$item['initialPrice'] = (double) $product['BASE_PRICE']; $item['initialPrice'] = (double) $product['BASE_PRICE'];
} else {
$item['discountManualAmount'] = 0;
$item['initialPrice'] = $product['PRICE'];
}
$order['items'][] = $item; $order['items'][] = $item;
@ -756,4 +759,26 @@ class RetailCrmOrder
return $arOrder; 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;
}
} }