From 2bc97c84ffa88e6be3dbad479cce311be75bda0c Mon Sep 17 00:00:00 2001 From: DanielWeiser <46303277+DanielWeiser@users.noreply.github.com> Date: Thu, 23 Jul 2020 16:28:36 +0300 Subject: [PATCH] Payment and shipment status --- .../general/RetailcrmConfigProvider.php | 17 +++++++++++ .../classes/general/RetailcrmConstants.php | 1 + .../general/history/RetailCrmHistory_v5.php | 29 ++++++++++++++++++- intaro.retailcrm/options.php | 17 +++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) diff --git a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php index 789db8b6..070887f8 100644 --- a/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php +++ b/intaro.retailcrm/classes/general/RetailcrmConfigProvider.php @@ -51,6 +51,9 @@ class RetailcrmConfigProvider /** @var bool|null|string */ private static $corporateClient; + /** @var bool|null|string $shipmentDeducted */ + private static $shipmentDeducted; + /** @var array $sitesList */ private static $sitesList; @@ -516,7 +519,21 @@ class RetailcrmConfigProvider return static::$shops; } + + /** + * getShipmentDeducted + * + * @return bool|string|null + */ + public static function getShipmentDeducted() + { + if (self::isEmptyNotZero(static::$shipmentDeducted)) { + static::$shipmentDeducted = static::getOption(RetailcrmConstants::CRM_SHIPMENT_DEDUCTED); + } + return static::$shipmentDeducted; + } + /** * isPhoneRequired * diff --git a/intaro.retailcrm/classes/general/RetailcrmConstants.php b/intaro.retailcrm/classes/general/RetailcrmConstants.php index 4dc323d5..cba861ec 100644 --- a/intaro.retailcrm/classes/general/RetailcrmConstants.php +++ b/intaro.retailcrm/classes/general/RetailcrmConstants.php @@ -76,4 +76,5 @@ class RetailcrmConstants const CRM_ORDER_DIMENSIONS = 'order_dimensions'; const CANCEL_PROPERTY_CODE = 'INTAROCRM_IS_CANCELED'; const CRM_INTEGRATION_DELIVERY = 'integration_delivery'; + const CRM_SHIPMENT_DEDUCTED = 'shipment_deducted'; } diff --git a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php index c137aa1b..25d95613 100644 --- a/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php +++ b/intaro.retailcrm/classes/general/history/RetailCrmHistory_v5.php @@ -101,7 +101,7 @@ class RetailCrmHistory $registerNewUser = true; - if (!empty($customer['email'])) { + if (!empty($customer['email'])) { $dbUser = CUser::GetList(($by = 'ID'), ($sort = 'ASC'), array('=EMAIL' => $customer['email'])); switch ($dbUser->SelectedRowsCount()) { case 0: @@ -212,6 +212,7 @@ class RetailCrmHistory $optionsCanselOrder = RetailcrmConfigProvider::getCancellableOrderPaymentStatuses(); $currency = RetailcrmConfigProvider::getCurrencyOrDefault(); $contragentTypes = array_flip(RetailcrmConfigProvider::getContragentTypes()); + $shipmentDeducted = RetailcrmConfigProvider::getShipmentDeducted(); $api = new RetailCrm\ApiClient(RetailcrmConfigProvider::getApiUrl(), RetailcrmConfigProvider::getApiKey()); @@ -1127,6 +1128,32 @@ class RetailCrmHistory unset($orderCrm); } + if (isset($order['fullPaidAt']) && is_string($order['fullPaidAt'])) { + $newOrder->setField('PAID', 'Y'); + } + + if ($shipmentDeducted === 'Y') { + $collection = $newOrder->getShipmentCollection()->getNotSystemItems(); + + if (isset($order['shipped'])) { + if ($order['shipped']) { + if ($collection->count() === 0) { + $collection = $newOrder->getShipmentCollection(); + $shipment = $collection->createItem(); + $shipment->setField('DEDUCTED', 'Y'); + } else { + foreach ($collection as $shipment) { + $shipment->setField('DEDUCTED', 'Y'); + } + } + } else { + foreach ($collection as $shipment) { + $shipment->setField('DEDUCTED', 'N'); + } + } + } + } + $newOrder->setField('PRICE', $orderSumm); self::orderSave($newOrder); diff --git a/intaro.retailcrm/options.php b/intaro.retailcrm/options.php index 27ff35db..f962b1b2 100644 --- a/intaro.retailcrm/options.php +++ b/intaro.retailcrm/options.php @@ -462,6 +462,13 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { UnRegisterModuleDependences("main", "OnBeforeProlog", $mid, "RetailCrmDc", "add"); } + //shipment + if (htmlspecialchars(trim($_POST['shipment_deducted'])) == 'Y') { + $shipment_deducted = 'Y'; + } else { + $shipment_deducted = 'N'; + } + //corporate-cliente if (htmlspecialchars(trim($_POST['corp-client'])) == 'Y') { $cc = 'Y'; @@ -563,6 +570,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { COption::SetOptionString($mid, $CRM_DISCOUNT_ROUND, $discount_round); COption::SetOptionString($mid, $CRM_PURCHASE_PRICE_NULL, $purchasePrice_null); + COption::SetOptionString($mid, RetailcrmConstants::CRM_SHIPMENT_DEDUCTED, $shipment_deducted); COption::SetOptionString($mid, $CRM_CC, $cc); COption::SetOptionString($mid, $CRM_CORP_SHOPS, serialize(RCrmActions::clearArr($bitrixCorpShopsArr))); @@ -682,6 +690,7 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { $optionDiscRound = COption::GetOptionString($mid, $CRM_DISCOUNT_ROUND, 0); $optionPricePrchaseNull = COption::GetOptionString($mid, $CRM_PURCHASE_PRICE_NULL, 0); + $optionShipmentDeducted = RetailcrmConfigProvider::getShipmentDeducted(); //corporate-cliente $optionCorpClient = COption::GetOptionString($mid, $CRM_CC, 0); @@ -1460,6 +1469,14 @@ if (isset($_POST['Update']) && ($_POST['Update'] == 'Y')) { + + + + + + + + Buttons(); ?>