public function testUnsubscribeCustomer()
 {
     //Creating customer and subscribe
     $customerData = $this->customerHelper->createSampleCustomer(["extension_attributes" => ["is_subscribed" => true]]);
     $this->assertNotNull($customerData['id']);
     $this->subscriber->loadByCustomerId($customerData['id']);
     $subscriptionId = $this->subscriber->getId();
     $this->assertNotNull($subscriptionId);
     $this->assertEquals($customerData['id'], $this->subscriber->getCustomerId());
     //Manage customer in order to unsubscribe
     $this->customerHelper->updateSampleCustomer(array_merge($customerData, ["extension_attributes" => ["is_subscribed" => false]]), $customerData["id"]);
     $this->initSubscriber();
     $this->subscriber->loadByCustomerId($customerData['id']);
     $this->assertEquals(Subscriber::STATUS_UNSUBSCRIBED, $this->subscriber->getStatus());
 }
예제 #2
0
파일: Data.php 프로젝트: aiesh/magento2
 /**
  * Retrieve unsubsription url
  *
  * @param \Magento\Newsletter\Model\Subscriber $subscriber
  * @return string
  */
 public function getUnsubscribeUrl($subscriber)
 {
     return $this->_urlBuilder->setScope($subscriber->getStoreId())->getUrl('newsletter/subscriber/unsubscribe', array('id' => $subscriber->getId(), 'code' => $subscriber->getCode(), '_nosid' => true));
 }
예제 #3
0
 /**
  * Updates data when subscriber received
  *
  * @param \Magento\Newsletter\Model\Subscriber $subscriber
  * @param \Magento\Newsletter\Model\Queue $queue
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function received(\Magento\Newsletter\Model\Subscriber $subscriber, \Magento\Newsletter\Model\Queue $queue)
 {
     $this->connection->beginTransaction();
     try {
         $data['letter_sent_at'] = $this->_date->gmtDate();
         $this->connection->update($this->_subscriberLinkTable, $data, ['subscriber_id = ?' => $subscriber->getId(), 'queue_id = ?' => $queue->getId()]);
         $this->connection->commit();
     } catch (\Exception $e) {
         $this->connection->rollBack();
         throw new \Magento\Framework\Exception\LocalizedException(__('We cannot mark as received subscriber.'));
     }
     return $this;
 }
예제 #4
0
 /**
  * Add Subscriber Data
  *
  * @param \Magento\Newsletter\Model\Subscriber $subscriber
  * @return $this
  */
 public function addSubscriberData(\Magento\Newsletter\Model\Subscriber $subscriber)
 {
     $this->setSubscriberId($subscriber->getId());
     return $this;
 }