The 'isFromCart' parameter was added when creating an order

This commit is contained in:
Uryvskiy Dima 2023-04-20 18:01:25 +03:00
parent 3110960d06
commit d77c03ffde
4 changed files with 30 additions and 3 deletions

View file

@ -1,3 +1,6 @@
## v3.5.2
* Добавлен признак корзины при создании заказа
## v3.5.1
* Обновление формата даты в корзинах

View file

@ -1 +1 @@
3.5.1
3.5.2

View file

@ -396,7 +396,8 @@ class RetailcrmExport
throw new RetailcrmNotFoundException('Order not found');
}
$customer = new Customer($object->id_customer);
$customerId = $object->id_customer;
$customer = new Customer($customerId);
$apiResponse = static::$api->ordersGet($object->id);
$existingOrder = [];
@ -418,6 +419,29 @@ class RetailcrmExport
}
if (empty($existingOrder)) {
try {
$reference = new RetailcrmReferences(static::$api);
$site = $reference->getSite()['code'];
$crmCart = static::$api->cartGet($customerId, $site);
if (!empty($crmCart['cart'])) {
// If the order is from a corporate customer, need to clear the cart for the contact person
if (!empty($crmOrder['contragent']['legalName']) && !empty($crmOrder['contact'])) {
static::$api->cartClear(
[
'clearedAt' => date('Y-m-d H:i:sP'),
'customer' => ['externalId' => $customerId],
],
$site
);
} else {
$crmOrder['isFromCart'] = true;
}
}
} catch (Throwable $exception) {
self::handleError($customerId, $exception);
}
$response = static::$api->ordersCreate($crmOrder);
} else {
$response = static::$api->ordersEdit($crmOrder);

View file

@ -48,7 +48,7 @@ require_once dirname(__FILE__) . '/bootstrap.php';
class RetailCRM extends Module
{
const VERSION = '3.5.1';
const VERSION = '3.5.2';
const API_URL = 'RETAILCRM_ADDRESS';
const API_KEY = 'RETAILCRM_API_TOKEN';