From 30e6cb9886859aa4f1f31282e7473d4c221a49f2 Mon Sep 17 00:00:00 2001 From: gorokh Date: Fri, 6 Dec 2019 11:01:29 +0300 Subject: [PATCH] =?UTF-8?q?task=2063938=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4?= =?UTF-8?q?=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=BE=D0=B9=20?= =?UTF-8?q?=D0=B2=20CRM=20=D0=BE=D1=87=D0=B8=D1=89=D0=B0=D0=B5=D0=BC=20?= =?UTF-8?q?=D0=BF=D1=83=D1=81=D1=82=D1=8B=D0=B5=20=D0=BF=D0=BE=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/extension/retailcrm/order.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/upload/catalog/model/extension/retailcrm/order.php b/src/upload/catalog/model/extension/retailcrm/order.php index c844c9b..c8e67fb 100644 --- a/src/upload/catalog/model/extension/retailcrm/order.php +++ b/src/upload/catalog/model/extension/retailcrm/order.php @@ -67,10 +67,12 @@ class ModelExtensionRetailcrmOrder extends Model { } if ($create) { + $order = self::filterRecursive($order); $retailcrmApiClient->ordersCreate($order); } else { $order_payment = reset($order['payments']); unset($order['payments']); + $order = self::filterRecursive($order); $response = $retailcrmApiClient->ordersEdit($order); if ($this->settings[$this->moduleTitle . '_apiversion'] == 'v5' && $response->isSuccessful()) { @@ -396,4 +398,29 @@ class ModelExtensionRetailcrmOrder extends Model { return $resultTotals; } + + /** + * Recursive array filter + * + * @param array $haystack input array + * + * @return array + */ + public static function filterRecursive($haystack) + { + foreach ($haystack as $key => $value) { + if (is_array($value)) { + $haystack[$key] = self::filterRecursive($haystack[$key]); + } + if ($haystack[$key] === null + || $haystack[$key] === '' + || (is_array($haystack[$key]) && empty($haystack[$key])) + ) { + unset($haystack[$key]); + } elseif (!is_array($value)) { + $haystack[$key] = trim($value); + } + } + return $haystack; + } }