1
0
mirror of synced 2024-11-21 21:06:09 +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
*/
public function setFloor(string $floor)
public function setFloor(?string $floor): CustomerAddress
{
$this->floor = $floor;

View File

@ -1,4 +1,8 @@
<?php
use Bitrix\Sale\Internals\Fields;
use Intaro\RetailCrm\Service\UploadOrderService;
IncludeModuleLangFile(__FILE__);
class RetailCrmOrder
{
@ -220,16 +224,15 @@ class RetailCrmOrder
$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['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;
}
}