Поддержка функции добавления одинакового товара в заказ как разные товарные позиции из CRM
This commit is contained in:
parent
defebe6439
commit
b98c6ba9ea
@ -1,3 +1,6 @@
|
|||||||
|
## 2019-09-17 v.2.5.2
|
||||||
|
* Поддержка функции добавления одинакового товара в заказ как разные товарные позиции из CRM
|
||||||
|
|
||||||
## 2019-08-28 v.2.5.1
|
## 2019-08-28 v.2.5.1
|
||||||
* Исправление генерации единиц измерения
|
* Исправление генерации единиц измерения
|
||||||
|
|
||||||
|
@ -126,7 +126,7 @@ class RetailCrmHistory
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($registerNewUser === true) {
|
if ($registerNewUser === true) {
|
||||||
$userPassword = uniqid("R");
|
$userPassword = uniqid();
|
||||||
|
|
||||||
$arFields = array(
|
$arFields = array(
|
||||||
"EMAIL" => $customer['email'],
|
"EMAIL" => $customer['email'],
|
||||||
@ -137,12 +137,12 @@ class RetailCrmHistory
|
|||||||
);
|
);
|
||||||
$registeredUserID = $newUser->Add($arFields);
|
$registeredUserID = $newUser->Add($arFields);
|
||||||
if ($registeredUserID === false) {
|
if ($registeredUserID === false) {
|
||||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'CUser::Register', 'Error register user: ' . $newUser->LAST_ERROR);
|
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'CUser::Register', 'Error register user');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(RCrmActions::apiMethod($api, 'customersFixExternalIds', __METHOD__, array(array('id' => $customer['id'], 'externalId' => $registeredUserID))) == false) {
|
if(RCrmActions::apiMethod($api, 'customersFixExternalIds', __METHOD__, array(array('id' => $customer['id'], 'externalId' => $registeredUserID))) == false) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +361,7 @@ class RetailCrmHistory
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($registerNewUser === true) {
|
if ($registerNewUser === true) {
|
||||||
$userPassword = uniqid("R");
|
$userPassword = uniqid();
|
||||||
|
|
||||||
$newUser = new CUser;
|
$newUser = new CUser;
|
||||||
$arFields = array(
|
$arFields = array(
|
||||||
@ -384,7 +384,7 @@ class RetailCrmHistory
|
|||||||
$registeredUserID = $newUser->Add($arFields);
|
$registeredUserID = $newUser->Add($arFields);
|
||||||
|
|
||||||
if ($registeredUserID === false) {
|
if ($registeredUserID === false) {
|
||||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'CUser::Register', 'Error register user ' . $newUser->LAST_ERROR);
|
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'CUser::Register', 'Error register user');
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -423,7 +423,7 @@ class RetailCrmHistory
|
|||||||
if (isset($order['externalId'])) {
|
if (isset($order['externalId'])) {
|
||||||
$itemUpdate = false;
|
$itemUpdate = false;
|
||||||
|
|
||||||
if ($order['externalId'] && is_numeric($order['externalId'])) {
|
if ($order['externalId']) {
|
||||||
try {
|
try {
|
||||||
$newOrder = Bitrix\Sale\Order::load($order['externalId']);
|
$newOrder = Bitrix\Sale\Order::load($order['externalId']);
|
||||||
} catch (Bitrix\Main\ArgumentNullException $e) {
|
} catch (Bitrix\Main\ArgumentNullException $e) {
|
||||||
@ -566,9 +566,6 @@ class RetailCrmHistory
|
|||||||
}
|
}
|
||||||
} elseif (array_key_exists($key, $order['delivery']['address'])) {
|
} elseif (array_key_exists($key, $order['delivery']['address'])) {
|
||||||
if ($propsKey[$orderProp]['TYPE'] == 'LOCATION') {
|
if ($propsKey[$orderProp]['TYPE'] == 'LOCATION') {
|
||||||
if( $order['delivery']['address']['index'] ) {
|
|
||||||
$location = CSaleLocation::GetByZIP($order['delivery']['address']['index']);
|
|
||||||
}
|
|
||||||
$order['delivery']['address'][$key] = trim($order['delivery']['address'][$key]);
|
$order['delivery']['address'][$key] = trim($order['delivery']['address'][$key]);
|
||||||
if(!empty($order['delivery']['address'][$key])){
|
if(!empty($order['delivery']['address'][$key])){
|
||||||
$parameters = array();
|
$parameters = array();
|
||||||
@ -585,9 +582,7 @@ class RetailCrmHistory
|
|||||||
$parameters['filter']['NAME.LANGUAGE_ID'] = 'ru';
|
$parameters['filter']['NAME.LANGUAGE_ID'] = 'ru';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ( !isset($location) ) {
|
$location = \Bitrix\Sale\Location\Search\Finder::find($parameters, array('USE_INDEX' => false, 'USE_ORM' => false))->fetch();
|
||||||
$location = \Bitrix\Sale\Location\Search\Finder::find($parameters, array('USE_INDEX' => false, 'USE_ORM' => false))->fetch();
|
|
||||||
}
|
|
||||||
$somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']);
|
$somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']);
|
||||||
self::setProp($somePropValue, $location['CODE']);
|
self::setProp($somePropValue, $location['CODE']);
|
||||||
} catch (\Bitrix\Main\ArgumentException $argumentException) {
|
} catch (\Bitrix\Main\ArgumentException $argumentException) {
|
||||||
@ -611,7 +606,7 @@ class RetailCrmHistory
|
|||||||
foreach ($optionsLegalDetails[$personType] as $key => $orderProp) {
|
foreach ($optionsLegalDetails[$personType] as $key => $orderProp) {
|
||||||
if (array_key_exists($key, $order)) {
|
if (array_key_exists($key, $order)) {
|
||||||
$somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']);
|
$somePropValue = $propertyCollection->getItemByOrderPropertyId($propsKey[$orderProp]['ID']);
|
||||||
self::setProp($somePropValue, RCrmActions::fromJSON($order[$key]));
|
self::setProp($somePropValue, $order[$key]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -646,11 +641,32 @@ class RetailCrmHistory
|
|||||||
if (isset($order['items'])) {
|
if (isset($order['items'])) {
|
||||||
$itemUpdate = true;
|
$itemUpdate = true;
|
||||||
|
|
||||||
|
$response = RCrmActions::apiMethod($api, 'orderGet', __METHOD__, $order['id']);
|
||||||
|
if (isset($response['order'])) {
|
||||||
|
$orderTemp = $response['order'];
|
||||||
|
$ditems = [];
|
||||||
|
foreach ($orderTemp['items'] as $item) {
|
||||||
|
$ditems[$item['offer']['xmlId']]['quantity'] += $item['quantity'];
|
||||||
|
$ditems[$item['offer']['xmlId']]['discountTotal'] += $item['quantity'] * $item['discountTotal'];
|
||||||
|
$ditems[$item['offer']['xmlId']]['initialPrice'] = (float)$item['initialPrice'];
|
||||||
|
$ditems[$item['offer']['xmlId']]['price_sum'] = $ditems[$item['offer']['xmlId']]['initialPrice'] * $ditems[$item['offer']['xmlId']]['quantity'] - $ditems[$item['offer']['xmlId']]['discountTotal'];
|
||||||
|
$ditems[$item['offer']['xmlId']]['price_item'] = $ditems[$item['offer']['xmlId']]['price_sum'] / $ditems[$item['offer']['xmlId']]['quantity'];
|
||||||
|
}
|
||||||
|
unset($orderTemp);
|
||||||
|
}
|
||||||
|
|
||||||
|
$log->write($ditems, 'duplicateItemsOrderHistory');
|
||||||
|
|
||||||
foreach ($order['items'] as $product) {
|
foreach ($order['items'] as $product) {
|
||||||
|
if($ditems[$product['offer']['xmlId']]['quantity']){
|
||||||
|
$product['quantity'] = $ditems[$product['offer']['xmlId']]['quantity'];
|
||||||
|
}
|
||||||
|
|
||||||
$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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -679,9 +695,11 @@ class RetailCrmHistory
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($product['delete']) {
|
if ($product['delete']) {
|
||||||
$item->delete();
|
if ($ditems[$product['offer']['xmlId']]['quantity'] <= 0) {
|
||||||
|
$item->delete();
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($product['quantity']) {
|
if ($product['quantity']) {
|
||||||
@ -709,6 +727,12 @@ class RetailCrmHistory
|
|||||||
$item->setField('DISCOUNT_VALUE', '');
|
$item->setField('DISCOUNT_VALUE', '');
|
||||||
$item->setField('DISCOUNT_PRICE', $resultDiscount);
|
$item->setField('DISCOUNT_PRICE', $resultDiscount);
|
||||||
$item->setField('PRICE', $itemCost - $resultDiscount);
|
$item->setField('PRICE', $itemCost - $resultDiscount);
|
||||||
|
|
||||||
|
//set price dublicate item
|
||||||
|
if ($ditems[$product['offer']['xmlId']]['price_item']) {
|
||||||
|
$item->setField('PRICE', $ditems[$product['offer']['xmlId']]['price_item']);
|
||||||
|
$item->setField('DISCOUNT_PRICE', '');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -772,16 +796,20 @@ class RetailCrmHistory
|
|||||||
if (!empty($newHistoryPayments)) {
|
if (!empty($newHistoryPayments)) {
|
||||||
foreach ($newOrder->getPaymentCollection() as $orderPayment) {
|
foreach ($newOrder->getPaymentCollection() as $orderPayment) {
|
||||||
if (array_key_exists($orderPayment->getField('XML_ID'), $newHistoryPayments)) {
|
if (array_key_exists($orderPayment->getField('XML_ID'), $newHistoryPayments)) {
|
||||||
|
|
||||||
$paymentId = $orderPayment->getId();
|
$paymentId = $orderPayment->getId();
|
||||||
$paymentExternalId = RCrmActions::generatePaymentExternalId($paymentId);
|
$paymentExternalId = RCrmActions::generatePaymentExternalId($paymentId);
|
||||||
if (is_null($paymentId)) {
|
if (is_null($paymentId)) {
|
||||||
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'paymentsUpdate', 'Save payment error, order=' . $order['number']);
|
RCrmActions::eventLog('RetailCrmHistory::orderHistory', 'paymentsUpdate', 'Save payment error, order=' . $order['number']);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$paymentExternalId = $orderPayment->getId();
|
||||||
|
|
||||||
if ($paymentExternalId) {
|
if ($paymentExternalId) {
|
||||||
$newHistoryPayments[$orderPayment->getField('XML_ID')]['externalId'] = $paymentExternalId;
|
$newHistoryPayments[$orderPayment->getField('XML_ID')]['externalId'] = $paymentExternalId;
|
||||||
RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $newHistoryPayments[$orderPayment->getField('XML_ID')]);
|
RCrmActions::apiMethod($api, 'paymentEditById', __METHOD__, $newHistoryPayments[$orderPayment->getField('XML_ID')]);
|
||||||
\Bitrix\Sale\Internals\PaymentTable::update($paymentId, array('XML_ID' => ''));
|
\Bitrix\Sale\Internals\PaymentTable::update($paymentExternalId, array('XML_ID' => ''));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -815,6 +843,26 @@ class RetailCrmHistory
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $array
|
||||||
|
* @param $value
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function search_array_by_value($array, $value)
|
||||||
|
{
|
||||||
|
$results = array();
|
||||||
|
if (is_array($array)) {
|
||||||
|
$found = array_search($value,$array);
|
||||||
|
if ($found) {
|
||||||
|
$results[] = $found;
|
||||||
|
}
|
||||||
|
foreach ($array as $subarray)
|
||||||
|
$results = array_merge($results, static::search_array_by_value($subarray, $value));
|
||||||
|
}
|
||||||
|
return $results;
|
||||||
|
}
|
||||||
|
|
||||||
public static function assemblyCustomer($customerHistory)
|
public static function assemblyCustomer($customerHistory)
|
||||||
{
|
{
|
||||||
$server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot();
|
$server = \Bitrix\Main\Context::getCurrent()->getServer()->getDocumentRoot();
|
||||||
@ -1017,9 +1065,10 @@ class RetailCrmHistory
|
|||||||
$serviceCode = str_replace(array('-'), "_", $serviceCode);
|
$serviceCode = str_replace(array('-'), "_", $serviceCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($deliveryCode) {
|
if ($deliveryCode) {
|
||||||
try {
|
try {
|
||||||
$deliveryService = \Bitrix\Sale\Delivery\Services\Manager::getObjectByCode($deliveryCode . ':' . $serviceCode);
|
$deliveryService = \Bitrix\Sale\Delivery\Services\Manager::getObjectByCode($deliveryCode . ':' . $orderCrm['delivery']['service']['code']);
|
||||||
} catch (Bitrix\Main\SystemException $systemException) {
|
} catch (Bitrix\Main\SystemException $systemException) {
|
||||||
RCrmActions::eventLog('RetailCrmHistory::deliveryEdit', '\Bitrix\Sale\Delivery\Services\Manager::getObjectByCode', $systemException->getMessage());
|
RCrmActions::eventLog('RetailCrmHistory::deliveryEdit', '\Bitrix\Sale\Delivery\Services\Manager::getObjectByCode', $systemException->getMessage());
|
||||||
}
|
}
|
||||||
@ -1036,13 +1085,13 @@ class RetailCrmHistory
|
|||||||
|
|
||||||
if ($delivery) {
|
if ($delivery) {
|
||||||
if (!$update) {
|
if (!$update) {
|
||||||
$shipment = $shipmentColl->createItem($delivery);
|
$shipment = $shipmentColl->createItem($delivery);
|
||||||
$shipment->setFields(array(
|
$shipment->setFields(array(
|
||||||
'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'
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
foreach ($shipmentColl as $shipment) {
|
foreach ($shipmentColl as $shipment) {
|
||||||
if (!$shipment->isSystem()) {
|
if (!$shipment->isSystem()) {
|
||||||
@ -1157,8 +1206,7 @@ class RetailCrmHistory
|
|||||||
foreach ($paymentsCrm['payments'] as $paymentCrm) {
|
foreach ($paymentsCrm['payments'] as $paymentCrm) {
|
||||||
if (isset($paymentCrm['externalId']) && !empty($paymentCrm['externalId'])) {
|
if (isset($paymentCrm['externalId']) && !empty($paymentCrm['externalId'])) {
|
||||||
//find the payment
|
//find the payment
|
||||||
$nowPaymentId = RCrmActions::getFromPaymentExternalId($paymentCrm['externalId']);
|
$nowPayment = $paymentsList[$paymentCrm['externalId']];
|
||||||
$nowPayment = $paymentsList[$nowPaymentId];
|
|
||||||
//update data
|
//update data
|
||||||
if ($nowPayment instanceof \Bitrix\Sale\Payment) {
|
if ($nowPayment instanceof \Bitrix\Sale\Payment) {
|
||||||
$nowPayment->setField('SUM', $paymentCrm['amount']);
|
$nowPayment->setField('SUM', $paymentCrm['amount']);
|
||||||
@ -1170,7 +1218,7 @@ class RetailCrmHistory
|
|||||||
$nowPayment->setField('PAID', $optionsPayment[$paymentCrm['status']]);
|
$nowPayment->setField('PAID', $optionsPayment[$paymentCrm['status']]);
|
||||||
}
|
}
|
||||||
|
|
||||||
unset($paymentsList[$nowPaymentId]);
|
unset($paymentsList[$paymentCrm['externalId']]);
|
||||||
}
|
}
|
||||||
} elseif (array_key_exists($paymentCrm['type'], $optionsPayTypes)) {
|
} elseif (array_key_exists($paymentCrm['type'], $optionsPayTypes)) {
|
||||||
$newHistoryPayments[$paymentCrm['id']] = $paymentCrm;
|
$newHistoryPayments[$paymentCrm['id']] = $paymentCrm;
|
||||||
|
@ -56,9 +56,9 @@ class RetailCrmOrder
|
|||||||
'createdAt' => $arFields['DATE_INSERT'],
|
'createdAt' => $arFields['DATE_INSERT'],
|
||||||
'customer' => array('externalId' => $arFields['USER_ID']),
|
'customer' => array('externalId' => $arFields['USER_ID']),
|
||||||
'orderType' => isset($arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']]) ?
|
'orderType' => isset($arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']]) ?
|
||||||
$arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']] : '',
|
$arParams['optionsOrderTypes'][$arFields['PERSON_TYPE_ID']] : '',
|
||||||
'status' => isset($arParams['optionsPayStatuses'][$arFields['STATUS_ID']]) ?
|
'status' => isset($arParams['optionsPayStatuses'][$arFields['STATUS_ID']]) ?
|
||||||
$arParams['optionsPayStatuses'][$arFields['STATUS_ID']] : '',
|
$arParams['optionsPayStatuses'][$arFields['STATUS_ID']] : '',
|
||||||
'customerComment' => $arFields['USER_DESCRIPTION'],
|
'customerComment' => $arFields['USER_DESCRIPTION'],
|
||||||
'managerComment' => $arFields['COMMENTS'],
|
'managerComment' => $arFields['COMMENTS'],
|
||||||
'delivery' => array(
|
'delivery' => array(
|
||||||
@ -140,10 +140,11 @@ class RetailCrmOrder
|
|||||||
//basket
|
//basket
|
||||||
foreach ($arFields['BASKET'] as $product) {
|
foreach ($arFields['BASKET'] as $product) {
|
||||||
$item = array(
|
$item = array(
|
||||||
|
'externalId' => $product['PRODUCT_ID'],
|
||||||
'quantity' => $product['QUANTITY'],
|
'quantity' => $product['QUANTITY'],
|
||||||
'offer' => array('externalId' => $product['PRODUCT_ID'],
|
'offer' => array('externalId' => $product['PRODUCT_ID'],
|
||||||
'xmlId' => $product['PRODUCT_XML_ID']
|
'xmlId' => $product['PRODUCT_XML_ID']
|
||||||
),
|
),
|
||||||
'productName' => $product['NAME']
|
'productName' => $product['NAME']
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -205,7 +206,7 @@ class RetailCrmOrder
|
|||||||
'amount' => $payment['SUM']
|
'amount' => $payment['SUM']
|
||||||
);
|
);
|
||||||
if (!empty($payment['ID'])) {
|
if (!empty($payment['ID'])) {
|
||||||
$pm['externalId'] = $payment['ID'];
|
$pm['externalId'] = RCrmActions::generatePaymentExternalId($payment['ID']);
|
||||||
}
|
}
|
||||||
if (!empty($payment['DATE_PAID'])) {
|
if (!empty($payment['DATE_PAID'])) {
|
||||||
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
|
$pm['paidAt'] = new \DateTime($payment['DATE_PAID']);
|
||||||
|
@ -1 +1 @@
|
|||||||
- Исправление генерации единиц измерения
|
- Поддержка функции добавления одинакового товара в заказ как разные товарные позиции из CRM
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?
|
<?
|
||||||
$arModuleVersion = array(
|
$arModuleVersion = array(
|
||||||
"VERSION" => "2.5.1",
|
"VERSION" => "2.5.2",
|
||||||
"VERSION_DATE" => "2019-08-28 15:20:00"
|
"VERSION_DATE" => "2019-09-17 15:20:00"
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user