1
0
mirror of synced 2024-11-25 14:56:09 +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
* Добавлен выбор валюты в настройках, для выгрузки заказов из CRM
* Исправлена выборка свойств заказа

View File

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

View File

@ -235,8 +235,8 @@ class RetailCrmEvent
}
if ($optionsSitesList) {
if (array_key_exists($arOrder['LID'], $optionsSitesList) && $optionsSitesList[$arOrder['LID']] !== null) {
$site = $optionsSitesList[$arOrder['LID']];
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
$site = $optionsSitesList[$arPayment['LID']];
} else {
return;
}
@ -257,7 +257,7 @@ class RetailCrmEvent
if ($payments) {
foreach ($payments as $payment) {
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'];
RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $payment, $site);
}
@ -321,10 +321,10 @@ class RetailCrmEvent
*/
function paymentDelete($event)
{
{
$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;
}
@ -343,16 +343,16 @@ class RetailCrmEvent
return;
}
if(!empty($optionsSitesList) && array_key_exists($arPayment['LID'], $optionsSitesList)) {
$site = $optionsSitesList[$arPayment['LID']];
} else {
if ($optionsSitesList) {
if (array_key_exists($arPayment['LID'], $optionsSitesList) && $optionsSitesList[$arPayment['LID']] !== null) {
$site = $optionsSitesList[$arPayment['LID']];
} else {
return;
}
} elseif (!$optionsSitesList) {
$site = null;
}
if ($site == null) {
return;
}
$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 = new RetailCrm\ApiClient($api_host, $api_key);

View File

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

View File

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

View File

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

View File

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