Esempio n. 1
0
 public function beforeSubscribeCustomerById($subscriber, $customerId)
 {
     $subscriber->loadByCustomerId($customerId);
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMageiaEnabled($storeId)) {
         $customer = $this->_customer->load($customerId);
         $mergeVars = $this->_helper->getMergeVars($customer);
         $api = $this->_api;
         $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
         if ($this->_helper->isDoubleOptInEnabled($storeId) && !$isSubscribeOwnEmail) {
             $status = 'pending';
         } else {
             $status = 'subscribed';
         }
         if ($mergeVars) {
             $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => $mergeVars);
         } else {
             $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status);
         }
         $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
         if (isset($return->id)) {
             $subscriber->setMageiaId($return->id);
         }
     }
     return [$customerId];
 }
Esempio n. 2
0
 public function beforeSubscribe($subscriber, $email)
 {
     $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
     if ($isSubscribeOwnEmail) {
         $subscriber->loadByEmail($email);
     }
     $storeId = $this->_storeManager->getStore()->getId();
     if ($this->_helper->isMageiaEnabled($storeId)) {
         $api = $this->_api;
         $data = ['emails' => json_encode([['email' => $email]])];
         $listId = $this->_helper->getDefaultList();
         $return = $api->listCreateMember($listId, $data);
         if (isset($return->result) && $return->result) {
             $subscriber->setMageiaId($email);
         }
     }
 }
Esempio n. 3
0
 public function testIsMonkeyEnabled()
 {
     $this->_scopeMock->expects($this->once())->method('getValue')->willReturn(1);
     $this->assertEquals($this->_helper->isMageiaEnabled(), 1);
 }