From d77c03ffdeb0bf0fb814bdf0fd74bd61400be24d Mon Sep 17 00:00:00 2001 From: Uryvskiy Dima Date: Thu, 20 Apr 2023 18:01:25 +0300 Subject: [PATCH] The 'isFromCart' parameter was added when creating an order --- CHANGELOG.md | 3 +++ VERSION | 2 +- retailcrm/lib/RetailcrmExport.php | 26 +++++++++++++++++++++++++- retailcrm/retailcrm.php | 2 +- 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95b9044..d5c3eb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## v3.5.2 +* Добавлен признак корзины при создании заказа + ## v3.5.1 * Обновление формата даты в корзинах diff --git a/VERSION b/VERSION index d5c0c99..87ce492 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3.5.1 +3.5.2 diff --git a/retailcrm/lib/RetailcrmExport.php b/retailcrm/lib/RetailcrmExport.php index 44c4b6b..1a6cc11 100644 --- a/retailcrm/lib/RetailcrmExport.php +++ b/retailcrm/lib/RetailcrmExport.php @@ -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); diff --git a/retailcrm/retailcrm.php b/retailcrm/retailcrm.php index 7b8dd81..1abd475 100644 --- a/retailcrm/retailcrm.php +++ b/retailcrm/retailcrm.php @@ -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';