From b2b7c23261bfc6a592278b671f434e54816f0a18 Mon Sep 17 00:00:00 2001 From: Cid Lopes Date: Tue, 11 Aug 2020 11:48:41 +0300 Subject: [PATCH 1/6] Remove excessive loggin when confirming order via Shopware API --- Components/Order/Confirmation.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Components/Order/Confirmation.php b/Components/Order/Confirmation.php index 6a555a26..0165dd57 100644 --- a/Components/Order/Confirmation.php +++ b/Components/Order/Confirmation.php @@ -64,8 +64,6 @@ public function sendOrder(OrderModel $order) // Shopware throws an exception if service does not exist. // This would be the case when using Shopware API or cli $shop = $order->getShop(); - /** @noinspection PhpUndefinedMethodInspection */ - Shopware()->Plugins()->Frontend()->NostoTagging()->getLogger()->error($e->getMessage()); } if ($shop === null) { return; @@ -92,7 +90,11 @@ public function sendOrder(OrderModel $order) $orderConfirmation->send($model, $customerId); } catch (\Exception $e) { /** @noinspection PhpUndefinedMethodInspection */ - Shopware()->Plugins()->Frontend()->NostoTagging()->getLogger()->error($e->getMessage()); + Shopware()->Plugins()->Frontend()->NostoTagging()->getLogger()->error( + sprintf("Nosto order confirmation failed. Messa was: %s", + $e->getMessage() + ) + ); } } } From 1cd79f41baa102064af92e202d736700fbcff458 Mon Sep 17 00:00:00 2001 From: Cid Lopes Date: Tue, 11 Aug 2020 12:03:36 +0300 Subject: [PATCH 2/6] Fix missing ISO code for customer country Fix sending invalid orders to Nosto --- Components/Model/Order/Buyer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Components/Model/Order/Buyer.php b/Components/Model/Order/Buyer.php index 197a725c..1be115ac 100644 --- a/Components/Model/Order/Buyer.php +++ b/Components/Model/Order/Buyer.php @@ -81,7 +81,7 @@ public function loadData(Customer $customer) $this->setLastName($address->getLastname()); $this->setPostCode($address->getZipCode()); $this->setPhone($address->getPhone()); - $this->setCountry($address->getCountry()->getName()); + $this->setCountry($address->getCountry()->getIso()); } } else { /** @phan-suppress-next-line UndeclaredTypeInInlineVar */ From 91780004b79ee87f501de579548e64df599b9921 Mon Sep 17 00:00:00 2001 From: Cid Lopes Date: Tue, 11 Aug 2020 12:05:15 +0300 Subject: [PATCH 3/6] Bump Version && Update Changelog --- Bootstrap.php | 2 +- CHANGELOG.md | 4 ++++ composer.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Bootstrap.php b/Bootstrap.php index b1f86405..ed8d76f6 100644 --- a/Bootstrap.php +++ b/Bootstrap.php @@ -86,7 +86,7 @@ class Shopware_Plugins_Frontend_NostoTagging_Bootstrap extends Shopware_Components_Plugin_Bootstrap { const PLATFORM_NAME = 'shopware'; - const PLUGIN_VERSION = '2.4.6'; + const PLUGIN_VERSION = '2.4.7'; const MENU_PARENT_ID = 23; // Configuration const NEW_ENTITY_MANAGER_VERSION = '5.0.0'; const NEW_ATTRIBUTE_MANAGER_VERSION = '5.2.0'; diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c7b9e5b..cebd9df2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## 2.4.7 +- Fix sending invalid orders to Nosto by setting missing ISO code for customer country +- Remove excessive logging in order confirmation via API operations + ## 2.4.6 - Fix an error where in some installations the plugin source path it is saved incorrectly diff --git a/composer.json b/composer.json index 97cac8c8..099d0c8b 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "license": [ "BSD-3-Clause" ], - "version": "2.4.6", + "version": "2.4.7", "require": { "php": ">=5.4.0", "nosto/php-sdk": "3.15.0" From 21dff27383395abf59f3011a23d9970c350cadea Mon Sep 17 00:00:00 2001 From: Cid Lopes Date: Tue, 11 Aug 2020 13:31:51 +0300 Subject: [PATCH 4/6] Fix typo in log message --- Components/Order/Confirmation.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Components/Order/Confirmation.php b/Components/Order/Confirmation.php index 0165dd57..092a9d41 100644 --- a/Components/Order/Confirmation.php +++ b/Components/Order/Confirmation.php @@ -91,7 +91,7 @@ public function sendOrder(OrderModel $order) } catch (\Exception $e) { /** @noinspection PhpUndefinedMethodInspection */ Shopware()->Plugins()->Frontend()->NostoTagging()->getLogger()->error( - sprintf("Nosto order confirmation failed. Messa was: %s", + sprintf("Nosto order update upsert failed. Message was: %s", $e->getMessage() ) ); From 3e4b0e0000550300aaf96008c9d8244c77645531 Mon Sep 17 00:00:00 2001 From: Cid Lopes Date: Tue, 11 Aug 2020 13:40:10 +0300 Subject: [PATCH 5/6] Ignore logging only for Shopware ServiceNotFoundException --- Components/Order/Confirmation.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Components/Order/Confirmation.php b/Components/Order/Confirmation.php index 092a9d41..00892373 100644 --- a/Components/Order/Confirmation.php +++ b/Components/Order/Confirmation.php @@ -39,6 +39,7 @@ use Shopware\Models\Attribute\Order as OrderAttribute; use Shopware_Plugins_Frontend_NostoTagging_Components_Model_Order as NostoOrderModel; use Shopware\Models\Order\Order as OrderModel; +use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; /** * Order confirmation component. Used to send order information to Nosto. @@ -60,10 +61,14 @@ public function sendOrder(OrderModel $order) { try { $shop = Shopware()->Shop(); - } catch (\Exception $e) { + } catch (ServiceNotFoundException $e) { + $shop = $order->getShop(); // Shopware throws an exception if service does not exist. // This would be the case when using Shopware API or cli - $shop = $order->getShop(); + } catch (\Exception $e) { + /** @noinspection PhpUndefinedMethodInspection */ + Shopware()->Plugins()->Frontend()->NostoTagging()->getLogger()->error($e->getMessage()); + return; } if ($shop === null) { return; From 0281077c6dd25a5bf917964d065019193f2fd938 Mon Sep 17 00:00:00 2001 From: Cid Lopes Date: Tue, 11 Aug 2020 14:29:43 +0300 Subject: [PATCH 6/6] Add flag to only persist customer session if data has changed --- Components/Customer.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Components/Customer.php b/Components/Customer.php index 49766237..88c03e58 100644 --- a/Components/Customer.php +++ b/Components/Customer.php @@ -86,15 +86,20 @@ public static function persistSession() ->Models() ->getRepository('\Shopware\CustomModels\Nosto\Customer\Customer') ->findOneBy(array('sessionId' => $sessionId)); + $shouldPersist = false; if (empty($customer)) { $customer = new Customer(); $customer->setSessionId($sessionId); + $shouldPersist = true; } if ($nostoId !== $customer->getNostoId()) { $customer->setNostoId($nostoId); + $shouldPersist = true; + } + if ($shouldPersist) { + Shopware()->Models()->persist($customer); + Shopware()->Models()->flush($customer); } - Shopware()->Models()->persist($customer); - Shopware()->Models()->flush($customer); } }