1
0
mirror of synced 2024-11-22 21:36:10 +03:00
This commit is contained in:
Akolzin Dmitry 2018-01-12 11:14:33 +03:00 committed by GitHub
parent 6d398f7160
commit 02e6beb385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 120 additions and 48 deletions

View File

@ -1,3 +1,10 @@
## 2017-12-27 v.2.3.2
* Исправлен баг с рассчетом суммы заказа
* Добавлен перехват исключения при редактировании отгруженной доставки
## 2017-12-27 v.2.3.1
* Исправлены мелкие баги и недочеты
## 2017-12-04 v.2.3.0 ## 2017-12-04 v.2.3.0
* Добавлен выбор валюты в настройках, для выгрузки заказов из CRM * Добавлен выбор валюты в настройках, для выгрузки заказов из CRM
* Исправлена выборка свойств заказа * Исправлена выборка свойств заказа

View File

@ -112,7 +112,6 @@ class Client
$curlHandler = curl_init(); $curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, $url); curl_setopt($curlHandler, CURLOPT_URL, $url);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlHandler, CURLOPT_FAILONERROR, false); curl_setopt($curlHandler, CURLOPT_FAILONERROR, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);

View File

@ -235,8 +235,8 @@ class RetailCrmEvent
} }
if ($optionsSitesList) { if ($optionsSitesList) {
if (array_key_exists($arOrder['LID'], $optionsSitesList) && $optionsSitesList[$arOrder['LID']] !== null) { if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
$site = $optionsSitesList[$arOrder['LID']]; $site = $optionsSitesList[$arPayment['LID']];
} else { } else {
return; return;
} }
@ -257,7 +257,7 @@ class RetailCrmEvent
if ($payments) { if ($payments) {
foreach ($payments as $payment) { foreach ($payments as $payment) {
if (!isset($payment['externalId'])) { if (!isset($payment['externalId'])) {
if ($payment['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']] && $payment['amount'] == $arPayment['SUM']) { if ($payment['type'] == $optionsPaymentTypes[$arPayment['PAY_SYSTEM_ID']]) {
$payment['externalId'] = $arPayment['ID']; $payment['externalId'] = $arPayment['ID'];
RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $payment, $site); RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $payment, $site);
} }
@ -324,7 +324,7 @@ class RetailCrmEvent
{ {
$apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0); $apiVersion = COption::GetOptionString(self::$MODULE_ID, 'api_version', 0);
if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) || $apiVersion != 'v5') { if ((isset($GLOBALS['RETAIL_CRM_HISTORY']) && $GLOBALS['RETAIL_CRM_HISTORY']) || $apiVersion != 'v5' || !$event->getId()) {
return; return;
} }
@ -343,15 +343,15 @@ class RetailCrmEvent
return; return;
} }
if(!empty($optionsSitesList) && array_key_exists($arPayment['LID'], $optionsSitesList)) { if ($optionsSitesList) {
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
$site = $optionsSitesList[$arPayment['LID']]; $site = $optionsSitesList[$arPayment['LID']];
} else { } else {
$site = null;
}
if ($site == null) {
return; return;
} }
} elseif (!$optionsSitesList) {
$site = null;
}
$api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0); $api_host = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0); $api_key = COption::GetOptionString(self::$MODULE_ID, self::$CRM_API_KEY_OPTION, 0);

View File

@ -397,8 +397,14 @@ class RetailCrmHistory
continue; continue;
} }
$newOrder = Bitrix\Sale\Order::create($site, $order['customer']['externalId']); $newOrder = Bitrix\Sale\Order::create($site, $order['customer']['externalId'], $currency);
$newOrder->setField('CURRENCY', $currency);
if (!is_object($newOrder) || !$newOrder instanceof \Bitrix\Sale\Order) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'Bitrix\Sale\Order::create', 'Error order create');
continue;
}
$externalId = $newOrder->getId(); $externalId = $newOrder->getId();
$order['externalId'] = $externalId; $order['externalId'] = $externalId;
} }
@ -621,13 +627,17 @@ class RetailCrmHistory
if (isset($order['items'])) { if (isset($order['items'])) {
$itemUpdate = true; $itemUpdate = true;
foreach ($order['items'] as $product) { foreach ($order['items'] as $product) {
$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;
} }
$item = $basket->createItem('catalog', $product['offer']['externalId']); $item = $basket->createItem('catalog', $product['offer']['externalId']);
if ($item instanceof \Bitrix\Sale\BasketItem) { if ($item instanceof \Bitrix\Sale\BasketItem) {
$elem = self::getInfoElement($product['offer']['externalId']); $elem = self::getInfoElement($product['offer']['externalId']);
$item->setFields(array( $item->setFields(array(
@ -649,6 +659,7 @@ class RetailCrmHistory
continue; continue;
} }
} }
if ($product['delete']) { if ($product['delete']) {
$item->delete(); $item->delete();
@ -685,16 +696,17 @@ class RetailCrmHistory
$orderSumm += $deliverySumm; $orderSumm += $deliverySumm;
$newOrder->setField('PRICE', $orderSumm);
$order['summ'] = $orderSumm; $order['summ'] = $orderSumm;
//payment //payment
$newHistoryPayments = array();
if (array_key_exists('payments', $order)) { if (array_key_exists('payments', $order)) {
if (!isset($orderCrm)) { if (!isset($orderCrm)) {
$orderCrm = RCrmActions::apiMethod($api, 'orderGet', __METHOD__, $order['id']); $orderCrm = RCrmActions::apiMethod($api, 'orderGet', __METHOD__, $order['id']);
} }
if ($orderCrm) { if ($orderCrm) {
$newOrder = self::paymentsUpdate($newOrder, $orderCrm['order'], $api); self::paymentsUpdate($newOrder, $orderCrm['order'], $api, $newHistoryPayments);
} }
} }
@ -706,22 +718,40 @@ class RetailCrmHistory
$orderCrm = RCrmActions::apiMethod($api, 'orderGet', __METHOD__, $order['id']); $orderCrm = RCrmActions::apiMethod($api, 'orderGet', __METHOD__, $order['id']);
} }
if ($orderCrm) { if ($orderCrm) {
$newOrder = self::deliveryEdit($newOrder, $optionsDelivTypes, $orderCrm['order']); self::deliveryUpdate($newOrder, $optionsDelivTypes, $orderCrm['order']);
} }
} }
if ($itemUpdate === true) {
self::shipmentItemReset($newOrder);
}
if (isset($orderCrm)) { if (isset($orderCrm)) {
unset($orderCrm); unset($orderCrm);
} }
$newOrder->setField('PRICE', $orderSumm);
$newOrder->save(); $newOrder->save();
if ($newHistoryPayments) {
foreach ($newOrder->getPaymentCollection() as $orderPayment) {
if (array_key_exists($orderPayment->getField('XML_ID'), $newHistoryPayments)) {
$paymentExternalId = $orderPayment->getId();
if ($paymentExternalId) {
$newHistoryPayments[$orderPayment->getField('XML_ID')]['externalId'] = $paymentExternalId;
RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $newHistoryPayments[$orderPayment->getField('XML_ID')]);
}
\Bitrix\Sale\Internals\PaymentTable::update($paymentExternalId, array('XML_ID' => ''));
}
}
}
if (!$order['externalId']) { if (!$order['externalId']) {
if(RCrmActions::apiMethod($api, 'ordersFixExternalIds', __METHOD__, array(array('id' => $order['id'], 'externalId' => $newOrder->getId()))) == false){ if(RCrmActions::apiMethod($api, 'ordersFixExternalIds', __METHOD__, array(array('id' => $order['id'], 'externalId' => $newOrder->getId()))) == false){
continue; continue;
} }
} else {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'Bitrix\Sale\Order::create', 'Error order create');
} }
if (function_exists('retailCrmAfterOrderSave')) { if (function_exists('retailCrmAfterOrderSave')) {
@ -915,9 +945,9 @@ class RetailCrmHistory
* @param options delivery types * @param options delivery types
* @param order from crm * @param order from crm
* *
* @return order object * @return void
*/ */
public static function deliveryEdit(Bitrix\Sale\Order $order, $optionsDelivTypes, $orderCrm) public static function deliveryUpdate(Bitrix\Sale\Order $order, $optionsDelivTypes, $orderCrm)
{ {
if (!$order instanceof Bitrix\Sale\Order) { if (!$order instanceof Bitrix\Sale\Order) {
return false; return false;
@ -965,7 +995,9 @@ class RetailCrmHistory
'PRICE_DELIVERY' => $orderCrm['delivery']['cost'], 'PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'], 'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
'CURRENCY' => $order->getCurrency(), 'CURRENCY' => $order->getCurrency(),
'DELIVERY_NAME' => $delivery->getName() 'DELIVERY_NAME' => $delivery->getName(),
'CUSTOM_PRICE_DELIVERY' => 'Y',
'DISCOUNT_PRICE' => 0
)); ));
} else { } else {
foreach ($shipmentColl as $shipment) { foreach ($shipmentColl as $shipment) {
@ -975,22 +1007,54 @@ class RetailCrmHistory
'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'], 'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
'CURRENCY' => $order->getCurrency(), 'CURRENCY' => $order->getCurrency(),
'DELIVERY_ID' => $deliveryId, 'DELIVERY_ID' => $deliveryId,
'DELIVERY_NAME' => $delivery->getName() 'DELIVERY_NAME' => $delivery->getName(),
'CUSTOM_PRICE_DELIVERY' => 'Y',
'DISCOUNT_PRICE' => 0
)); ));
} }
} }
} }
} }
}
if (isset($shipment) && $shipment) { /**
* Update shipment item colletion
*
* @param object $order
*
* @return void | boolean
*/
public static function shipmentItemReset($order)
{
$shipmentCollection = $order->getShipmentCollection();
$basket = $order->getBasket();
foreach ($shipmentCollection as $shipment) {
if (!$shipment->isSystem()) {
$shipmentItemColl = $shipment->getShipmentItemCollection(); $shipmentItemColl = $shipment->getShipmentItemCollection();
try {
$shipmentItemColl->resetCollection($basket); $shipmentItemColl->resetCollection($basket);
} catch (\Bitrix\Main\NotSupportedException $NotSupportedException) {
RCrmActions::eventLog('RetailCrmHistory::shipmentItemReset', '\Bitrix\Sale\ShipmentItemCollection::resetCollection()', $NotSupportedException->getMessage());
return false;
}
}
}
} }
return $order; /**
} * Update payment in order
*
public static function paymentsUpdate($order, $paymentsCrm, $api) * @param object $order
* @param array $paymentsCrm
* @param object $api
* @param array $newHistoryPayments
*
* @return void
*/
public static function paymentsUpdate($order, $paymentsCrm, $api, &$newHistoryPayments = array())
{ {
$optionsPayTypes = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0))); $optionsPayTypes = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT_TYPES, 0)));
$optionsPayment = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0))); $optionsPayment = array_flip(unserialize(COption::GetOptionString(self::$MODULE_ID, self::$CRM_PAYMENT, 0)));
@ -1025,6 +1089,7 @@ class RetailCrmHistory
unset($paymentsList[$paymentCrm['externalId']]); unset($paymentsList[$paymentCrm['externalId']]);
} }
} else { } else {
$newHistoryPayments[$paymentCrm['id']] = $paymentCrm;
$newPayment = $paymentColl->createItem(); $newPayment = $paymentColl->createItem();
$newPayment->setField('SUM', $paymentCrm['amount']); $newPayment->setField('SUM', $paymentCrm['amount']);
$newPayment->setField('PAY_SYSTEM_ID', $optionsPayTypes[$paymentCrm['type']]); $newPayment->setField('PAY_SYSTEM_ID', $optionsPayTypes[$paymentCrm['type']]);
@ -1035,6 +1100,7 @@ class RetailCrmHistory
$newPayment->setField('PRICE_COD', '0.00'); $newPayment->setField('PRICE_COD', '0.00');
$newPayment->setField('EXTERNAL_PAYMENT', 'N'); $newPayment->setField('EXTERNAL_PAYMENT', 'N');
$newPayment->setField('UPDATED_1C', 'N'); $newPayment->setField('UPDATED_1C', 'N');
$newPayment->setField('XML_ID', $paymentCrm['id']);
$newPaymentId = $newPayment->getId(); $newPaymentId = $newPayment->getId();
@ -1059,8 +1125,6 @@ class RetailCrmHistory
} else { } else {
$order->setFieldNoDemand('PAYED', 'N'); $order->setFieldNoDemand('PAYED', 'N');
} }
return $order;
} }
public static function newValue($value) public static function newValue($value)

View File

@ -64,6 +64,11 @@ class RetailCrmOrder
} }
$order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arFields['PERSON_TYPE_ID']]; $order['contragent']['contragentType'] = $arParams['optionsContragentType'][$arFields['PERSON_TYPE_ID']];
if ($methodApi == 'ordersEdit') {
$order['discountManualAmount'] = 0;
$order['discountManualPercent'] = 0;
}
//fields //fields
foreach ($arFields['PROPS']['properties'] as $prop) { foreach ($arFields['PROPS']['properties'] as $prop) {
if ($search = array_search($prop['CODE'], $arParams['optionsLegalDetails'][$arFields['PERSON_TYPE_ID']])) { if ($search = array_search($prop['CODE'], $arParams['optionsLegalDetails'][$arFields['PERSON_TYPE_ID']])) {
@ -301,7 +306,7 @@ class RetailCrmOrder
continue; continue;
} }
} elseif (!$optionsSitesList) { } elseif (!$optionsSitesList) {
$site == null; $site = null;
} }
if (RCrmActions::apiMethod($api, 'customersUpload', __METHOD__, $customerLoad, $site) === false) { if (RCrmActions::apiMethod($api, 'customersUpload', __METHOD__, $customerLoad, $site) === false) {
return false; return false;
@ -318,7 +323,7 @@ class RetailCrmOrder
continue; continue;
} }
} elseif (!$optionsSitesList) { } elseif (!$optionsSitesList) {
$site == null; $site = null;
} }
if (RCrmActions::apiMethod($api, 'ordersUpload', __METHOD__, $orderLoad, $site) === false) { if (RCrmActions::apiMethod($api, 'ordersUpload', __METHOD__, $orderLoad, $site) === false) {
return false; return false;

View File

@ -1,5 +1,2 @@
- Добавлен выбор валюты в настройках, для выгрузки заказов из CRM - Исправлен баг с рассчетом суммы заказа
- Исправлена выборка свойств заказа - Добавлен перехват исключения при редактировании отгруженной доставки
- Устранен баг в настройках соответствия полей свойств заказа
- Улучшена механика выгрузки заказов из CRM

View File

@ -1,5 +1,5 @@
<? <?
$arModuleVersion = array( $arModuleVersion = array(
"VERSION" => "2.3.0", "VERSION" => "2.3.2",
"VERSION_DATE" => "2017-12-04 12:00:00" "VERSION_DATE" => "2017-01-12 10:30:00"
); );