1
0
mirror of synced 2024-11-22 13:26:10 +03:00

Merge pull request #83 from Evgeniy-Goroh/master

Поддержка одинаковых позицый товаров в CRM
This commit is contained in:
Alex Lushpai 2019-10-17 13:02:39 +03:00 committed by GitHub
commit a0db53017c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 78 additions and 19 deletions

View File

@ -1,3 +1,6 @@
## 2019-09-17 v.2.5.2
* Поддержка функции добавления одинакового товара в заказ как разные товарные позиции из CRM
## 2019-08-28 v.2.5.1 ## 2019-08-28 v.2.5.1
* Исправление генерации единиц измерения * Исправление генерации единиц измерения

View File

@ -646,11 +646,32 @@ class RetailCrmHistory
if (isset($order['items'])) { if (isset($order['items'])) {
$itemUpdate = true; $itemUpdate = true;
$response = RCrmActions::apiMethod($api, 'orderGet', __METHOD__, $order['id']);
if (isset($response['order'])) {
$orderTemp = $response['order'];
$ditems = [];
foreach ($orderTemp['items'] as $item) {
$ditems[$item['offer']['xmlId']]['quantity'] += $item['quantity'];
$ditems[$item['offer']['xmlId']]['discountTotal'] += $item['quantity'] * $item['discountTotal'];
$ditems[$item['offer']['xmlId']]['initialPrice'] = (float)$item['initialPrice'];
$ditems[$item['offer']['xmlId']]['price_sum'] = $ditems[$item['offer']['xmlId']]['initialPrice'] * $ditems[$item['offer']['xmlId']]['quantity'] - $ditems[$item['offer']['xmlId']]['discountTotal'];
$ditems[$item['offer']['xmlId']]['price_item'] = $ditems[$item['offer']['xmlId']]['price_sum'] / $ditems[$item['offer']['xmlId']]['quantity'];
}
unset($orderTemp);
}
$log->write($ditems, 'duplicateItemsOrderHistory');
foreach ($order['items'] as $product) { foreach ($order['items'] as $product) {
if($ditems[$product['offer']['xmlId']]['quantity']){
$product['quantity'] = $ditems[$product['offer']['xmlId']]['quantity'];
}
$item = self::getExistsItem($basket, 'catalog', $product['offer']['externalId']); $item = self::getExistsItem($basket, 'catalog', $product['offer']['externalId']);
if (!$item) { if (!$item) {
if ($product['delete']) { if ($product['delete']) {
continue; continue;
} }
@ -679,10 +700,12 @@ class RetailCrmHistory
} }
if ($product['delete']) { if ($product['delete']) {
if ($ditems[$product['offer']['xmlId']]['quantity'] <= 0) {
$item->delete(); $item->delete();
continue; continue;
} }
}
if ($product['quantity']) { if ($product['quantity']) {
$item->setFieldNoDemand('QUANTITY', $product['quantity']); $item->setFieldNoDemand('QUANTITY', $product['quantity']);
@ -709,6 +732,12 @@ class RetailCrmHistory
$item->setField('DISCOUNT_VALUE', ''); $item->setField('DISCOUNT_VALUE', '');
$item->setField('DISCOUNT_PRICE', $resultDiscount); $item->setField('DISCOUNT_PRICE', $resultDiscount);
$item->setField('PRICE', $itemCost - $resultDiscount); $item->setField('PRICE', $itemCost - $resultDiscount);
//set price dublicate item
if ($ditems[$product['offer']['xmlId']]['price_item']) {
$item->setField('PRICE', $ditems[$product['offer']['xmlId']]['price_item']);
$item->setField('DISCOUNT_PRICE', '');
}
} }
} }
} }
@ -772,12 +801,16 @@ class RetailCrmHistory
if (!empty($newHistoryPayments)) { if (!empty($newHistoryPayments)) {
foreach ($newOrder->getPaymentCollection() as $orderPayment) { foreach ($newOrder->getPaymentCollection() as $orderPayment) {
if (array_key_exists($orderPayment->getField('XML_ID'), $newHistoryPayments)) { if (array_key_exists($orderPayment->getField('XML_ID'), $newHistoryPayments)) {
$paymentId = $orderPayment->getId(); $paymentId = $orderPayment->getId();
$paymentExternalId = RCrmActions::generatePaymentExternalId($paymentId); $paymentExternalId = RCrmActions::generatePaymentExternalId($paymentId);
if (is_null($paymentId)) { if (is_null($paymentId)) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'paymentsUpdate', 'Save payment error, order=' . $order['number']); RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'paymentsUpdate', 'Save payment error, order=' . $order['number']);
continue; continue;
} }
$paymentExternalId = $orderPayment->getId();
if ($paymentExternalId) { if ($paymentExternalId) {
$newHistoryPayments[$orderPayment->getField('XML_ID')]['externalId'] = $paymentExternalId; $newHistoryPayments[$orderPayment->getField('XML_ID')]['externalId'] = $paymentExternalId;
RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $newHistoryPayments[$orderPayment->getField('XML_ID')]); RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $newHistoryPayments[$orderPayment->getField('XML_ID')]);
@ -815,6 +848,26 @@ class RetailCrmHistory
} }
} }
/**
* @param $array
* @param $value
*
* @return array
*/
public static function search_array_by_value($array, $value)
{
$results = array();
if (is_array($array)) {
$found = array_search($value,$array);
if ($found) {
$results[] = $found;
}
foreach ($array as $subarray)
$results = array_merge($results, static::search_array_by_value($subarray, $value));
}
return $results;
}
public static function assemblyCustomer($customerHistory) public static function assemblyCustomer($customerHistory)
{ {
$server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot(); $server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot();
@ -1009,6 +1062,7 @@ class RetailCrmHistory
if (isset($orderCrm['delivery']['service']['code'])) { if (isset($orderCrm['delivery']['service']['code'])) {
$deliveryCode = \Bitrix\Sale\Delivery\Services\Manager::getCodeById($deliveryId); $deliveryCode = \Bitrix\Sale\Delivery\Services\Manager::getCodeById($deliveryId);
$serviceCode = $orderCrm['delivery']['service']['code']; $serviceCode = $orderCrm['delivery']['service']['code'];
$service = \Bitrix\Sale\Delivery\Services\Manager::getService($deliveryId); $service = \Bitrix\Sale\Delivery\Services\Manager::getService($deliveryId);
if (is_object($service)) { if (is_object($service)) {
$services = $service->getProfilesList(); $services = $service->getProfilesList();
@ -1017,6 +1071,7 @@ class RetailCrmHistory
$serviceCode = str_replace(array('-'), "_", $serviceCode); $serviceCode = str_replace(array('-'), "_", $serviceCode);
} }
} }
if ($deliveryCode) { if ($deliveryCode) {
try { try {
$deliveryService = \Bitrix\Sale\Delivery\Services\Manager::getObjectByCode($deliveryCode . ':' . $serviceCode); $deliveryService = \Bitrix\Sale\Delivery\Services\Manager::getObjectByCode($deliveryCode . ':' . $serviceCode);

View File

@ -140,6 +140,7 @@ class RetailCrmOrder
//basket //basket
foreach ($arFields['BASKET'] as $product) { foreach ($arFields['BASKET'] as $product) {
$item = array( $item = array(
'externalId' => $product['PRODUCT_ID'],
'quantity' => $product['QUANTITY'], 'quantity' => $product['QUANTITY'],
'offer' => array('externalId' => $product['PRODUCT_ID'], 'offer' => array('externalId' => $product['PRODUCT_ID'],
'xmlId' => $product['PRODUCT_XML_ID'] 'xmlId' => $product['PRODUCT_XML_ID']
@ -205,7 +206,7 @@ class RetailCrmOrder
'amount' => $payment['SUM'] 'amount' => $payment['SUM']
); );
if (!empty($payment['ID'])) { if (!empty($payment['ID'])) {
$pm['externalId'] = $payment['ID']; $pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
} }
if (!empty($payment['DATE_PAID'])) { if (!empty($payment['DATE_PAID'])) {
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']); $pm['paidAt'] = new \DateTime($payment['DATE_PAID']);

View File

@ -1 +1 @@
- Исправление генерации единиц измерения - Поддержка функции добавления одинакового товара в заказ как разные товарные позиции из CRM

View File

@ -1,5 +1,5 @@
<? <?
$arModuleVersion = array( $arModuleVersion = array(
"VERSION" => "2.5.1", "VERSION" => "2.5.2",
"VERSION_DATE" => "2019-08-28 15:20:00" "VERSION_DATE" => "2019-09-17 15:20:00"
); );