From e947509efd0f4f9364d94e193f3ce89b7682ea73 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 7 Aug 2023 10:55:56 +0200 Subject: [PATCH] feat: add cross-engage requirements to glue (#4) * feat: add cross-engage requirements to glue * improve code --- .../CustomerHashCheckoutQuoteMapPlugin.php | 30 +++++++++++ .../CustomerOptInOptOutUrlQuoteMapPlugin.php | 38 +++++++++++++ ...esNewsletterSignupCommunicationFactory.php | 17 ++++++ ...alesNewsletterSignupDependencyProvider.php | 54 +++++++++++++++++++ 4 files changed, 139 insertions(+) create mode 100644 src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/Plugin/CheckoutRestApi/CustomerHashCheckoutQuoteMapPlugin.php create mode 100644 src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/Plugin/CheckoutRestApi/CustomerOptInOptOutUrlQuoteMapPlugin.php create mode 100644 src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/SalesNewsletterSignupCommunicationFactory.php create mode 100644 src/FondOfSpryker/Zed/SalesNewsletterSignup/SalesNewsletterSignupDependencyProvider.php diff --git a/src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/Plugin/CheckoutRestApi/CustomerHashCheckoutQuoteMapPlugin.php b/src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/Plugin/CheckoutRestApi/CustomerHashCheckoutQuoteMapPlugin.php new file mode 100644 index 0000000..5d39160 --- /dev/null +++ b/src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/Plugin/CheckoutRestApi/CustomerHashCheckoutQuoteMapPlugin.php @@ -0,0 +1,30 @@ +getCustomer(); + if ($customer && $customer->getEmail()) { + $quoteTransfer->setUserHash($this->getFactory()->getNewsletterService()->getHash($customer->getEmail())); + } + + return $quoteTransfer; + } +} diff --git a/src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/Plugin/CheckoutRestApi/CustomerOptInOptOutUrlQuoteMapPlugin.php b/src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/Plugin/CheckoutRestApi/CustomerOptInOptOutUrlQuoteMapPlugin.php new file mode 100644 index 0000000..aceac69 --- /dev/null +++ b/src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/Plugin/CheckoutRestApi/CustomerOptInOptOutUrlQuoteMapPlugin.php @@ -0,0 +1,38 @@ +getCustomer(); + if ($restCheckoutRequestAttributesTransfer->getSignupNewsletter() === true && $customer && $customer->getEmail()) { + $newsletterService = $this->getFactory()->getNewsletterService(); + $params = [ + 'language' => $newsletterService->getLanguagePrefix(), + $newsletterService->getNewsletterParamName() => $newsletterService->getNewsletterParamName(), + $newsletterService->getNewsletterTokenParamName() => $newsletterService->getHash($customer->getEmail()), + ]; + + $quoteTransfer->setOptInUrl($newsletterService->getOptInUrl($params)); + $quoteTransfer->setOptOutUrl($newsletterService->getOptOutUrl($params)); + } + + return $quoteTransfer; + } +} diff --git a/src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/SalesNewsletterSignupCommunicationFactory.php b/src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/SalesNewsletterSignupCommunicationFactory.php new file mode 100644 index 0000000..c9eb053 --- /dev/null +++ b/src/FondOfSpryker/Zed/SalesNewsletterSignup/Communication/SalesNewsletterSignupCommunicationFactory.php @@ -0,0 +1,17 @@ +getProvidedDependency(SalesNewsletterSignupDependencyProvider::SERVICE_NEWSLETTER); + } +} diff --git a/src/FondOfSpryker/Zed/SalesNewsletterSignup/SalesNewsletterSignupDependencyProvider.php b/src/FondOfSpryker/Zed/SalesNewsletterSignup/SalesNewsletterSignupDependencyProvider.php new file mode 100644 index 0000000..3e055ff --- /dev/null +++ b/src/FondOfSpryker/Zed/SalesNewsletterSignup/SalesNewsletterSignupDependencyProvider.php @@ -0,0 +1,54 @@ +addNewsletterService($container); + $container = $this->addStoreFacade($container); + + return $container; + } + + /** + * @param \Spryker\Zed\Kernel\Container $container + * + * @return \Spryker\Zed\Kernel\Container + */ + protected function addNewsletterService(Container $container) + { + $container[static::SERVICE_NEWSLETTER] = function (Container $container) { + return $container->getLocator()->newsletter()->service(); + }; + + return $container; + } + + /** + * @param \Spryker\Zed\Kernel\Container $container + * + * @return \Spryker\Zed\Kernel\Container + */ + protected function addStoreFacade(Container $container) + { + $container[static::FACADE_STORE] = function (Container $container) { + return $container->getLocator()->store()->facade(); + }; + + return $container; + } +}