-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cross-engage requirements to glue (#4)
* feat: add cross-engage requirements to glue * improve code
- Loading branch information
1 parent
d052267
commit e947509
Showing
4 changed files
with
139 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...sletterSignup/Communication/Plugin/CheckoutRestApi/CustomerHashCheckoutQuoteMapPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace FondOfSpryker\Zed\SalesNewsletterSignup\Communication\Plugin\CheckoutRestApi; | ||
|
||
use Generated\Shared\Transfer\QuoteTransfer; | ||
use Generated\Shared\Transfer\RestCheckoutRequestAttributesTransfer; | ||
use Spryker\Zed\CheckoutRestApiExtension\Dependency\Plugin\QuoteMapperPluginInterface; | ||
use Spryker\Zed\Kernel\Communication\AbstractPlugin; | ||
|
||
/** | ||
* @method \FondOfSpryker\Zed\SalesNewsletterSignup\Communication\SalesNewsletterSignupCommunicationFactory getFactory() | ||
*/ | ||
class CustomerHashCheckoutQuoteMapPlugin extends AbstractPlugin implements QuoteMapperPluginInterface | ||
{ | ||
/** | ||
* @param \Generated\Shared\Transfer\RestCheckoutRequestAttributesTransfer $restCheckoutRequestAttributesTransfer | ||
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer | ||
* | ||
* @return \Generated\Shared\Transfer\QuoteTransfer | ||
*/ | ||
public function map(RestCheckoutRequestAttributesTransfer $restCheckoutRequestAttributesTransfer, QuoteTransfer $quoteTransfer): QuoteTransfer | ||
{ | ||
$customer = $restCheckoutRequestAttributesTransfer->getCustomer(); | ||
if ($customer && $customer->getEmail()) { | ||
$quoteTransfer->setUserHash($this->getFactory()->getNewsletterService()->getHash($customer->getEmail())); | ||
} | ||
|
||
return $quoteTransfer; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...etterSignup/Communication/Plugin/CheckoutRestApi/CustomerOptInOptOutUrlQuoteMapPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace FondOfSpryker\Zed\SalesNewsletterSignup\Communication\Plugin\CheckoutRestApi; | ||
|
||
use Generated\Shared\Transfer\QuoteTransfer; | ||
use Generated\Shared\Transfer\RestCheckoutRequestAttributesTransfer; | ||
use Spryker\Zed\CheckoutRestApiExtension\Dependency\Plugin\QuoteMapperPluginInterface; | ||
use Spryker\Zed\Kernel\Communication\AbstractPlugin; | ||
|
||
/** | ||
* @method \FondOfSpryker\Zed\SalesNewsletterSignup\Communication\SalesNewsletterSignupCommunicationFactory getFactory() | ||
*/ | ||
class CustomerOptInOptOutUrlQuoteMapPlugin extends AbstractPlugin implements QuoteMapperPluginInterface | ||
{ | ||
/** | ||
* @param \Generated\Shared\Transfer\RestCheckoutRequestAttributesTransfer $restCheckoutRequestAttributesTransfer | ||
* @param \Generated\Shared\Transfer\QuoteTransfer $quoteTransfer | ||
* | ||
* @return \Generated\Shared\Transfer\QuoteTransfer | ||
*/ | ||
public function map(RestCheckoutRequestAttributesTransfer $restCheckoutRequestAttributesTransfer, QuoteTransfer $quoteTransfer): QuoteTransfer | ||
{ | ||
$customer = $restCheckoutRequestAttributesTransfer->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; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ker/Zed/SalesNewsletterSignup/Communication/SalesNewsletterSignupCommunicationFactory.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
namespace FondOfSpryker\Zed\SalesNewsletterSignup\Communication; | ||
|
||
use FondOfSpryker\Service\Newsletter\NewsletterServiceInterface; | ||
use FondOfSpryker\Zed\SalesNewsletterSignup\SalesNewsletterSignupDependencyProvider; | ||
use Spryker\Zed\Kernel\Communication\AbstractCommunicationFactory; | ||
|
||
class SalesNewsletterSignupCommunicationFactory extends AbstractCommunicationFactory | ||
{ | ||
/** | ||
* @return \FondOfSpryker\Service\Newsletter\NewsletterServiceInterface | ||
*/ | ||
public function getNewsletterService(): NewsletterServiceInterface | ||
{ | ||
return $this->getProvidedDependency(SalesNewsletterSignupDependencyProvider::SERVICE_NEWSLETTER); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
src/FondOfSpryker/Zed/SalesNewsletterSignup/SalesNewsletterSignupDependencyProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace FondOfSpryker\Zed\SalesNewsletterSignup; | ||
|
||
use Spryker\Zed\Kernel\AbstractBundleDependencyProvider; | ||
use Spryker\Zed\Kernel\Container; | ||
|
||
class SalesNewsletterSignupDependencyProvider extends AbstractBundleDependencyProvider | ||
{ | ||
public const SERVICE_NEWSLETTER = 'SERVICE_NEWSLETTER'; | ||
public const FACADE_STORE = 'FACADE_STORE'; | ||
|
||
/** | ||
* @param \Spryker\Zed\Kernel\Container $container | ||
* | ||
* @return \Spryker\Zed\Kernel\Container | ||
*/ | ||
public function provideCommunicationLayerDependencies(Container $container) | ||
{ | ||
$container = parent::provideCommunicationLayerDependencies($container); | ||
$container = $this->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; | ||
} | ||
} |