Esempio n. 1
0
 /**
  * MCAPI constructor.
  * @param \Ebizmarts\MageMonkey\Helper\Data $helper
  * @param \Magento\Framework\HTTP\Adapter\Curl $curl
  */
 public function __construct(\Ebizmarts\MageMonkey\Helper\Data $helper, \Magento\Framework\HTTP\Adapter\Curl $curl)
 {
     $this->_helper = $helper;
     $this->_curl = $curl;
     $this->_apiKey = $helper->getApiKey();
     $this->_secure = false;
 }
Esempio n. 2
0
 /**
  * @param \Ebizmarts\MageMonkey\Helper\Data $helper
  */
 public function __construct(\Ebizmarts\MageMonkey\Helper\Data $helper)
 {
     $this->_helper = $helper;
     $this->_api = new \Ebizmarts\MageMonkey\Model\Api(array(), $helper);
     if ($helper->getApiKey()) {
         $this->_options = $this->_api->lists();
     }
 }
Esempio n. 3
0
 /**
  * @param \Ebizmarts\MageMonkey\Helper\Data $helper
  */
 public function __construct(\Ebizmarts\MageMonkey\Helper\Data $helper, \Ebizmarts\MageMonkey\Model\Api $api)
 {
     $this->_helper = $helper;
     $this->_api = $api;
     if ($helper->getApiKey()) {
         $this->_options = $this->_api->info();
     }
 }
Esempio n. 4
0
 /**
  * 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);
 }
Esempio n. 5
0
 public function listDeleteMember($listId, $memberId)
 {
     $this->_helper->log('Delete Member with Id: ' . $memberId);
     $response = $this->callServer('DELETE', 'lists', [0 => $listId, 'members' => $memberId]);
     $this->_helper->log($response);
     return $response;
 }
 public function beforeUnsubscribe($subscriber)
 {
     if ($subscriber->getMagemonkeyId()) {
         $this->_api->listDeleteMember($this->_helper->getDefaultList(), $subscriber->getMagemonkeyId());
         $subscriber->setMagemonkeyId('');
     }
     return null;
 }
Esempio n. 7
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];
 }
Esempio n. 8
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);
 }
Esempio n. 9
0
 public function aroundDelete(\Magento\Newsletter\Model\Subscriber $subscriber, \Closure $proceed)
 {
     $monkeyId = $subscriber->getMagemonkeyId();
     $result = $proceed();
     if ($monkeyId) {
     }
     $api = new \Ebizmarts\MageMonkey\Model\Api(array(), $this->_helper);
     $return = $api->listDeleteMember($this->_helper->getDefaultList(), $monkeyId);
     $result->setMagemonkeyId('')->save();
     return $result;
 }
Esempio n. 10
0
 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();
         }
     }
 }
Esempio n. 11
0
 /**
  * @param array $args
  * @param \Ebizmarts\MageMonkey\Helper\Data $helper
  */
 public function __construct(array $args, \Ebizmarts\MageMonkey\Helper\Data $helper)
 {
     $apiKey = !isset($args['apiKey']) ? $helper->getApiKey() : $args['apiKey'];
     $this->_mcapi = new \Ebizmarts\MageMonkey\Model\MCAPI($apiKey, $helper);
 }