v.2.3.4 (#39)
This commit is contained in:
parent
a27d2f361e
commit
1e1426f6d3
11
CHANGELOG.md
11
CHANGELOG.md
@ -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
|
||||
* Исправлен баг с рассчетом суммы заказа
|
||||
* Добавлен перехват исключения при редактировании отгруженной доставки
|
||||
|
@ -262,6 +262,26 @@ class RCrmActions
|
||||
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)
|
||||
{
|
||||
$result = array();
|
||||
|
@ -228,6 +228,18 @@
|
||||
"managerComment": {
|
||||
"type": "string"
|
||||
},
|
||||
"weight": {
|
||||
"type": "double"
|
||||
},
|
||||
"length": {
|
||||
"type": "int"
|
||||
},
|
||||
"width": {
|
||||
"type": "int"
|
||||
},
|
||||
"height": {
|
||||
"type": "int"
|
||||
},
|
||||
"paymentDetail": {
|
||||
"type": "string"
|
||||
},
|
||||
|
@ -599,6 +599,13 @@ class RetailCrmHistory
|
||||
|
||||
//items
|
||||
$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'])) {
|
||||
$itemUpdate = true;
|
||||
foreach ($order['items'] as $product) {
|
||||
|
@ -271,21 +271,21 @@ class RetailCrmHistory
|
||||
|
||||
$log = new Logger();
|
||||
$log->write($orderH, 'orderHistory');
|
||||
|
||||
|
||||
if (count($orderH) == 0) {
|
||||
if ($orderHistory['history']['totalPageCount'] > $orderHistory['history']['currentPage']) {
|
||||
$historyFilter['page'] = $orderHistory['history']['currentPage'] + 1;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
$orders = self::assemblyOrder($orderH);
|
||||
|
||||
|
||||
$GLOBALS['RETAIL_CRM_HISTORY'] = true;
|
||||
|
||||
|
||||
//orders with changes
|
||||
foreach ($orders as $order) {
|
||||
if (function_exists('retailCrmBeforeOrderSave')) {
|
||||
@ -298,9 +298,9 @@ class RetailCrmHistory
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$log->write($order, 'assemblyOrderHistory');
|
||||
|
||||
|
||||
if (isset($order['deleted'])) {
|
||||
if (isset($order['externalId'])) {
|
||||
try {
|
||||
@ -314,7 +314,7 @@ class RetailCrmHistory
|
||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'Bitrix\Sale\Order::load', 'Error order load: ' . $order['externalId']);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
$newOrder->setField('CANCELED', 'Y');
|
||||
$newOrder->save();
|
||||
}
|
||||
@ -422,9 +422,9 @@ 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']);
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -466,6 +466,7 @@ class RetailCrmHistory
|
||||
if ($optionsPayStatuses[$order['status']]) {
|
||||
$newOrder->setField('STATUS_ID', $optionsPayStatuses[$order['status']]);
|
||||
if (in_array($optionsPayStatuses[$order['status']], $optionsCanselOrder)) {
|
||||
self::unreserveShipment($newOrder);
|
||||
$newOrder->setFieldNoDemand('CANCELED', 'Y');
|
||||
} else {
|
||||
$newOrder->setFieldNoDemand('CANCELED', 'N');
|
||||
@ -608,6 +609,13 @@ class RetailCrmHistory
|
||||
$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'])) {
|
||||
$itemUpdate = true;
|
||||
|
||||
@ -615,7 +623,7 @@ class RetailCrmHistory
|
||||
$item = self::getExistsItem($basket, 'catalog', $product['offer']['externalId']);
|
||||
|
||||
if (!$item) {
|
||||
if($product['delete']){
|
||||
if ($product['delete']) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -638,7 +646,7 @@ class RetailCrmHistory
|
||||
));
|
||||
} else {
|
||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'createItem', 'Error item add');
|
||||
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -718,8 +726,8 @@ class RetailCrmHistory
|
||||
|
||||
if ($optionsOrderNumbers == 'Y' && isset($order['number'])) {
|
||||
$searchFilter = array(
|
||||
'filter' => array('ACCOUNT_NUMBER' => $order['number']),
|
||||
'select' => array('ID'),
|
||||
'filter' => array('ACCOUNT_NUMBER' => $order['number']),
|
||||
'select' => array('ID'),
|
||||
);
|
||||
$searchOrder = \Bitrix\Sale\OrderTable::GetList($searchFilter)->fetch();
|
||||
if (!empty($searchOrder)) {
|
||||
@ -961,7 +969,6 @@ class RetailCrmHistory
|
||||
|
||||
$crmCode = isset($orderCrm['delivery']['code']) ? $orderCrm['delivery']['code'] : false;
|
||||
$noDeliveryId = \Bitrix\Sale\Delivery\Services\EmptyDeliveryService::getEmptyDeliveryServiceId();
|
||||
$basket = $order->getBasket();
|
||||
|
||||
if ($crmCode === false || !isset($optionsDelivTypes[$crmCode])) {
|
||||
$deliveryId = $noDeliveryId;
|
||||
@ -992,24 +999,20 @@ class RetailCrmHistory
|
||||
if (!$update) {
|
||||
$shipment = $shipmentColl->createItem($delivery);
|
||||
$shipment->setFields(array(
|
||||
'PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
|
||||
'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
|
||||
'CURRENCY' => $order->getCurrency(),
|
||||
'DELIVERY_NAME' => $delivery->getName(),
|
||||
'CUSTOM_PRICE_DELIVERY' => 'Y',
|
||||
'DISCOUNT_PRICE' => 0
|
||||
'CUSTOM_PRICE_DELIVERY' => 'Y'
|
||||
));
|
||||
} else {
|
||||
foreach ($shipmentColl as $shipment) {
|
||||
if (!$shipment->isSystem()) {
|
||||
$shipment->setFields(array(
|
||||
'PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
|
||||
'BASE_PRICE_DELIVERY' => $orderCrm['delivery']['cost'],
|
||||
'CURRENCY' => $order->getCurrency(),
|
||||
'DELIVERY_ID' => $deliveryId,
|
||||
'DELIVERY_NAME' => $delivery->getName(),
|
||||
'CUSTOM_PRICE_DELIVERY' => 'Y',
|
||||
'DISCOUNT_PRICE' => 0
|
||||
'CUSTOM_PRICE_DELIVERY' => 'Y'
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -1020,7 +1023,7 @@ class RetailCrmHistory
|
||||
/**
|
||||
* Update shipment item colletion
|
||||
*
|
||||
* @param object $order
|
||||
* @param \Bitrix\Sale\Order $order
|
||||
*
|
||||
* @return void | boolean
|
||||
*/
|
||||
@ -1031,10 +1034,24 @@ class RetailCrmHistory
|
||||
|
||||
foreach ($shipmentCollection as $shipment) {
|
||||
if (!$shipment->isSystem()) {
|
||||
$reserved = false;
|
||||
|
||||
if ($shipment->isReserved()) {
|
||||
$reserved = true;
|
||||
}
|
||||
|
||||
$shipmentItemColl = $shipment->getShipmentItemCollection();
|
||||
|
||||
if ($reserved === true) {
|
||||
$shipment->tryUnreserve();
|
||||
}
|
||||
|
||||
try {
|
||||
$shipmentItemColl->resetCollection($basket);
|
||||
$shipmentItemColl->resetCollection($basket);
|
||||
|
||||
if ($reserved === true) {
|
||||
$shipment->tryReserve();
|
||||
}
|
||||
} catch (\Bitrix\Main\NotSupportedException $NotSupportedException) {
|
||||
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
|
||||
*
|
||||
@ -1191,11 +1236,11 @@ class RetailCrmHistory
|
||||
$info = array(
|
||||
'NAME' => $elementInfo['NAME'],
|
||||
'URL' => $url,
|
||||
'DIMENSIONS' => serialize(serialize(array(
|
||||
'DIMENSIONS' => serialize(array(
|
||||
'WIDTH' => $catalog['WIDTH'],
|
||||
'HEIGHT' => $catalog['HEIGHT'],
|
||||
'LENGTH' => $catalog['LENGTH'],
|
||||
))),
|
||||
)),
|
||||
'WEIGHT' => $catalog['WEIGHT'],
|
||||
'XML_ID' => $elementInfo["XML_ID"],
|
||||
'IBLOCK_XML_ID' => $elementInfo["IBLOCK_EXTERNAL_ID"]
|
||||
|
@ -122,6 +122,11 @@ class RetailCrmOrder
|
||||
}
|
||||
}
|
||||
|
||||
$weight = 0;
|
||||
$width = 0;
|
||||
$height = 0;
|
||||
$length = 0;
|
||||
|
||||
//basket
|
||||
foreach ($arFields['BASKET'] as $product) {
|
||||
$item = array(
|
||||
@ -141,8 +146,19 @@ class RetailCrmOrder
|
||||
$item['initialPrice'] = (double) $product['PRICE'] + (double) $product['DISCOUNT_PRICE'];
|
||||
|
||||
$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 = array();
|
||||
foreach ($arFields['PAYMENTS'] as $payment) {
|
||||
@ -341,7 +357,7 @@ class RetailCrmOrder
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public static function orderObjToArr($obOrder)
|
||||
{
|
||||
$arOrder = array(
|
||||
@ -363,7 +379,7 @@ class RetailCrmOrder
|
||||
'COMMENTS' => $obOrder->getField('COMMENTS'),
|
||||
'REASON_CANCELED' => $obOrder->getField('REASON_CANCELED'),
|
||||
);
|
||||
|
||||
|
||||
$shipmentList = $obOrder->getShipmentCollection();
|
||||
foreach ($shipmentList as $shipmentData) {
|
||||
if ($shipmentData->getDeliveryId()) {
|
||||
@ -383,7 +399,7 @@ class RetailCrmOrder
|
||||
$arOrder['DELIVERYS'][] = $shipment;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$paymentList = $obOrder->getPaymentCollection();
|
||||
foreach ($paymentList as $paymentData) {
|
||||
$arOrder['PAYMENTS'][] = $paymentData->getFields()->getValues();
|
||||
@ -393,7 +409,7 @@ class RetailCrmOrder
|
||||
foreach ($basketItems as $item) {
|
||||
$arOrder['BASKET'][] = $item->getFields();
|
||||
}
|
||||
|
||||
|
||||
return $arOrder;
|
||||
}
|
||||
}
|
||||
|
@ -31,8 +31,16 @@ class RetailCrmUa
|
||||
</script>";
|
||||
if (isset($_GET['ORDER_ID'])) {
|
||||
CModule::IncludeModule("sale");
|
||||
$arOrder = CSaleOrder::GetByID($_GET['ORDER_ID']);
|
||||
$ua .= "<script type=\"text/javascript\">
|
||||
$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\">
|
||||
ga('require', 'ecommerce', 'ecommerce.js');
|
||||
ga('ecommerce:addTransaction', {
|
||||
'id': $arOrder[ID],
|
||||
@ -40,26 +48,27 @@ class RetailCrmUa
|
||||
'revenue': $arOrder[PRICE],
|
||||
'tax': $arOrder[DISCOUNT_VALUE]
|
||||
});
|
||||
";
|
||||
$arBasketItems = CsaleBasket::GetList(
|
||||
array('id' => 'asc'),
|
||||
array('ORDER_ID' => $_GET['ORDER_ID']),
|
||||
false,
|
||||
false,
|
||||
array('PRODUCT_ID', 'NAME', 'PRICE', 'QUANTITY', 'ORDER_ID', 'ID')
|
||||
);
|
||||
while ($arItem = $arBasketItems->fetch()) {
|
||||
$ua .= "
|
||||
ga('ecommerce:addItem', {
|
||||
'id': $arOrder[ID],
|
||||
'sku': '$arItem[PRODUCT_ID]',
|
||||
'name': '$arItem[NAME]',
|
||||
'price': $arItem[PRICE],
|
||||
'quantity': $arItem[QUANTITY]
|
||||
});
|
||||
";
|
||||
$arBasketItems = CsaleBasket::GetList(
|
||||
array('id' => 'asc'),
|
||||
array('ORDER_ID' => $_GET['ORDER_ID']),
|
||||
false,
|
||||
false,
|
||||
array('PRODUCT_ID', 'NAME', 'PRICE', 'QUANTITY', 'ORDER_ID', 'ID')
|
||||
);
|
||||
while ($arItem = $arBasketItems->fetch()) {
|
||||
$ua .= "
|
||||
ga('ecommerce:addItem', {
|
||||
'id': $arOrder[ID],
|
||||
'sku': '$arItem[PRODUCT_ID]',
|
||||
'name': '$arItem[NAME]',
|
||||
'price': $arItem[PRICE],
|
||||
'quantity': $arItem[QUANTITY]
|
||||
});
|
||||
";
|
||||
}
|
||||
$ua .= "ga('ecommerce:send');";
|
||||
}
|
||||
$ua .= "ga('ecommerce:send');";
|
||||
}
|
||||
$ua .= "</script>";
|
||||
|
||||
|
@ -16,7 +16,9 @@ class RetailCrmUser
|
||||
'externalId' => $arFields['ID'],
|
||||
'email' => $arFields['EMAIL'],
|
||||
'createdAt' => new \DateTime($arFields['DATE_REGISTER']),
|
||||
'contragentType' => $contragentType
|
||||
'contragent' => array(
|
||||
'contragentType' => $contragentType
|
||||
)
|
||||
);
|
||||
|
||||
if (!empty($arFields['NAME'])) {
|
||||
|
@ -1,2 +1,5 @@
|
||||
- Исправлен баг с передачей номера заказа
|
||||
- Исправлены мелкие ошибки и недочеты
|
||||
- Добавлена передача веса и габаритов в заказе
|
||||
- Добавлена проверка существования fuser у корзины товаров перед сохранением
|
||||
- Добавлено снятие резерва с товаров при отмене заказа в CRM
|
||||
- Исправлена выборка данных для UA, когда id заказа не совпадает с номером
|
||||
- Исправлены мелкие баги
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?
|
||||
$arModuleVersion = array(
|
||||
"VERSION" => "2.3.3",
|
||||
"VERSION_DATE" => "2018-01-23 17:15:00"
|
||||
"VERSION" => "2.3.4",
|
||||
"VERSION_DATE" => "2018-02-27 17:15:00"
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user