1
0
mirror of synced 2024-11-22 05:16:09 +03:00
* Теперь учитываются группы доставки
* Изменен алгоритм передачи оплат
* Исправлено задваивание количества товаров в отгрузке
* Небольшие исправления
This commit is contained in:
Евгений 2017-09-22 15:28:19 +03:00 committed by Alex Lushpai
parent ef4c4a7d33
commit 0557b573a3
10 changed files with 129 additions and 74 deletions

View File

@ -1,3 +1,9 @@
## 2017-09-22 v.2.2.5
* Теперь учитываются группы доставки
* Изменен алгоритм передачи оплат
* Исправлено задваивание количества товаров в отгрузке
* Небольшие исправления
## 2017-09-07 v.2.2.4
* Исправлена работа истории пользователей
* Убраны события для старого API

View File

@ -53,12 +53,15 @@ class RCrmActions
in_array($arDeliveryService['PARENT_ID'], $groups)) &&
$arDeliveryService['ID'] != $noOrderId &&
$arDeliveryService['CLASS_NAME'] != '\Bitrix\Sale\Delivery\Services\Group') {
if (in_array($arDeliveryService['PARENT_ID'], $groups)) {
$arDeliveryService['PARENT_ID'] = 0;
}
$bitrixDeliveryTypesList[] = $arDeliveryService;
}
}
return $bitrixDeliveryTypesList;
}
}
public static function PaymentList()
{
@ -78,7 +81,7 @@ class RCrmActions
{
$bitrixPaymentStatusesList = array();
$obStatuses = \Bitrix\Sale\Internals\StatusTable::getList(array(
'filter' => array('TYPE' => 'O'),
'filter' => array('TYPE' => 'O', '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID),
'select' => array('ID', "NAME" => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME')
));
while ($arStatus = $obStatuses->fetch()) {

View File

@ -135,7 +135,13 @@
},
"browserId": {
"type": "string"
}
},
"discountCardNumber": {
"type": "string"
},
"personalDiscount": {
"type": "string"
}
},
"orders": {
"number": {

View File

@ -371,7 +371,7 @@ class RetailCrmHistory
$order['customer']['externalId'] = $registeredUserID;
}
if (isset($optionsSitesList)) {
if ($optionsSitesList) {
$site = array_search($order['site'], $optionsSitesList);
} else {
$site = CSite::GetDefSite();
@ -426,9 +426,9 @@ class RetailCrmHistory
'filter' => array('ACCOUNT_NUMBER' => $order['number']),
'select' => array('ID'),
);
$searchOrder = reset(Bitrix\Sale\Order::loadByFilter($searchFilter));
$searchOrder = \Bitrix\Sale\OrderTable::GetList($searchFilter)->fetch();
if (!empty($searchOrder)) {
if ($searchOrder->getId() != $order['externalId']) {
if ($searchOrder['ID'] != $order['externalId']) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'setField("ACCOUNT_NUMBER")', 'Error order load id=' . $order['externalId']) . '. Number ' . $order['number'] . ' already exists';
continue;
@ -439,25 +439,26 @@ class RetailCrmHistory
}
$personType = $newOrder->getField('PERSON_TYPE_ID');
$nType = array();
$tList = RCrmActions::OrderTypesList(array(array('LID' => $site)));
foreach($tList as $type){
if (isset($optionsOrderTypes[$type['ID']])) {
$nType[$optionsOrderTypes[$type['ID']]] = $type['ID'];
if (isset($order['orderType']) && $order['orderType']) {
$nType = array();
$tList = RCrmActions::OrderTypesList(array(array('LID' => $site)));
foreach($tList as $type){
if (isset($optionsOrderTypes[$type['ID']])) {
$nType[$optionsOrderTypes[$type['ID']]] = $type['ID'];
}
}
}
$optionsOrderTypes = $nType;
if ($optionsOrderTypes[$order['orderType']]) {
if ($personType != $optionsOrderTypes[$order['orderType']] && $personType != 0) {
$propsRemove = true;
$newOptionsOrderTypes = $nType;
if ($newOptionsOrderTypes[$order['orderType']]) {
if ($personType != $newOptionsOrderTypes[$order['orderType']] && $personType != 0) {
$propsRemove = true;
}
$personType = $newOptionsOrderTypes[$order['orderType']];
$newOrder->setField('PERSON_TYPE_ID', $personType);
} elseif ($personType == 0) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'orderType not found', 'PERSON_TYPE_ID = 0');
}
$personType = $optionsOrderTypes[$order['orderType']];
$newOrder->setField('PERSON_TYPE_ID', $personType);
} elseif ($personType == 0) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'orderType not found', 'PERSON_TYPE_ID = 0');
}
}
//status
if ($optionsPayStatuses[$order['status']]) {
@ -623,6 +624,8 @@ class RetailCrmHistory
}
if ($product['delete']) {
$item->delete();
$basket->save();
continue;
}
@ -808,8 +811,10 @@ class RetailCrmHistory
$change['order']['items'] = $items;
}
if ($change['order']['contragent']['contragentType']) {
$change['order']['contragentType'] = self::newValue($change['order']['contragent']['contragentType']);
if (isset($change['order']['contragent']) && count($change['order']['contragent']) > 0) {
foreach ($change['order']['contragent'] as $name => $value) {
$change['order'][$name] = self::newValue($value);
}
unset($change['order']['contragent']);
}
@ -833,7 +838,7 @@ class RetailCrmHistory
if (empty($change['newValue']) && $change['field'] == 'order_product') {
$orders[$change['order']['id']]['items'][$change['item']['id']]['delete'] = 1;
}
if (!$orders[$change['order']['id']]['items'][$change['item']['id']]['create'] && $fields['item'][$change['field']]) {
if (/*!$orders[$change['order']['id']]['items'][$change['item']['id']]['create'] && */$fields['item'][$change['field']]) {
$orders[$change['order']['id']]['items'][$change['item']['id']][$fields['item'][$change['field']]] = $change['newValue'];
}
} else {
@ -1045,7 +1050,7 @@ class RetailCrmHistory
}
$obShipments = \Bitrix\Sale\Internals\ShipmentTable::getList(array(
'filter' => array('ORDER_ID' => $orderId),
'filter' => array('ORDER_ID' => $orderId, 'SYSTEM' => 'N'),
'select' => array('ID')
));

View File

@ -440,9 +440,9 @@ class RetailCrmHistory
'filter' => array('ACCOUNT_NUMBER' => $order['number']),
'select' => array('ID'),
);
$searchOrder = reset(Bitrix\Sale\Order::loadByFilter($searchFilter));
$searchOrder = \Bitrix\Sale\OrderTable::GetList($searchFilter)->fetch();
if (!empty($searchOrder)) {
if ($searchOrder->getId() != $order['externalId']) {
if ($searchOrder['ID'] != $order['externalId']) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'setField("ACCOUNT_NUMBER")', 'Error order load id=' . $order['externalId']) . '. Number ' . $order['number'] . ' already exists';
continue;
@ -453,24 +453,25 @@ class RetailCrmHistory
}
$personType = $newOrder->getField('PERSON_TYPE_ID');
$nType = array();
$tList = RCrmActions::OrderTypesList(array(array('LID' => $site)));
foreach($tList as $type){
if (isset($optionsOrderTypes[$type['ID']])) {
$nType[$optionsOrderTypes[$type['ID']]] = $type['ID'];
if (isset($order['orderType']) && $order['orderType']) {
$nType = array();
$tList = RCrmActions::OrderTypesList(array(array('LID' => $site)));
foreach($tList as $type){
if (isset($optionsOrderTypes[$type['ID']])) {
$nType[$optionsOrderTypes[$type['ID']]] = $type['ID'];
}
}
}
$optionsOrderTypes = $nType;
$newOptionsOrderTypes = $nType;
if ($optionsOrderTypes[$order['orderType']]) {
if ($personType != $optionsOrderTypes[$order['orderType']] && $personType != 0) {
$propsRemove = true;
if ($newOptionsOrderTypes[$order['orderType']]) {
if ($personType != $newOptionsOrderTypes[$order['orderType']] && $personType != 0) {
$propsRemove = true;
}
$personType = $newOptionsOrderTypes[$order['orderType']];
$newOrder->setField('PERSON_TYPE_ID', $personType);
} elseif ($personType == 0) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'orderType not found', 'PERSON_TYPE_ID = 0');
}
$personType = $optionsOrderTypes[$order['orderType']];
$newOrder->setField('PERSON_TYPE_ID', $personType);
} elseif ($personType == 0) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'orderType not found', 'PERSON_TYPE_ID = 0');
}
//status
@ -628,7 +629,9 @@ class RetailCrmHistory
'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider',
'DIMENSIONS' => $elem['DIMENSIONS'],
'WEIGHT' => $elem['WEIGHT'],
'NOTES' => GetMessage('PRICE_TYPE')
'NOTES' => GetMessage('PRICE_TYPE'),
'PRODUCT_XML_ID' => $elem["XML_ID"],
'CATALOG_XML_ID' => $elem["IBLOCK_XML_ID"]
));
} else {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'createItem', 'Error item add');
@ -638,6 +641,7 @@ class RetailCrmHistory
}
if ($product['delete']) {
$item->delete();
$basket->save();
continue;
}
@ -826,9 +830,11 @@ class RetailCrmHistory
}
$change['order']['payments'] = $payments;
}
if ($change['order']['contragent']['contragentType']) {
$change['order']['contragentType'] = self::newValue($change['order']['contragent']['contragentType']);
if (isset($change['order']['contragent']) && count($change['order']['contragent']) > 0) {
foreach ($change['order']['contragent'] as $name => $value) {
$change['order'][$name] = self::newValue($value);
}
unset($change['order']['contragent']);
}
@ -852,7 +858,7 @@ class RetailCrmHistory
if (empty($change['newValue']) && $change['field'] == 'order_product') {
$orders[$change['order']['id']]['items'][$change['item']['id']]['delete'] = 1;
}
if (!$orders[$change['order']['id']]['items'][$change['item']['id']]['create'] && $fields['item'][$change['field']]) {
if (/*!$orders[$change['order']['id']]['items'][$change['item']['id']]['create'] && */$fields['item'][$change['field']]) {
$orders[$change['order']['id']]['items'][$change['item']['id']][$fields['item'][$change['field']]] = $change['newValue'];
}
} elseif ($change['payment']) {
@ -1081,7 +1087,7 @@ class RetailCrmHistory
}
$obShipments = \Bitrix\Sale\Internals\ShipmentTable::getList(array(
'filter' => array('ORDER_ID' => $orderId),
'filter' => array('ORDER_ID' => $orderId, 'SYSTEM' => 'N'),
'select' => array('ID')
));
@ -1277,7 +1283,9 @@ class RetailCrmHistory
'HEIGHT' => $catalog['HEIGHT'],
'LENGTH' => $catalog['LENGTH'],
))),
'WEIGHT' => $catalog['WEIGHT']
'WEIGHT' => $catalog['WEIGHT'],
'XML_ID' => $elementInfo["XML_ID"],
'IBLOCK_XML_ID' => $elementInfo["IBLOCK_EXTERNAL_ID"]
);
return $info;

View File

@ -155,7 +155,7 @@ class RetailCrmOrder
}
$normalizer = new RestNormalizer();
$order = $normalizer->normalize($order, 'orders');
$order = $normalizer->normalize($order, 'ordersSend');
$log = new Logger();
$log->write($order, 'order');
@ -326,6 +326,12 @@ class RetailCrmOrder
foreach ($shipmentList as $shipmentData) {
if ($shipmentData->getDeliveryId()) {
$delivery = \Bitrix\Sale\Delivery\Services\Manager::getById($shipmentData->getDeliveryId());
$siteDeliverys = RCrmActions::DeliveryList();
foreach ($siteDeliverys as $siteDelivery) {
if ($siteDelivery['ID'] == $delivery['ID'] && $siteDelivery['PARENT_ID'] == 0) {
unset($delivery['PARENT_ID']);
}
}
if ($delivery['PARENT_ID']) {
$servise = explode(':', $delivery['CODE']);
$shipment = array('id' => $delivery['PARENT_ID'], 'service' => $servise[1]);

View File

@ -141,20 +141,26 @@ class RetailCrmOrder
//payments
$payments = array();
foreach ($arFields['PAYMENTS'] as $payment) {
$pm = array(
'type' => isset($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']]) ? $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']] : '',
'amount' => $payment['SUM']
);
if (!empty($payment['ID'])) {
$pm['externalId'] = $payment['ID'];
if (!empty($payment['PAY_SYSTEM_ID']) && isset($arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']])) {
$pm = array(
'type' => $arParams['optionsPayTypes'][$payment['PAY_SYSTEM_ID']],
'amount' => $payment['SUM']
);
if (!empty($payment['ID'])) {
$pm['externalId'] = $payment['ID'];
}
if (!empty($payment['DATE_PAID'])) {
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
}
if (!empty($arParams['optionsPayment'][$payment['PAID']])) {
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
}
$payments[] = $pm;
} else {
RCrmActions::eventLog('RetailCrmOrder::orderSend', 'payments', 'OrderID = ' . $arFields['ID'] . '. Payment not found.');
continue;
}
if (!empty($payment['DATE_PAID'])) {
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
}
if (!empty($arParams['optionsPayment'][$payment['PAID']])) {
$pm['status'] = $arParams['optionsPayment'][$payment['PAID']];
}
$payments[] = $pm;
}
if (count($payments) > 0) {
$order['payments'] = $payments;
@ -173,7 +179,7 @@ class RetailCrmOrder
}
$normalizer = new RestNormalizer();
$order = $normalizer->normalize($order, 'orders');
$order = $normalizer->normalize($order, 'ordersSend');
$log = new Logger();
$log->write($order, 'order');
@ -198,7 +204,14 @@ class RetailCrmOrder
foreach ($order['payments'] as $payment) {
if (isset($crmPayments['externalIds'][$payment['externalId']])) {
//update payment
if(RCrmActions::apiMethod($api, 'ordersPaymentEdit', __METHOD__, $payment, $site)){
if ($payment['type'] == $crmPayments['externalIds'][$payment['externalId']]['type']) {
if (RCrmActions::apiMethod($api, 'ordersPaymentEdit', __METHOD__, $payment, $site)) {
unset($crmPayments['externalIds'][$payment['externalId']]);
}
} else {
RCrmActions::apiMethod($api, 'ordersPaymentDelete', __METHOD__, $crmPayments['externalIds'][$payment['externalId']]['id']);
$payment['order']['externalId'] = $order['externalId'];
RCrmActions::apiMethod($api, 'ordersPaymentCreate', __METHOD__, $payment, $site);
unset($crmPayments['externalIds'][$payment['externalId']]);
}
} else {
@ -395,6 +408,12 @@ class RetailCrmOrder
foreach ($shipmentList as $shipmentData) {
if ($shipmentData->getDeliveryId()) {
$delivery = \Bitrix\Sale\Delivery\Services\Manager::getById($shipmentData->getDeliveryId());
$siteDeliverys = RCrmActions::DeliveryList();
foreach ($siteDeliverys as $siteDelivery) {
if ($siteDelivery['ID'] == $delivery['ID'] && $siteDelivery['PARENT_ID'] == 0) {
unset($delivery['PARENT_ID']);
}
}
if ($delivery['PARENT_ID']) {
$servise = explode(':', $delivery['CODE']);
$shipment = array('id' => $delivery['PARENT_ID'], 'service' => $servise[1]);

View File

@ -65,7 +65,7 @@ class RetailCrmUser
$customer = $normalizer->normalize($customer, 'customers');
$log = new Logger();
$log->write($customer, 'customer');
$log->write($customer, 'customerSend');
if ($send) {
if (!RCrmActions::apiMethod($api, 'customersCreate', __METHOD__, $customer, $site)) {
@ -136,7 +136,7 @@ class RetailCrmUser
$customer = $normalizer->normalize($customer, 'customers');
$log = new Logger();
$log->write($customer, 'customer');
$log->write($customer, 'customerSend');
if (function_exists('retailCrmBeforeCustomerSend')) {
$newResCustomer = retailCrmBeforeCustomerSend($customer);

View File

@ -1,2 +1,4 @@
- Убраны старые обработчики событий
- Исправлена работа истории пользователей
- Теперь учитываются группы доставки
- Изменен алгоритм передачи оплат
- Исправлено задваивание количества товаров в отгрузке
- Небольшие исправления

View File

@ -1,5 +1,5 @@
<?
$arModuleVersion = array(
"VERSION" => "2.2.4",
"VERSION_DATE" => "2017-09-07 12:00:00"
"VERSION" => "2.2.5",
"VERSION_DATE" => "2017-09-22 18:00:00"
);