Exemple #1
0
 public function beforeSubscribeCustomerById($subscriber, $customerId)
 {
     $subscriber->loadByCustomerId($customerId);
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMonkeyEnabled($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->setMagemonkeyId($return->id);
         }
     }
     return [$customerId];
 }
 /**
  * On initial module installation there are no Magento/Mailchimp mappings configured.
  * This breaks customer registration due to the following error: Invalid argument supplied for foreach()
  */
 public function testGetMergeVarsWithNoMapping()
 {
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock();
     $this->_scopeMock->expects($this->atLeastOnce())->method('getValue')->willReturn(null);
     $customerMock->expects($this->any())->method('getData')->will($this->returnCallback([$this, '_getData']));
     $this->_helper->getMergeVars($customerMock);
 }
Exemple #3
0
 public function testGetMergeVars()
 {
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Model\\Customer')->disableOriginalConstructor()->getMock();
     $this->_scopeMock->expects($this->atLeastOnce())->method('getValue')->willReturn('a:10:{s:18:"_1455130677743_743";a:2:{s:7:"magento";s:5:"fname";s:9:"mailchimp";s:5:"FNAME";}s:18:"_1455132553917_917";a:2:{s:7:"magento";s:5:"lname";s:9:"mailchimp";s:5:"LNAME";}s:18:"_1455132560288_288";a:2:{s:7:"magento";s:6:"gender";s:9:"mailchimp";s:6:"GENDER";}s:18:"_1455132567137_137";a:2:{s:7:"magento";s:3:"dob";s:9:"mailchimp";s:3:"DOB";}s:18:"_1455132573944_944";a:2:{s:7:"magento";s:15:"billing_address";s:9:"mailchimp";s:7:"BILLING";}s:18:"_1455132594111_111";a:2:{s:7:"magento";s:16:"shipping_address";s:9:"mailchimp";s:8:"SHIPPING";}s:17:"_1455132602049_49";a:2:{s:7:"magento";s:9:"telephone";s:9:"mailchimp";s:9:"TELEPHONE";}s:18:"_1455132614663_663";a:2:{s:7:"magento";s:7:"company";s:9:"mailchimp";s:7:"COMPANY";}s:18:"_1455132622855_855";a:2:{s:7:"magento";s:8:"group_id";s:9:"mailchimp";s:6:"CGROUP";}s:18:"_1455132622855_877";a:2:{s:7:"magento";s:10:"middlename";s:9:"mailchimp";s:5:"MNAME";}}');
     $customerMock->expects($this->any())->method('getData')->will($this->returnCallback([$this, '_getData']));
     $billingMock = $this->getMockBuilder('Magento\\Customer\\Model\\Customer\\Address')->disableOriginalConstructor()->setMethods(array('getTelephone', 'getStreetLine', 'getCompany', 'getCity', 'getRegion', 'getPostCode', 'getCountryId'))->getMock();
     $billingMock->expects($this->any())->method('getTelephone')->willReturn('555 1234');
     $billingMock->expects($this->any())->method('getCompany')->willReturn('ebizmarts');
     $billingMock->expects($this->any())->method('getStreetLine')->willReturn('here');
     $billingMock->expects($this->any())->method('getCity')->willReturn('los angeles');
     $billingMock->expects($this->any())->method('getRegion')->willReturn('ca');
     $billingMock->expects($this->any())->method('getPostCode')->willReturn('90210');
     $billingMock->expects($this->any())->method('getCountryId')->willReturn('1');
     $customerMock->expects($this->any())->method('getDefaultBillingAddress')->willReturn($billingMock);
     $customerMock->expects($this->any())->method('getDefaultShippingAddress')->willReturn($billingMock);
     $ret = $this->_helper->getMergeVars($customerMock);
     $ret = $this->_helper->getMergeVars($customerMock);
 }
 public function afterSubscribeCustomerById($subscriber)
 {
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMonkeyEnabled($storeId)) {
         $customer = $this->_customer;
         $mergeVars = $this->_helper->getMergeVars($customer);
         $api = new \Ebizmarts\MageMonkey\Model\Api(array(), $this->_helper);
         $isSubscribeOwnEmail = $this->_customerSession->isLoggedIn() && $this->_customerSession->getCustomerDataObject()->getEmail() == $subscriber->getSubscriberEmail();
         if ($this->_helper->isDoubleOptInEnabled($storeId) && !$isSubscribeOwnEmail) {
             $status = 'pending';
         } else {
             $status = 'subscribed';
         }
         $data = array('list_id' => $this->_helper->getDefaultList(), 'email_address' => $subscriber->getEmail(), 'email_type' => 'html', 'status' => $status);
         $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
         if (isset($return->id)) {
             $subscriber->setMagemonkeyId($return->id)->save();
         }
     }
 }
 public function beforeSubscribeCustomerById($subscriber, $customerId)
 {
     $subscriber->loadByCustomerId($customerId);
     $subscriber->setImportMode(true);
     $storeId = $subscriber->getStoreId();
     if ($this->_helper->isMonkeyEnabled($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 = ['list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => $mergeVars];
         } else {
             $data = ['list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => ['EMAIL' => $customer->getEmail()]];
         }
         try {
             $emailHash = md5(strtolower($customer->getEmail()));
             $return = $api->getMember($this->_helper->getDefaultList(), $emailHash);
             if (!isset($return->id)) {
                 $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
                 if (isset($return->id)) {
                     $subscriber->setMagemonkeyId($return->id)->save();
                 }
             }
             $subscriber->setMagemonkeyId($emailHash)->save();
         } catch (\Exception $e) {
             $this->_helper->log($e->getMessage());
         }
     }
     return [$customerId];
 }