/**
  * @return void
  */
 public function install()
 {
     if ($this->queryContainer->queryNewsletterType()->count() > 0) {
         return;
     }
     $this->installNewsletterTypes();
 }
예제 #2
0
 /**
  * @param \Generated\Shared\Transfer\NewsletterSubscriberTransfer $newsletterSubscriberTransfer
  *
  * @return bool
  */
 public function assignCustomerToExistingSubscriber(NewsletterSubscriberTransfer $newsletterSubscriberTransfer)
 {
     $newsletterSubscriberTransfer->requireEmail()->requireFkCustomer();
     $subscriberEntity = $this->queryContainer->querySubscriber()->findOneByEmail($newsletterSubscriberTransfer->getEmail());
     if ($subscriberEntity === null) {
         return false;
     }
     $subscriberEntity->setFkCustomer($newsletterSubscriberTransfer->getFkCustomer());
     return (bool) $subscriberEntity->save();
 }
예제 #3
0
 /**
  * @param \Generated\Shared\Transfer\NewsletterSubscriberTransfer $subscriberTransfer
  *
  * @return \Orm\Zed\Newsletter\Persistence\SpyNewsletterSubscriber|null
  */
 protected function findSubscriberEntity(NewsletterSubscriberTransfer $subscriberTransfer)
 {
     $subscriberQuery = $this->queryContainer->querySubscriber();
     $idNewsletterSubscriber = $subscriberTransfer->getIdNewsletterSubscriber();
     if ($idNewsletterSubscriber !== null) {
         return $subscriberQuery->findOneByIdNewsletterSubscriber($idNewsletterSubscriber);
     }
     $email = $subscriberTransfer->getEmail();
     if ($email !== null) {
         return $subscriberQuery->findOneByEmail($email);
     }
     return null;
 }
 /**
  * @param \Generated\Shared\Transfer\NewsletterSubscriptionRequestTransfer $newsletterSubscriptionRequest
  *
  * @throws \Exception
  *
  * @return \Generated\Shared\Transfer\NewsletterSubscriptionResponseTransfer
  */
 public function processNewsletterUnsubscriptions(NewsletterSubscriptionRequestTransfer $newsletterSubscriptionRequest)
 {
     $subscriptionResponse = $this->createSubscriptionResponse();
     $connection = $this->queryContainer->getConnection();
     $connection->beginTransaction();
     try {
         $newsletterSubscriberTransfer = $newsletterSubscriptionRequest->getNewsletterSubscriber();
         foreach ($newsletterSubscriptionRequest->getNewsletterTypes() as $newsletterTypeTransfer) {
             $isSuccess = $this->subscriptionManager->unsubscribe($newsletterSubscriberTransfer, $newsletterTypeTransfer);
             $subscriptionResult = $this->createSubscriptionResultTransfer($newsletterTypeTransfer, $isSuccess);
             $subscriptionResponse->addSubscriptionResult($subscriptionResult);
         }
         $connection->commit();
     } catch (\Exception $e) {
         $connection->rollBack();
         throw $e;
     }
     return $subscriptionResponse;
 }
예제 #5
0
 /**
  * @param \Generated\Shared\Transfer\NewsletterSubscriberTransfer $newsletterSubscriber
  * @param \Generated\Shared\Transfer\NewsletterTypeTransfer $newsletterType
  *
  * @return \Orm\Zed\Newsletter\Persistence\SpyNewsletterSubscription|null
  */
 protected function getSubscription(NewsletterSubscriberTransfer $newsletterSubscriber, NewsletterTypeTransfer $newsletterType)
 {
     if ($newsletterSubscriber->getSubscriberKey() !== null) {
         $subscriptionEntity = $this->queryContainer->querySubscriptionBySubscriberKeyAndNewsletterTypeName($newsletterSubscriber->getSubscriberKey(), $newsletterType->getName())->findOne();
         return $subscriptionEntity;
     }
     if ($newsletterSubscriber->getFkCustomer() !== null) {
         $subscriptionEntity = $this->queryContainer->querySubscriptionByIdCustomerAndNewsletterTypeName($newsletterSubscriber->getFkCustomer(), $newsletterType->getName())->findOne();
         return $subscriptionEntity;
     }
     return null;
 }