1
0
mirror of synced 2025-02-21 09:23:14 +03:00
This commit is contained in:
Akolzin Dmitry 2018-02-27 15:29:43 +03:00 committed by GitHub
parent a27d2f361e
commit 1e1426f6d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 180 additions and 55 deletions

View File

@ -1,3 +1,14 @@
## 2018-02-27 v.2.3.4
* Добавлена передача веса и габаритов в заказе
* Добавлена проверка существования fuser у корзины товаров перед сохранением
* Добавлено снятие резерва с товаров при отмене заказа в CRM
* Исправлена выборка данных для UA, когда id заказа не совпадает с номером
* Исправлены мелкие баги
## 2018-01-23 v.2.3.3
* Исправлен баг с передачей номера заказа
* Исправлены мелкие ошибки и недочеты
## 2017-12-27 v.2.3.2 ## 2017-12-27 v.2.3.2
* Исправлен баг с рассчетом суммы заказа * Исправлен баг с рассчетом суммы заказа
* Добавлен перехват исключения при редактировании отгруженной доставки * Добавлен перехват исключения при редактировании отгруженной доставки

View File

@ -262,6 +262,26 @@ class RCrmActions
return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET); return $APPLICATION->ConvertCharset($str, 'utf-8', SITE_CHARSET);
} }
/**
* Unserialize array
*
* @param string $string
*
* @return array
*/
public static function unserializeArrayRecursive($string)
{
if (is_string($string)) {
$string = unserialize($string);
}
if (!is_array($string)) {
$string = self::unserializeRecursive($string);
}
return $string;
}
public static function explodeFIO($fio) public static function explodeFIO($fio)
{ {
$result = array(); $result = array();

View File

@ -228,6 +228,18 @@
"managerComment": { "managerComment": {
"type": "string" "type": "string"
}, },
"weight": {
"type": "double"
},
"length": {
"type": "int"
},
"width": {
"type": "int"
},
"height": {
"type": "int"
},
"paymentDetail": { "paymentDetail": {
"type": "string" "type": "string"
}, },

View File

@ -599,6 +599,13 @@ class RetailCrmHistory
//items //items
$basket = $newOrder->getBasket(); $basket = $newOrder->getBasket();
$fUserId = $basket->getFUserId(true);
if ($fUserId === null) {
$fUserId = Bitrix\Sale\Fuser::getIdByUserId($order['customer']['externalId']);
$basket->setFUserId($fUserId);
}
if (isset($order['items'])) { if (isset($order['items'])) {
$itemUpdate = true; $itemUpdate = true;
foreach ($order['items'] as $product) { foreach ($order['items'] as $product) {

View File

@ -422,7 +422,7 @@ class RetailCrmHistory
} }
} }
if (!$newOrder instanceof \Bitrix\Sale\Order) { if ($newOrder === null) {
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'Bitrix\Sale\Order::load', 'Error order load number=' . $order['number']); RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'Bitrix\Sale\Order::load', 'Error order load number=' . $order['number']);
continue; continue;
@ -466,6 +466,7 @@ class RetailCrmHistory
if ($optionsPayStatuses[$order['status']]) { if ($optionsPayStatuses[$order['status']]) {
$newOrder->setField('STATUS_ID', $optionsPayStatuses[$order['status']]); $newOrder->setField('STATUS_ID', $optionsPayStatuses[$order['status']]);
if (in_array($optionsPayStatuses[$order['status']], $optionsCanselOrder)) { if (in_array($optionsPayStatuses[$order['status']], $optionsCanselOrder)) {
self::unreserveShipment($newOrder);
$newOrder->setFieldNoDemand('CANCELED', 'Y'); $newOrder->setFieldNoDemand('CANCELED', 'Y');
} else { } else {
$newOrder->setFieldNoDemand('CANCELED', 'N'); $newOrder->setFieldNoDemand('CANCELED', 'N');
@ -608,6 +609,13 @@ class RetailCrmHistory
$newOrder->setBasket($basket); $newOrder->setBasket($basket);
} }
$fUserId = $basket->getFUserId(true);
if ($fUserId === null) {
$fUserId = Bitrix\Sale\Fuser::getIdByUserId($order['customer']['externalId']);
$basket->setFUserId($fUserId);
}
if (isset($order['items'])) { if (isset($order['items'])) {
$itemUpdate = true; $itemUpdate = true;
@ -615,7 +623,7 @@ class RetailCrmHistory
$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;
} }
@ -961,7 +969,6 @@ class RetailCrmHistory
$crmCode = isset($orderCrm['delivery']['code']) ? $orderCrm['delivery']['code'] : false; $crmCode = isset($orderCrm['delivery']['code']) ? $orderCrm['delivery']['code'] : false;
$noDeliveryId = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId(); $noDeliveryId = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId();
$basket = $order->getBasket();
if ($crmCode === false || !isset($optionsDelivTypes[$crmCode])) { if ($crmCode === false || !isset($optionsDelivTypes[$crmCode])) {
$deliveryId = $noDeliveryId; $deliveryId = $noDeliveryId;
@ -992,24 +999,20 @@ class RetailCrmHistory
if (!$update) { if (!$update) {
$shipment = $shipmentColl->createItem($delivery); $shipment = $shipmentColl->createItem($delivery);
$shipment->setFields(array( $shipment->setFields(array(
'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', 'CUSTOM_PRICE_DELIVERY' => 'Y'
'DISCOUNT_PRICE' => 0
)); ));
} else { } else {
foreach ($shipmentColl as $shipment) { foreach ($shipmentColl as $shipment) {
if (!$shipment->isSystem()) { if (!$shipment->isSystem()) {
$shipment->setFields(array( $shipment->setFields(array(
'PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
'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', 'CUSTOM_PRICE_DELIVERY' => 'Y'
'DISCOUNT_PRICE' => 0
)); ));
} }
} }
@ -1020,7 +1023,7 @@ class RetailCrmHistory
/** /**
* Update shipment item colletion * Update shipment item colletion
* *
* @param object $order * @param \Bitrix\Sale\Order $order
* *
* @return void | boolean * @return void | boolean
*/ */
@ -1031,10 +1034,24 @@ class RetailCrmHistory
foreach ($shipmentCollection as $shipment) { foreach ($shipmentCollection as $shipment) {
if (!$shipment->isSystem()) { if (!$shipment->isSystem()) {
$reserved = false;
if ($shipment->isReserved()) {
$reserved = true;
}
$shipmentItemColl = $shipment->getShipmentItemCollection(); $shipmentItemColl = $shipment->getShipmentItemCollection();
if ($reserved === true) {
$shipment->tryUnreserve();
}
try { try {
$shipmentItemColl->resetCollection($basket); $shipmentItemColl->resetCollection($basket);
if ($reserved === true) {
$shipment->tryReserve();
}
} catch (\Bitrix\Main\NotSupportedException $NotSupportedException) { } catch (\Bitrix\Main\NotSupportedException $NotSupportedException) {
RCrmActions::eventLog('RetailCrmHistory::shipmentItemReset', '\Bitrix\Sale\ShipmentItemCollection::resetCollection()', $NotSupportedException->getMessage()); RCrmActions::eventLog('RetailCrmHistory::shipmentItemReset', '\Bitrix\Sale\ShipmentItemCollection::resetCollection()', $NotSupportedException->getMessage());
@ -1044,6 +1061,34 @@ class RetailCrmHistory
} }
} }
/**
* Unreserve items if order canceled
*
* @param \Bitrix\Sale\Order $order
*
* @return void | boolean
*/
public static function unreserveShipment($order)
{
$shipmentCollection = $order->getShipmentCollection();
foreach ($shipmentCollection as $shipment) {
if (!$shipment->isSystem()) {
try {
$shipment->tryUnreserve();
} catch (Main\ArgumentOutOfRangeException $ArgumentOutOfRangeException) {
RCrmActions::eventLog('RetailCrmHistory::unreserveShipment', '\Bitrix\Sale\Shipment::tryUnreserve()', $ArgumentOutOfRangeException->getMessage());
return false;
} catch (Main\NotSupportedException $NotSupportedException) {
RCrmActions::eventLog('RetailCrmHistory::unreserveShipment', '\Bitrix\Sale\Shipment::tryUnreserve()', $NotSupportedException->getMessage());
return false;
}
}
}
}
/** /**
* Update payment in order * Update payment in order
* *
@ -1191,11 +1236,11 @@ class RetailCrmHistory
$info = array( $info = array(
'NAME' => $elementInfo['NAME'], 'NAME' => $elementInfo['NAME'],
'URL' => $url, 'URL' => $url,
'DIMENSIONS' => serialize(serialize(array( 'DIMENSIONS' => serialize(array(
'WIDTH' => $catalog['WIDTH'], 'WIDTH' => $catalog['WIDTH'],
'HEIGHT' => $catalog['HEIGHT'], 'HEIGHT' => $catalog['HEIGHT'],
'LENGTH' => $catalog['LENGTH'], 'LENGTH' => $catalog['LENGTH'],
))), )),
'WEIGHT' => $catalog['WEIGHT'], 'WEIGHT' => $catalog['WEIGHT'],
'XML_ID' => $elementInfo["XML_ID"], 'XML_ID' => $elementInfo["XML_ID"],
'IBLOCK_XML_ID' => $elementInfo["IBLOCK_EXTERNAL_ID"] 'IBLOCK_XML_ID' => $elementInfo["IBLOCK_EXTERNAL_ID"]

View File

@ -122,6 +122,11 @@ class RetailCrmOrder
} }
} }
$weight = 0;
$width = 0;
$height = 0;
$length = 0;
//basket //basket
foreach ($arFields['BASKET'] as $product) { foreach ($arFields['BASKET'] as $product) {
$item = array( $item = array(
@ -141,8 +146,19 @@ class RetailCrmOrder
$item['initialPrice'] = (double) $product['PRICE'] + (double) $product['DISCOUNT_PRICE']; $item['initialPrice'] = (double) $product['PRICE'] + (double) $product['DISCOUNT_PRICE'];
$order['items'][] = $item; $order['items'][] = $item;
$dimensions = RCrmActions::unserializeArrayRecursive($product['DIMENSIONS']);
$width += $dimensions['WIDTH'];
$height += $dimensions['HEIGHT'];
$length += $dimensions['LENGTH'];
$weight += $product['WEIGHT'];
} }
$order['width'] = $width;
$order['height'] = $height;
$order['length'] = $length;
$order['weight'] = $weight;
//payments //payments
$payments = array(); $payments = array();
foreach ($arFields['PAYMENTS'] as $payment) { foreach ($arFields['PAYMENTS'] as $payment) {

View File

@ -31,7 +31,15 @@ class RetailCrmUa
</script>"; </script>";
if (isset($_GET['ORDER_ID'])) { if (isset($_GET['ORDER_ID'])) {
CModule::IncludeModule("sale"); CModule::IncludeModule("sale");
$arOrder = CSaleOrder::GetByID($_GET['ORDER_ID']); $order = \Bitrix\Sale\Order::loadByAccountNumber($_GET['ORDER_ID']);
if ($order !== null) {
$arOrder = array(
'ID' => $order->getId(),
'PRICE' => $order->getPrice(),
'DISCOUNT_VALUE' => $order->getField('DISCOUNT_VALUE')
);
$ua .= "<script type=\"text/javascript\"> $ua .= "<script type=\"text/javascript\">
ga('require', 'ecommerce', 'ecommerce.js'); ga('require', 'ecommerce', 'ecommerce.js');
ga('ecommerce:addTransaction', { ga('ecommerce:addTransaction', {
@ -61,6 +69,7 @@ class RetailCrmUa
} }
$ua .= "ga('ecommerce:send');"; $ua .= "ga('ecommerce:send');";
} }
}
$ua .= "</script>"; $ua .= "</script>";
$APPLICATION->AddHeadString($ua); $APPLICATION->AddHeadString($ua);

View File

@ -16,7 +16,9 @@ class RetailCrmUser
'externalId' => $arFields['ID'], 'externalId' => $arFields['ID'],
'email' => $arFields['EMAIL'], 'email' => $arFields['EMAIL'],
'createdAt' => new \DateTime($arFields['DATE_REGISTER']), 'createdAt' => new \DateTime($arFields['DATE_REGISTER']),
'contragent' => array(
'contragentType' => $contragentType 'contragentType' => $contragentType
)
); );
if (!empty($arFields['NAME'])) { if (!empty($arFields['NAME'])) {

View File

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

View File

@ -1,5 +1,5 @@
<? <?
$arModuleVersion = array( $arModuleVersion = array(
"VERSION" => "2.3.3", "VERSION" => "2.3.4",
"VERSION_DATE" => "2018-01-23 17:15:00" "VERSION_DATE" => "2018-02-27 17:15:00"
); );