From ef158142cdff2f6ea0d8a7bf9fdae90e7d12b2f8 Mon Sep 17 00:00:00 2001
From: Santiago
Date: Tue, 20 Feb 2018 14:51:51 -0300
Subject: [PATCH 001/113] Add interest groups. (IN PROGRESS)
---
.../MailChimp/Block/Checkout/Subscribe.php | 5 +-
.../Block/Checkout/Success/Groups.php | 233 ++++++++++++++++++
.../Block/Customer/Newsletter/Index.php | 209 ++++++++++++++++
.../Ebizmarts/MailChimp/Helper/Data.php | 136 +++++++++-
.../Ebizmarts/MailChimp/Model/Api/Batches.php | 2 +-
.../MailChimp/Model/Api/Subscribers.php | 20 +-
.../Ebizmarts/MailChimp/Model/Config.php | 51 ++--
.../MailChimp/Model/Interestgroup.php | 32 +++
.../MailChimp/Model/Mysql4/Interestgroup.php | 42 ++++
.../Model/Mysql4/Interestgroup/Collection.php | 27 ++
.../Ebizmarts/MailChimp/Model/Observer.php | 46 +++-
.../System/Config/Source/CustomerGroup.php | 43 ++++
.../MailChimp/controllers/GroupController.php | 60 +++++
.../Ebizmarts/MailChimp/etc/config.xml | 24 +-
.../Ebizmarts/MailChimp/etc/system.xml | 54 +++-
.../mysql4-upgrade-1.1.11-1.1.12.php | 18 ++
.../default/layout/ebizmarts/mailchimp.xml | 22 +-
.../mailchimp/checkout/subscribe.phtml | 11 +-
.../mailchimp/checkout/success/groups.phtml | 83 +++++++
.../mailchimp/customer/newsletter/index.phtml | 68 +++++
20 files changed, 1109 insertions(+), 77 deletions(-)
create mode 100644 app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
create mode 100644 app/code/community/Ebizmarts/MailChimp/Block/Customer/Newsletter/Index.php
create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Interestgroup.php
create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/Mysql4/Interestgroup.php
create mode 100755 app/code/community/Ebizmarts/MailChimp/Model/Mysql4/Interestgroup/Collection.php
create mode 100644 app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/CustomerGroup.php
create mode 100644 app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php
create mode 100755 app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.11-1.1.12.php
create mode 100644 app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/groups.phtml
create mode 100644 app/design/frontend/base/default/template/ebizmarts/mailchimp/customer/newsletter/index.phtml
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Subscribe.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Subscribe.php
index 96e519d1f..e3fc73cde 100644
--- a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Subscribe.php
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Subscribe.php
@@ -17,6 +17,9 @@ class Ebizmarts_MailChimp_Block_Checkout_Subscribe extends Mage_Core_Block_Templ
protected $_generalList = array();
protected $_form;
protected $_api;
+ /**
+ * @var Ebizmarts_MailChimp_Helper_Data
+ */
protected $helper;
protected $storeId;
@@ -116,8 +119,6 @@ public function getGeneralList()
$helper = $this->helper;
$listId = $helper->getGeneralList($storeId);
- //@Todo add support for intetest groups
-
return $listId;
}
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
new file mode 100644
index 000000000..55951054a
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
@@ -0,0 +1,233 @@
+
+ * @license http://opensource.org/licenses/osl-3.0.php
+ */
+class Ebizmarts_MailChimp_Block_Checkout_Success_Groups extends Mage_Core_Block_Template
+{
+
+ protected $_lists = array();
+ protected $_info = array();
+ protected $_myLists = array();
+ protected $_generalList = array();
+ protected $_form;
+ protected $_api;
+ /**
+ * @var Ebizmarts_MailChimp_Helper_Data
+ */
+ protected $helper;
+ protected $storeId;
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->helper = Mage::helper('mailchimp');
+ $this->storeId = Mage::app()->getStore()->getId();
+ }
+
+ /**
+ * Get list data from MC
+ *
+ * @return array
+ */
+ public function getGeneralList()
+ {
+ $storeId = $this->storeId;
+ $helper = $this->helper;
+ $listId = $helper->getGeneralList($storeId);
+
+ return $listId;
+ }
+
+ public function getListInterestGroups()
+ {
+ $storeId = $this->storeId;
+ $helper = $this->helper;
+ $return = $helper->getListInterestGroups($storeId);
+ return $return;
+ }
+
+ public function getCategoryTitle($category)
+ {
+ return $category['title'];
+ }
+
+ public function renderGroups($category)
+ {
+ $object = $this->createObject($category);
+
+ $this->addGroupOptions($category, $object);
+
+ $html = $this->getElementHtml($category, $object);
+
+ return $html;
+ }
+
+ public function getGroupClass($type)
+ {
+ switch ($type) {
+ case 'radio':
+ $class = 'Varien_Data_Form_Element_Radios';
+ break;
+ case 'checkboxes':
+ $class = 'Varien_Data_Form_Element_Checkboxes';
+ break;
+ case 'dropdown':
+ $class = 'Varien_Data_Form_Element_Select';
+ break;
+ default:
+ $class = 'Varien_Data_Form_Element_Text';
+ break;
+ }
+
+ return $class;
+ }
+
+ public function htmlGroupName($category)
+ {
+ $storeId = $this->storeId;
+ $helper = $this->helper;
+ $listId = $helper->getGeneralList($storeId);
+ $htmlName = "list[{$listId}]";
+ $htmlName .= "[{$category['id']}]";
+
+ if ($category['type'] == 'checkboxes') {
+ $htmlName .= '[]';
+ }
+
+ return $htmlName;
+ }
+
+ /**
+ * Form getter/instantiation
+ *
+ * @return Varien_Data_Form
+ */
+ public function getForm()
+ {
+ if ($this->_form instanceof Varien_Data_Form) {
+ return $this->_form;
+ }
+ $form = new Varien_Data_Form();
+ return $form;
+ }
+
+ /**
+ * @param $category
+ * @param $object
+ */
+ protected function addGroupOptions($category, $object)
+ {
+ $type = $category['type'];
+
+ if ($type == 'checkboxes' || $type == 'dropdown') {
+ $options = $this->createOptionArray($category);
+
+ if (isset($category['groups'])) {
+ foreach ($category['groups'] as $key => $group) {
+ $options[$key] = $group;
+ }
+
+ $object->setValues($options);
+ }
+ }
+ }
+
+ /**
+ * @param $category
+ * @return mixed
+ */
+ protected function createOptionArray($category)
+ {
+ $options = array();
+ $type = $category['type'];
+
+ if ($type == 'dropdown') {
+ $options[''] = '-- Select Group --';
+ }
+ return $options;
+ }
+
+ /**
+ * @param $category
+ * @param $html
+ * @return string
+ */
+ protected function addGroupContainer($category, $html)
+ {
+ $type = $category['type'];
+ if ($type != 'checkboxes') {
+ $html = "{$html}
";
+ }
+ return $html;
+ }
+
+ /**
+ * @param $category
+ * @return mixed
+ */
+ protected function createObject($category)
+ {
+ $type = $category['type'];
+ $class = $this->getGroupClass($type);
+ $object = new $class;
+ $object->setForm($this->getForm());
+ $object->setName($this->htmlGroupName($category));
+ $object->setHtmlId('interest-group');
+
+ return $object;
+ }
+
+ /**
+ * @param $category
+ * @param $object
+ * @return string
+ */
+ protected function getElementHtml($category, $object)
+ {
+ $html = $object->getElementHtml();
+ $html = $this->addGroupContainer($category, $html);
+
+ return $html;
+ }
+
+ public function getFormUrl()
+ {
+ return $this->getSuccessInterestUrl();
+ }
+
+ public function getSuccessInterestUrl()
+ {
+ $url = 'mailchimp/group/index';
+ return Mage::app()->getStore()->getUrl($url);
+ }
+
+ public function getInterest()
+ {
+ $subscriber = Mage::getModel('newsletter/subscriber');
+ $order = Mage::getSingleton('checkout/session')->getLastRealOrder();
+ $subscriber->loadByEmail($order->getCustomerEmail());
+ $interest = $this->helper->getSubscriberInterest($subscriber->getSubscriberId(),$subscriber->getStoreId());
+ Mage::log(__METHOD__, null, 'ebizmarts.log', true);
+ Mage::log($interest, null, 'ebizmarts.log', true);
+ return $interest;
+ }
+
+ public function getMessageBefore()
+ {
+ $storeId = $this->storeId;
+ return $this->helper->getCheckoutSuccessHtmlBefore($storeId);
+ }
+
+ public function getMessageAfter()
+ {
+ $storeId = $this->storeId;
+ return $this->helper->getCheckoutSuccessHtmlAfter($storeId);
+ }
+
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Customer/Newsletter/Index.php b/app/code/community/Ebizmarts/MailChimp/Block/Customer/Newsletter/Index.php
new file mode 100644
index 000000000..d9efdb41b
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Customer/Newsletter/Index.php
@@ -0,0 +1,209 @@
+
+ * @license http://opensource.org/licenses/osl-3.0.php
+ */
+class Ebizmarts_MailChimp_Block_Customer_Newsletter_Index extends Mage_Customer_Block_Newsletter
+{
+
+ protected $_lists = array();
+ protected $_info = array();
+ protected $_myLists = array();
+ protected $_generalList = array();
+ protected $_form;
+ protected $_api;
+ protected $_template = "ebizmarts/mailchimp/customer/newsletter/index.phtml";
+ /**
+ * @var Ebizmarts_MailChimp_Helper_Data
+ */
+ protected $helper;
+ protected $storeId;
+
+ public function __construct()
+ {
+// parent::__construct();
+ $this->setTemplate('ebizmarts/mailchimp/customer/newsletter/index.phtml');
+ $this->helper = Mage::helper('mailchimp');
+ $this->storeId = Mage::app()->getStore()->getId();
+ }
+
+ public function getInterest()
+ {
+ $subscriber = Mage::getModel('newsletter/subscriber');
+ $order = Mage::getSingleton('checkout/session')->getLastRealOrder();
+ $subscriber->loadByEmail($order->getCustomerEmail());
+ $interest = $this->helper->getSubscriberInterest($subscriber->getSubscriberId(),$subscriber->getStoreId());
+ return $interest;
+ }
+
+// /**
+// * Get list data from MC
+// *
+// * @return array
+// */
+// public function getGeneralList()
+// {
+// $storeId = $this->storeId;
+// $helper = $this->helper;
+// $listId = $helper->getGeneralList($storeId);
+//
+// return $listId;
+// }
+//
+// public function getListInterestGroups()
+// {
+// $storeId = $this->storeId;
+// $helper = $this->helper;
+// $return = $helper->getListInterestGroups($storeId);
+// return $return;
+// }
+//
+// public function getCategoryTitle($category)
+// {
+// return $category['title'];
+// }
+//
+// public function renderGroups($category)
+// {
+// $object = $this->createObject($category);
+//
+// $this->addGroupOptions($category, $object);
+//
+// $html = $this->getElementHtml($category, $object);
+//
+// return $html;
+// }
+//
+// public function getGroupClass($type)
+// {
+// switch ($type) {
+// case 'radio':
+// $class = 'Varien_Data_Form_Element_Radios';
+// break;
+// case 'checkboxes':
+// $class = 'Varien_Data_Form_Element_Checkboxes';
+// break;
+// case 'dropdown':
+// $class = 'Varien_Data_Form_Element_Select';
+// break;
+// default:
+// $class = 'Varien_Data_Form_Element_Text';
+// break;
+// }
+//
+// return $class;
+// }
+//
+// public function htmlGroupName($category)
+// {
+// $storeId = $this->storeId;
+// $helper = $this->helper;
+// $listId = $helper->getGeneralList($storeId);
+// $htmlName = "list[{$listId}]";
+// $htmlName .= "[{$category['id']}]";
+//
+// if ($category['type'] == 'checkboxes') {
+// $htmlName .= '[]';
+// }
+//
+// return $htmlName;
+// }
+//
+// /**
+// * Form getter/instantiation
+// *
+// * @return Varien_Data_Form
+// */
+// public function getForm()
+// {
+// if ($this->_form instanceof Varien_Data_Form) {
+// return $this->_form;
+// }
+// $form = new Varien_Data_Form();
+// return $form;
+// }
+//
+// /**
+// * @param $category
+// * @param $object
+// */
+// protected function addGroupOptions($category, $object)
+// {
+// $type = $category['type'];
+//
+// if ($type == 'checkboxes' || $type == 'dropdown') {
+// $options = $this->createOptionArray($category);
+//
+// if (isset($category['groups'])) {
+// foreach ($category['groups'] as $group) {
+// $options[$group] = $group;
+// }
+//
+// $object->setValues($options);
+// }
+// }
+// }
+//
+// /**
+// * @param $category
+// * @return mixed
+// */
+// protected function createOptionArray($category)
+// {
+// $options = array();
+// $type = $category['type'];
+//
+// if ($type == 'dropdown') {
+// $options[''] = '-- Select Group --';
+// }
+// return $options;
+// }
+//
+// /**
+// * @param $category
+// * @param $html
+// * @return string
+// */
+// protected function addGroupContainer($category, $html)
+// {
+// $type = $category['type'];
+// if ($type != 'checkboxes') {
+// $html = "{$html}
";
+// }
+// return $html;
+// }
+//
+// /**
+// * @param $category
+// * @return mixed
+// */
+// protected function createObject($category)
+// {
+// $type = $category['type'];
+// $class = $this->getGroupClass($type);
+// $object = new $class;
+// $object->setForm($this->getForm());
+// $object->setName($this->htmlGroupName($category));
+// $object->setHtmlId('interest-group');
+//
+// return $object;
+// }
+//
+// /**
+// * @param $category
+// * @param $object
+// * @return string
+// */
+// protected function getElementHtml($category, $object)
+// {
+// $html = $object->getElementHtml();
+// $html = $this->addGroupContainer($category, $html);
+//
+// return $html;
+// }
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
index 19e9ac95f..4c0b1c97a 100755
--- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
+++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
@@ -396,12 +396,12 @@ public function isEmailCatcherEnabled($scopeId = 0, $scope = null)
public function getDateSyncFinishByStoreId($scopeId = 0, $scope = null)
{
$mailchimpStoreId = $this->getMCStoreId($scopeId, $scope);
- return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_SYNC_DATE."_$mailchimpStoreId", 0, 'default');
+ return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_SYNC_DATE . "_$mailchimpStoreId", 0, 'default');
}
public function getDateSyncFinishByMailChimpStoreId($mailchimpStoreId)
{
- return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_SYNC_DATE."_$mailchimpStoreId", 0, 'default');
+ return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_SYNC_DATE . "_$mailchimpStoreId", 0, 'default');
}
/**
@@ -1148,11 +1148,6 @@ protected function setCurrentStore($magentoStoreId)
$this->getMageApp()->setCurrentStore($magentoStoreId);
}
- private function getProductImageModel()
- {
- return Mage::getModel('catalog/product_image');
- }
-
/**
* If orders with the given email exists, returns the date of the last order made.
*
@@ -2430,12 +2425,12 @@ public function getAllMailChimpStoreIds()
->addFieldToFilter('path', array('eq' => Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID));
$mailchimpStoreIdsArray = array();
foreach ($collection as $row) {
- $scopeData = $row->getScope().'_'.$row->getScopeId();
+ $scopeData = $row->getScope() . '_' . $row->getScopeId();
$mailchimpStoreIdsArray[$scopeData] = $row->getValue();
}
return $mailchimpStoreIdsArray;
}
-
+
public function subscribeMember($subscriber, $forceUpdateStatus = false)
{
$subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
@@ -2574,4 +2569,127 @@ public function getApiByMailChimpStoreId($mailchimpStoreId)
$scopeArray = $this->getScopeByMailChimpStoreId($mailchimpStoreId);
return $this->getApi($scopeArray['scope_id'], $scopeArray['scope']);
}
+
+ public function getListInterestCategories($scopeId, $scope = 'stores')
+ {
+ $interestGroupsArray = array();
+ $api = $this->getApi($scopeId, $scope);
+ $listId = $this->getGeneralList($scopeId, $scope);
+ try {
+ $interestCategories = $api->lists->interestCategory->getAll($listId, 'categories');
+ foreach ($interestCategories['categories'] as $interestCategory) {
+ $interestGroupsArray[] = array(
+ 'id' => $interestCategory['id'],
+ 'title' => $interestCategory['title'],
+ 'type' => $interestCategory['type']
+ );
+ }
+ } catch (Exception $e) {
+ $this->logError($e->getMessage());
+ }
+ return $interestGroupsArray;
+ }
+
+ public function getListInterestGroups($scopeId, $scope = 'stores')
+ {
+ $interestGroupsArray = array();
+ $api = $this->getApi($scopeId, $scope);
+ $listId = $this->getGeneralList($scopeId, $scope);
+ try {
+ $interestCategories = $api->lists->interestCategory->getAll($listId, 'categories');
+ foreach ($interestCategories['categories'] as $interestCategory) {
+ $interestGroups = $api->lists->interestCategory->interests->getAll($listId, $interestCategory['id']);
+ $groups = array();
+ foreach ($interestGroups['interests'] as $interestGroup) {
+ $groups[$interestGroup['id']] = $interestGroup['name'];
+ }
+ $interestGroupsArray[] = array(
+ 'id' => $interestCategory['id'],
+ 'title' => $interestCategory['title'],
+ 'type' => $interestCategory['type'],
+ 'groups' => $groups
+ );
+ }
+ } catch (Exception $e) {
+ $this->logError($e->getMessage());
+ }
+ return $interestGroupsArray;
+ }
+
+ public function getLocalInterestCategories($scopeId, $scope = 'stores')
+ {
+ return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_INTEREST_CATEGORIES, $scopeId, $scope);
+ }
+
+ public function getCheckoutSuccessHtmlBefore($scopeId, $scope = 'stores')
+ {
+ return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_INTEREST_SUCCESS_BEFORE, $scopeId, $scope);
+ }
+
+ public function getCheckoutSuccessHtmlAfter($scopeId, $scope = 'stores')
+ {
+ return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_INTEREST_SUCCESS_AFTER, $scopeId, $scope);
+ }
+
+ public function getInterest($storeId)
+ {
+ $rc = [];
+ $interest = $this->getLocalInterestCategories($storeId);
+ if ($interest != '') {
+ $interest = explode(",", $interest);
+ } else {
+ $interest = [];
+ }
+ $api = $this->getApi($storeId);
+ $listId = $this->getGeneralList($storeId);
+ $allInterest = $api->lists->interestCategory->getAll($listId);
+ foreach ($allInterest['categories'] as $item) {
+ if (in_array($item['id'], $interest)) {
+ $rc[$item['id']]['interest'] = ['id' => $item['id'], 'title' => $item['title'], 'type' => $item['type']];
+ }
+ }
+ foreach ($interest as $interestId) {
+ $mailchimpInterest = $api->lists->interestCategory->interests->getAll($listId, $interestId);
+ foreach ($mailchimpInterest['interests'] as $mi) {
+ $rc[$mi['category_id']]['category'][$mi['display_order']] = ['id' => $mi['id'], 'name' => $mi['name'], 'checked' => false];
+ }
+ }
+ return $rc;
+ }
+
+ public function getSubscriberInterest($subscriberId, $storeId, $interest = null)
+ {
+ if (!$interest) {
+ $interest = $this->getInterest($storeId);
+ }
+ $interestGroup = Mage::getModel('mailchimp/interestgroup');
+ $interestGroup->getBySubscriberIdStoreId($subscriberId, $storeId);
+ $groups = unserialize($interestGroup->getGroupdata());
+ if (isset($groups['group'])) {
+ foreach ($groups['group'] as $key => $value) {
+ if (isset($interest[$key])) {
+ if (is_array($value)) {
+ foreach ($value as $groupId) {
+ foreach ($interest[$key]['category'] as $gkey => $gvalue) {
+ if ($gvalue['id'] == $groupId) {
+ $interest[$key]['category'][$gkey]['checked'] = true;
+ } elseif (!isset($interest[$key]['category'][$gkey]['checked'])) {
+ $interest[$key]['category'][$gkey]['checked'] = false;
+ }
+ }
+ }
+ } else {
+ foreach ($interest[$key]['category'] as $gkey => $gvalue) {
+ if ($gvalue['id'] == $value) {
+ $interest[$key]['category'][$gkey]['checked'] = true;
+ } else {
+ $interest[$key]['category'][$gkey]['checked'] = false;
+ }
+ }
+ }
+ }
+ }
+ }
+ return $interest;
+ }
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php
index 7e948a7b2..9b8834877 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php
@@ -515,7 +515,7 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId)
$errorDetails = $response->detail;
}
- if (strstr($errorDetails, 'already exists in the account')) {
+ if (strstr($errorDetails, 'already exists')) {
$this->saveSyncData($id, $type, $mailchimpStoreId, null, null, 1, null, null, true);
continue;
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php
index 2ebe3e037..4fd4c6d61 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php
@@ -441,23 +441,6 @@ protected function statusEqualsUnconfirmed($status)
return $status == Mage_Newsletter_Model_Subscriber::STATUS_UNCONFIRMED;
}
- public function removeSubscriber($subscriber)
- {
- $helper = $this->mcHelper;
- $storeId = $subscriber->getStoreId();
- $listId = $helper->getGeneralList($storeId);
- $api = $helper->getApi($storeId);
- try {
- $md5HashEmail = md5(strtolower($subscriber->getSubscriberEmail()));
- $api->lists->members->update($listId, $md5HashEmail, null, 'unsubscribed');
- } catch (MailChimp_Error $e) {
- $helper->logError($e->getFriendlyMessage(), $storeId);
- Mage::getSingleton('adminhtml/session')->addError($e->getFriendlyMessage());
- } catch (Exception $e) {
- $helper->logError($e->getMessage(), $storeId);
- }
- }
-
/**
* @param $subscriber
*/
@@ -480,9 +463,8 @@ public function deleteSubscriber($subscriber)
public function update($emailAddress, $storeId)
{
- $helper = $this->mcHelper;
$subscriber = Mage::getSingleton('newsletter/subscriber')->loadByEmail($emailAddress);
- if ($subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED && $subscriber->getMailchimpSyncDelta() != $helper->getSubMinSyncDateFlag($storeId)) {
+ if ($subscriber->getId()) {
$subscriber->setMailchimpSyncModified(1)
->save();
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Config.php b/app/code/community/Ebizmarts/MailChimp/Model/Config.php
index b62bf58ad..d205d2efc 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Config.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Config.php
@@ -11,30 +11,33 @@
*/
class Ebizmarts_MailChimp_Model_Config
{
- const GENERAL_ACTIVE = 'mailchimp/general/active';
- const GENERAL_APIKEY = 'mailchimp/general/apikey';
- const GENERAL_OAUTH_WIZARD = 'mailchimp/general/oauth_wizard';
- const GENERAL_ACCOUNT_DETAILS = 'mailchimp/general/account_details';
- const GENERAL_LIST = 'mailchimp/general/list';
- const GENERAL_OLD_LIST = 'mailchimp/general/old_list';
- const GENERAL_LIST_CHANGED_SCOPES = 'mailchimp/general/list_changed_scopes';
- const GENERAL_CHECKOUT_SUBSCRIBE = 'mailchimp/general/checkout_subscribe';
- const GENERAL_MCSTOREID = 'mailchimp/general/storeid';
- const GENERAL_MCISSYNCING = 'mailchimp/general/is_syicing';
- const GENERAL_ECOMMMINSYNCDATEFLAG = 'mailchimp/general/mcminsyncdateflag';
- const GENERAL_SUBMINSYNCDATEFLAG = 'mailchimp/general/subminsyncdateflag';
- const GENERAL_MCSTORE_RESETED = 'mailchimp/general/mcstore_reset';
- const GENERAL_TWO_WAY_SYNC = 'mailchimp/general/webhook_active';
- const GENERAL_UNSUBSCRIBE = 'mailchimp/general/webhook_delete';
- const GENERAL_WEBHOOK_ID = 'mailchimp/general/webhook_id';
- const GENERAL_LOG = 'mailchimp/general/enable_log';
- const GENERAL_MAP_FIELDS = 'mailchimp/general/map_fields';
- const GENERAL_CUSTOM_MAP_FIELDS = 'mailchimp/general/customer_map_fields';
- const GENERAL_MIGRATE_FROM_115 = 'mailchimp/general/migrate_from_115';
- const GENERAL_MIGRATE_FROM_116 = 'mailchimp/general/migrate_from_116';
- const GENERAL_MIGRATE_FROM_1164 = 'mailchimp/general/migrate_from_1164';
- const GENERAL_MIGRATE_LAST_ORDER_ID = 'mailchimp/general/migrate_last_order_id';
- const GENERAL_SUBSCRIBER_AMOUNT = 'mailchimp/general/subscriber_batch_amount';
+ const GENERAL_ACTIVE = 'mailchimp/general/active';
+ const GENERAL_APIKEY = 'mailchimp/general/apikey';
+ const GENERAL_OAUTH_WIZARD = 'mailchimp/general/oauth_wizard';
+ const GENERAL_ACCOUNT_DETAILS = 'mailchimp/general/account_details';
+ const GENERAL_LIST = 'mailchimp/general/list';
+ const GENERAL_OLD_LIST = 'mailchimp/general/old_list';
+ const GENERAL_LIST_CHANGED_SCOPES = 'mailchimp/general/list_changed_scopes';
+ const GENERAL_CHECKOUT_SUBSCRIBE = 'mailchimp/general/checkout_subscribe';
+ const GENERAL_MCSTOREID = 'mailchimp/general/storeid';
+ const GENERAL_MCISSYNCING = 'mailchimp/general/is_syicing';
+ const GENERAL_ECOMMMINSYNCDATEFLAG = 'mailchimp/general/mcminsyncdateflag';
+ const GENERAL_SUBMINSYNCDATEFLAG = 'mailchimp/general/subminsyncdateflag';
+ const GENERAL_MCSTORE_RESETED = 'mailchimp/general/mcstore_reset';
+ const GENERAL_TWO_WAY_SYNC = 'mailchimp/general/webhook_active';
+ const GENERAL_UNSUBSCRIBE = 'mailchimp/general/webhook_delete';
+ const GENERAL_WEBHOOK_ID = 'mailchimp/general/webhook_id';
+ const GENERAL_LOG = 'mailchimp/general/enable_log';
+ const GENERAL_MAP_FIELDS = 'mailchimp/general/map_fields';
+ const GENERAL_CUSTOM_MAP_FIELDS = 'mailchimp/general/customer_map_fields';
+ const GENERAL_MIGRATE_FROM_115 = 'mailchimp/general/migrate_from_115';
+ const GENERAL_MIGRATE_FROM_116 = 'mailchimp/general/migrate_from_116';
+ const GENERAL_MIGRATE_FROM_1164 = 'mailchimp/general/migrate_from_1164';
+ const GENERAL_MIGRATE_LAST_ORDER_ID = 'mailchimp/general/migrate_last_order_id';
+ const GENERAL_SUBSCRIBER_AMOUNT = 'mailchimp/general/subscriber_batch_amount';
+ const GENERAL_INTEREST_CATEGORIES = 'mailchimp/general/interest_categories';
+ const GENERAL_INTEREST_SUCCESS_BEFORE = 'mailchimp/general/interest_success_before';
+ const GENERAL_INTEREST_SUCCESS_AFTER = 'mailchimp/general/interest_success_after';
const ECOMMERCE_ACTIVE = 'mailchimp/ecommerce/active';
const ECOMMERCE_CUSTOMERS_OPTIN = 'mailchimp/ecommerce/customers_optin';
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Interestgroup.php b/app/code/community/Ebizmarts/MailChimp/Model/Interestgroup.php
new file mode 100644
index 000000000..d683988b4
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Interestgroup.php
@@ -0,0 +1,32 @@
+
+ * @copyright Ebizmarts (http://ebizmarts.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @date: 5/16/16 6:23 PM
+ * @file: Interestgroup.php
+ */
+
+class Ebizmarts_MailChimp_Model_Interestgroup extends Mage_Core_Model_Abstract
+{
+ /**
+ * Initialize model
+ *
+ * @return void
+ */
+ public function _construct()
+ {
+ parent::_construct();
+ $this->_init('mailchimp/interestgroup');
+ }
+
+ public function getBySubscriberIdStoreId($subscriberId, $storeId)
+ {
+ $this->addData($this->getResource()->getBySubscriberIdStoreId($subscriberId, $storeId));
+ return $this;
+ }
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Mysql4/Interestgroup.php b/app/code/community/Ebizmarts/MailChimp/Model/Mysql4/Interestgroup.php
new file mode 100644
index 000000000..301d50126
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Mysql4/Interestgroup.php
@@ -0,0 +1,42 @@
+
+ * @copyright Ebizmarts (http://ebizmarts.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @date: 6/9/16 4:46 PM
+ * @file: Interestgroup.php
+ */
+class Ebizmarts_MailChimp_Model_Mysql4_Interestgroup extends Mage_Core_Model_Mysql4_Abstract
+{
+
+ /**
+ * Initialize
+ *
+ * @return void
+ */
+ public function _construct()
+ {
+ $this->_init('mailchimp/interestgroup', 'id');
+ }
+
+ public function getBySubscriberIdStoreId($subscriberId, $storeId)
+ {
+ $read = $this->_getReadAdapter();
+ $select = $read->select()
+ ->from($this->getMainTable())
+ ->where('subscriber_id = ?', $subscriberId)
+ ->where('store_id = ?', $storeId);
+
+ $result = $read->fetchRow($select);
+
+ if (!$result) {
+ return array();
+ }
+
+ return $result;
+ }
+}
\ No newline at end of file
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Mysql4/Interestgroup/Collection.php b/app/code/community/Ebizmarts/MailChimp/Model/Mysql4/Interestgroup/Collection.php
new file mode 100755
index 000000000..a008428dd
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Mysql4/Interestgroup/Collection.php
@@ -0,0 +1,27 @@
+
+ * @copyright Ebizmarts (http://ebizmarts.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @date: 5/16/16 6:53 PM
+ * @file: Collection.php
+ */
+
+class Ebizmarts_MailChimp_Model_Mysql4_Interestgroup_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
+{
+
+ /**
+ * Set resource type
+ *
+ * @return void
+ */
+ public function _construct()
+ {
+ parent::_construct();
+ $this->_init('mailchimp/interestgroup');
+ }
+}
\ No newline at end of file
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
index 15959d465..629aba029 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
@@ -41,6 +41,7 @@ public function saveConfig(Varien_Event_Observer $observer)
public function handleSubscriber(Varien_Event_Observer $observer)
{
$subscriber = $observer->getEvent()->getSubscriber();
+
if ($subscriber->getSubscriberSource() != Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE) {
$isEnabled = $this->makeHelper()->isMailChimpEnabled($subscriber->getStoreId());
if ($isEnabled) {
@@ -66,6 +67,26 @@ public function handleSubscriber(Varien_Event_Observer $observer)
}
}
+ public function subscriberSaveAfter(Varien_Event_Observer $observer)
+ {
+ Mage::log(__METHOD__, null, 'ebizmarts.log', true);
+ $params = Mage::app()->getRequest()->getParams();
+ $subscriber = $observer->getEvent()->getSubscriber();
+ $storeId = $subscriber->getStoreId();
+
+ if (isset($params['group'])) {
+ Mage::log('groups', null, 'ebizmarts.log', true);
+ Mage::log('subscriber id ' . $subscriber->getSubscriberId(), null, 'ebizmarts.log', true);
+ $interestGroup = Mage::getModel('mailchimp/interestgroup');
+ $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(), $storeId);
+ $interestGroup->setGroupdata(serialize($params));
+ $interestGroup->setSubscriberId($subscriber->getSubscriberId());
+ $interestGroup->setStoreId($storeId);
+ $interestGroup->setUpdatedAt(Mage::getModel('core/date')->date('d-m-Y H:i:s'));
+ $interestGroup->save();
+ }
+ }
+
/**
* Handle subscriber deletion from back end.
*
@@ -257,16 +278,17 @@ protected function _getLandingCookie()
*/
public function addColumnToSalesOrderGrid($observer)
{
+ $helper = $this->makeHelper();
$scopeArray = explode('-', $this->makeHelper()->getScopeString());
$block = $observer->getEvent()->getBlock();
if ($block instanceof Mage_Adminhtml_Block_Sales_Order_Grid
- && $this->makeHelper()->getMonkeyInGrid($scopeArray[1], $scopeArray[0])
- && ($this->makeHelper()->isAbandonedCartEnabled($scopeArray[1], $scopeArray[0])
- || $this->makeHelper()->isMailChimpEnabled($scopeArray[1], $scopeArray[0]))
+ && $helper->getMonkeyInGrid($scopeArray[1], $scopeArray[0])
+ && ($helper->isAbandonedCartEnabled($scopeArray[1], $scopeArray[0])
+ || $helper->isMailChimpEnabled($scopeArray[1], $scopeArray[0]))
) {
$block->addColumnAfter(
'mailchimp_flag', array(
- 'header' => $this->makeHelper()->__('MailChimp'),
+ 'header' => $helper->__('MailChimp'),
'index' => 'mailchimp_flag',
'align' => 'center',
'filter' => false,
@@ -596,6 +618,7 @@ protected function getPromoRulesApi()
public function cleanProductImagesCacheAfter(Varien_Event_Observer $observer)
{
+ Mage::log(__METHOD__, null, 'ebizmarts2.log', true);
$configValues = array(array(Ebizmarts_MailChimp_Model_Config::PRODUCT_IMAGE_CACHE_FLUSH, 1));
$this->makeHelper()->saveMailchimpConfig($configValues, 0, 'default');
}
@@ -640,4 +663,19 @@ protected function getConfig()
$config = Mage::getConfig();
return $config;
}
+
+ public function addTabToCustomer(Varien_Event_Observer $observer)
+ {
+ $block = $observer->getEvent()->getBlock();
+ if ($block->getType() == 'adminhtml/customer_edit_tabs') {
+
+ Mage::log($block->getType(), null, 'ebizmarts.log', true);
+ $block->addTab('custom_tab', array(
+ 'label' => Mage::helper('mailchimp')->__('MailChimp'),
+ 'title' => Mage::helper('mailchimp')->__('MailChimp'),
+ 'url' => $block->getUrl('mailchimp/adminhtml_custom/index', array('_current' => true)),
+ 'class' => 'ajax',));
+ }
+
+ }
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/CustomerGroup.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/CustomerGroup.php
new file mode 100644
index 000000000..3c78d026f
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/CustomerGroup.php
@@ -0,0 +1,43 @@
+
+ * Date : 8/29/14
+ * Time : 3:36 PM
+ * File : CustomerGroup.php
+ * Module : magemonkey
+ */
+class Ebizmarts_MailChimp_Model_System_Config_Source_CustomerGroup
+{
+ protected $_categories = null;
+
+ /**
+ * Load lists and store on class property
+ */
+ public function __construct()
+ {
+ $helper = Mage::helper('mailchimp');
+ $scopeArray = explode('-', Mage::helper('mailchimp')->getScopeString());
+ $this->_categories = $helper->getListInterestCategories($scopeArray[1], $scopeArray[0]);
+ }
+
+ /**
+ * Options getter
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ $groups = array();
+ $helper = Mage::helper('mailchimp');
+ if (is_array($this->_categories)) {
+ foreach ($this->_categories as $category) {
+ $groups[] = array('value'=> $category['id'], 'label' => $category['title']);
+ }
+ } else {
+ $groups []= array('value' => '', 'label' => $helper->__('--- No data ---'));
+ }
+ return $groups;
+ }
+
+}
\ No newline at end of file
diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php b/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php
new file mode 100644
index 000000000..f63c394a1
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php
@@ -0,0 +1,60 @@
+
+ * @copyright Ebizmarts (http://ebizmarts.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @date: 7/6/16 10:14 AM
+ * @file: GroupController.php
+ */
+
+
+class Ebizmarts_MailChimp_GroupController extends Mage_Core_Controller_Front_Action
+{
+ public function indexAction()
+ {
+ $order = Mage::getSingleton('checkout/session')->getLastRealOrder();
+ $session = Mage::getSingleton('core/session');
+ $helper = $this->getHelper();
+ $params = $this->getRequest()->getParams();
+ $storeId = $order->getStoreId();
+ $interestGroup = Mage::getModel('mailchimp/interestgroup');
+ $subscriber = Mage::getModel('newsletter/subscriber')
+ ->loadByEmail($order->getCustomerEmail());
+ try {
+ if ($subscriber->getSubscriberEmail() == $order->getCustomerEmail()) {
+ $this->getApiSubscriber()->update($subscriber->getSubscriberEmail(), $storeId, '', 1);
+ } else {
+ $subscriber->setSubscriberEmail($order->getCustomerEmail());
+ $subscriber->setSubscriberFirstname($order->getCustomerFirstname());
+ $subscriber->setSubscriberLastname($order->getCustomerLastname());
+ $subscriber->subscribe($order->getCustomerEmail());
+ }
+ $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(),$storeId);
+ $interestGroup->setGroupdata(serialize($params));
+ $interestGroup->setSubscriberId($subscriber->getSubscriberId());
+ $interestGroup->setStoreId($storeId);
+ $interestGroup->setUpdatedAt(Mage::getModel('core/date')->date('d-m-Y H:i:s'));
+ $interestGroup->save();
+
+ $session->addSuccess($this->__('Thanks for share your interest with us.'));
+ } catch (Exception $e) {
+ $helper->logError($e->getMessage());
+ $session->addWarning($this->__('Something went wrong with the interests subscription. Please go to the account subscription menu to subscriber to the interests successfully.'));
+ }
+ $this->_redirect('/');
+ }
+
+ protected function getHelper()
+ {
+ return Mage::helper('mailchimp');
+ }
+
+ protected function getApiSubscriber()
+ {
+ return Mage::getModel('mailchimp/api_subscribers');
+ }
+}
\ No newline at end of file
diff --git a/app/code/community/Ebizmarts/MailChimp/etc/config.xml b/app/code/community/Ebizmarts/MailChimp/etc/config.xml
index 54e21fcbe..ec16e39c1 100755
--- a/app/code/community/Ebizmarts/MailChimp/etc/config.xml
+++ b/app/code/community/Ebizmarts/MailChimp/etc/config.xml
@@ -3,10 +3,10 @@
- 1.1.10
+ 1.1.11
- 1.1.10
+ 1.1.11
@@ -27,6 +27,14 @@
+
+
+
+ mailchimp/observer
+ SubscriberSaveAfter
+
+
+
@@ -170,6 +178,9 @@
mailchimp_ecommerce_sync_data
+
+
+
@@ -301,6 +312,15 @@
+
+
+
+ model
+ mailchimp/observer
+ addTabToCustomer
+
+
+
diff --git a/app/code/community/Ebizmarts/MailChimp/etc/system.xml b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
index 6572470b4..473f8da59 100755
--- a/app/code/community/Ebizmarts/MailChimp/etc/system.xml
+++ b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
@@ -85,7 +85,7 @@
button
mailchimp/adminhtml_system_config_resetErrors
- 45
+ 42
1
1
1
@@ -95,7 +95,7 @@
select
mailchimp/system_config_source_list
mailchimp/system_config_backend_list
- 50
+ 44
1
1
1
@@ -106,12 +106,58 @@
button
mailchimp/adminhtml_system_config_resetList
- 52
+ 46
1
1
1
+
+ Interest Categories
+ multiselect
+ mailchimp/system_config_source_customerGroup
+ 48
+ 1
+ 1
+ 1
+ 1
+
+
+
+ Interest groups in checkout success
+ select
+ adminhtml/system_config_source_yesno
+ 49
+ 1
+ 1
+ 1
+
+
+ Add html code before the interest groups are displayed
+ textarea
+ 50
+ 1
+ 1
+ 1
+ 1
+
+
+ 1
+
+
+
+ Add html code after the interest groups are displayed
+ textarea
+ 51
+ 1
+ 1
+ 1
+ 1
+
+
+ 1
+
+
Subscriber amount to be sent per run
select
@@ -225,7 +271,7 @@
1
-
+
Select product image size to send
select
mailchimp/system_config_source_imageSize
diff --git a/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.11-1.1.12.php b/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.11-1.1.12.php
new file mode 100755
index 000000000..491729d7c
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.11-1.1.12.php
@@ -0,0 +1,18 @@
+run(
+ "
+ CREATE TABLE IF NOT EXISTS `{$this->getTable('mailchimp_interest_group')}` (
+ `id` INT(10) unsigned NOT NULL auto_increment,
+ `subscriber_id` INT(10) DEFAULT 0,
+ `store_id` SMALLINT (5) NOT NULL,
+ `updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP,
+ `groupdata` TEXT(4096) NOT NULL,
+ PRIMARY KEY (`id`)
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+"
+);
+
+$installer->endSetup();
\ No newline at end of file
diff --git a/app/design/frontend/base/default/layout/ebizmarts/mailchimp.xml b/app/design/frontend/base/default/layout/ebizmarts/mailchimp.xml
index 8ea478abc..98f4c2c12 100755
--- a/app/design/frontend/base/default/layout/ebizmarts/mailchimp.xml
+++ b/app/design/frontend/base/default/layout/ebizmarts/mailchimp.xml
@@ -29,16 +29,34 @@
+ template="ebizmarts/mailchimp/popup/emailcatcher.phtml"/>
+
+
+
+
+
+
+
+
+
-
+
+
+
+
+
+
diff --git a/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/subscribe.phtml b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/subscribe.phtml
index 7a8d73b00..444a173be 100644
--- a/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/subscribe.phtml
+++ b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/subscribe.phtml
@@ -31,19 +31,11 @@ $generalList = $this->getGeneralList();
value: subscribeValue + element.readAttribute('value'),
type: "hidden"
});
-// var listValue = new Element('input', {
-// name: element.readAttribute('name'),
-// id: "subscribe-" + element.readAttribute('value'),
-// value: element.readAttribute('value'),
-// type: "hidden"
-// });
try {
Element.insert(Form.findFirstElement(payment.form), inputer);
-// Element.insert(Form.findFirstElement(payment.form), listValue);
} catch (notelem) {
$("co-payment-form").insert(inputer);
-// $("co-payment-form").insert(listValue);
}
} else {
var arrCheckedLists = checkedLists.split(',');
@@ -85,8 +77,7 @@ $generalList = $this->getGeneralList();
value=""
title=""
class="mailchimp-list-subscriber"/>
- __('General Subscription'); ?>
+ __('General Subscription'); ?>
diff --git a/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/groups.phtml b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/groups.phtml
new file mode 100644
index 000000000..935a5e532
--- /dev/null
+++ b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/groups.phtml
@@ -0,0 +1,83 @@
+getInterest();
+?>
+
+ getMessageBefore() ?>
+
+getMessageAfter() ?>
+
+
\ No newline at end of file
diff --git a/app/design/frontend/base/default/template/ebizmarts/mailchimp/customer/newsletter/index.phtml b/app/design/frontend/base/default/template/ebizmarts/mailchimp/customer/newsletter/index.phtml
new file mode 100644
index 000000000..19db2efff
--- /dev/null
+++ b/app/design/frontend/base/default/template/ebizmarts/mailchimp/customer/newsletter/index.phtml
@@ -0,0 +1,68 @@
+getInterest();
+?>
+
+
+
+
+
+
From a97dd2c452d2d830eb652b1d85e29999b08c849f Mon Sep 17 00:00:00 2001
From: Santiago
Date: Tue, 20 Feb 2018 15:28:01 -0300
Subject: [PATCH 002/113] Updated merge data.
---
.../Ebizmarts/MailChimp/Helper/Data.php | 6 +-----
.../Model/System/Config/Source/CustomerGroup.php | 16 ++++++++++++----
.../community/Ebizmarts/MailChimp/etc/config.xml | 4 ++--
3 files changed, 15 insertions(+), 11 deletions(-)
diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
index 38eb3fbcd..ad34a73e5 100755
--- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
+++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
@@ -1397,11 +1397,6 @@ public function getCoreResource()
return Mage::getSingleton('core/resource');
}
- private function getProductImageModel()
- {
- return Mage::getModel('catalog/product_image');
- }
-
/**
* If orders with the given email exists, returns the date of the last order made.
*
@@ -2967,4 +2962,5 @@ public function isNewApiKeyForSameAccount($oldApiKey, $newApiKey)
}
return $isNewApiKeyForSameAccount;
}
+
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/CustomerGroup.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/CustomerGroup.php
index 3c78d026f..25ca7aa53 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/CustomerGroup.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/CustomerGroup.php
@@ -16,9 +16,9 @@ class Ebizmarts_MailChimp_Model_System_Config_Source_CustomerGroup
*/
public function __construct()
{
- $helper = Mage::helper('mailchimp');
- $scopeArray = explode('-', Mage::helper('mailchimp')->getScopeString());
- $this->_categories = $helper->getListInterestCategories($scopeArray[1], $scopeArray[0]);
+ $helper = $this->makeHelper();
+ $scopeArray = $helper->getCurrentScope();
+ $this->_categories = $helper->getListInterestCategories($scopeArray['scope_id'], $scopeArray['scope']);
}
/**
@@ -29,7 +29,7 @@ public function __construct()
public function toOptionArray()
{
$groups = array();
- $helper = Mage::helper('mailchimp');
+ $helper = $this->makeHelper();
if (is_array($this->_categories)) {
foreach ($this->_categories as $category) {
$groups[] = array('value'=> $category['id'], 'label' => $category['title']);
@@ -40,4 +40,12 @@ public function toOptionArray()
return $groups;
}
+ /**
+ * @return Ebizmarts_MailChimp_Helper_Data
+ */
+ protected function makeHelper()
+ {
+ return Mage::helper('mailchimp');
+ }
+
}
\ No newline at end of file
diff --git a/app/code/community/Ebizmarts/MailChimp/etc/config.xml b/app/code/community/Ebizmarts/MailChimp/etc/config.xml
index d4b5378f4..b81d755b6 100755
--- a/app/code/community/Ebizmarts/MailChimp/etc/config.xml
+++ b/app/code/community/Ebizmarts/MailChimp/etc/config.xml
@@ -3,10 +3,10 @@
- 1.1.11
+ 1.1.12
- 1.1.11
+ 1.1.12
From 2af25311299c626714c7274a1e2f376e16e6bae5 Mon Sep 17 00:00:00 2001
From: Santiago
Date: Thu, 1 Mar 2018 15:03:13 -0300
Subject: [PATCH 003/113] Updated merge data.
---
.../Ebizmarts/MailChimp/Helper/Data.php | 117 ++++++++++++++++++
1 file changed, 117 insertions(+)
diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
index ad34a73e5..2ae2cfbce 100755
--- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
+++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
@@ -2963,4 +2963,121 @@ public function isNewApiKeyForSameAccount($oldApiKey, $newApiKey)
return $isNewApiKeyForSameAccount;
}
+ public function getListInterestCategories($scopeId, $scope = 'stores')
+ {
+ $interestGroupsArray = array();
+ $api = $this->getApi($scopeId, $scope);
+ $listId = $this->getGeneralList($scopeId, $scope);
+ try {
+ $interestCategories = $api->lists->interestCategory->getAll($listId, 'categories');
+ foreach ($interestCategories['categories'] as $interestCategory) {
+ $interestGroupsArray[] = array(
+ 'id' => $interestCategory['id'],
+ 'title' => $interestCategory['title'],
+ 'type' => $interestCategory['type']
+ );
+ }
+ } catch (Exception $e) {
+ $this->logError($e->getMessage());
+ }
+ return $interestGroupsArray;
+ }
+
+ public function getListInterestGroups($scopeId, $scope = 'stores')
+ {
+ $interestGroupsArray = array();
+ $api = $this->getApi($scopeId, $scope);
+ $listId = $this->getGeneralList($scopeId, $scope);
+ try {
+ $interestCategories = $api->lists->interestCategory->getAll($listId, 'categories');
+ foreach ($interestCategories['categories'] as $interestCategory) {
+ $interestGroups = $api->lists->interestCategory->interests->getAll($listId, $interestCategory['id']);
+ $groups = array();
+ foreach ($interestGroups['interests'] as $interestGroup) {
+ $groups[$interestGroup['id']] = $interestGroup['name'];
+ }
+ $interestGroupsArray[] = array(
+ 'id' => $interestCategory['id'],
+ 'title' => $interestCategory['title'],
+ 'type' => $interestCategory['type'],
+ 'groups' => $groups
+ );
+ }
+ } catch (Exception $e) {
+ $this->logError($e->getMessage());
+ }
+ return $interestGroupsArray;
+ }
+ public function getLocalInterestCategories($scopeId, $scope = 'stores')
+ {
+ return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_INTEREST_CATEGORIES, $scopeId, $scope);
+ }
+ public function getCheckoutSuccessHtmlBefore($scopeId, $scope = 'stores')
+ {
+ return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_INTEREST_SUCCESS_BEFORE, $scopeId, $scope);
+ }
+ public function getCheckoutSuccessHtmlAfter($scopeId, $scope = 'stores')
+ {
+ return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_INTEREST_SUCCESS_AFTER, $scopeId, $scope);
+ }
+ public function getInterest($storeId)
+ {
+ $rc = [];
+ $interest = $this->getLocalInterestCategories($storeId);
+ if ($interest != '') {
+ $interest = explode(",", $interest);
+ } else {
+ $interest = [];
+ }
+ $api = $this->getApi($storeId);
+ $listId = $this->getGeneralList($storeId);
+ $allInterest = $api->lists->interestCategory->getAll($listId);
+ foreach ($allInterest['categories'] as $item) {
+ if (in_array($item['id'], $interest)) {
+ $rc[$item['id']]['interest'] = ['id' => $item['id'], 'title' => $item['title'], 'type' => $item['type']];
+ }
+ }
+ foreach ($interest as $interestId) {
+ $mailchimpInterest = $api->lists->interestCategory->interests->getAll($listId, $interestId);
+ foreach ($mailchimpInterest['interests'] as $mi) {
+ $rc[$mi['category_id']]['category'][$mi['display_order']] = ['id' => $mi['id'], 'name' => $mi['name'], 'checked' => false];
+ }
+ }
+ return $rc;
+ }
+ public function getSubscriberInterest($subscriberId, $storeId, $interest = null)
+ {
+ if (!$interest) {
+ $interest = $this->getInterest($storeId);
+ }
+ $interestGroup = Mage::getModel('mailchimp/interestgroup');
+ $interestGroup->getBySubscriberIdStoreId($subscriberId, $storeId);
+ $groups = unserialize($interestGroup->getGroupdata());
+ if (isset($groups['group'])) {
+ foreach ($groups['group'] as $key => $value) {
+ if (isset($interest[$key])) {
+ if (is_array($value)) {
+ foreach ($value as $groupId) {
+ foreach ($interest[$key]['category'] as $gkey => $gvalue) {
+ if ($gvalue['id'] == $groupId) {
+ $interest[$key]['category'][$gkey]['checked'] = true;
+ } elseif (!isset($interest[$key]['category'][$gkey]['checked'])) {
+ $interest[$key]['category'][$gkey]['checked'] = false;
+ }
+ }
+ }
+ } else {
+ foreach ($interest[$key]['category'] as $gkey => $gvalue) {
+ if ($gvalue['id'] == $value) {
+ $interest[$key]['category'][$gkey]['checked'] = true;
+ } else {
+ $interest[$key]['category'][$gkey]['checked'] = false;
+ }
+ }
+ }
+ }
+ }
+ }
+ return $interest;
+ }
}
From 7dc6181e130905ccb8910aff0f241e16dee7601f Mon Sep 17 00:00:00 2001
From: Santiago
Date: Wed, 4 Apr 2018 15:51:37 -0300
Subject: [PATCH 004/113] Added MailChimp tab in customer edit view in admin
panel.
---
.../Adminhtml/Customer/Edit/Tab/Mailchimp.php | 20 +++++
.../Block/Checkout/Success/Groups.php | 2 -
.../Ebizmarts/MailChimp/Model/Observer.php | 41 +++++++++-
.../Model/System/Config/Source/Account.php | 2 +-
.../Adminhtml/MailchimpController.php | 9 ++
.../Ebizmarts/MailChimp/etc/config.xml | 10 +--
.../mailchimp/customer/tab/mailchimp.phtml | 82 +++++++++++++++++++
7 files changed, 154 insertions(+), 12 deletions(-)
create mode 100644 app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Customer/Edit/Tab/Mailchimp.php
create mode 100644 app/design/adminhtml/default/default/template/ebizmarts/mailchimp/customer/tab/mailchimp.phtml
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Customer/Edit/Tab/Mailchimp.php b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Customer/Edit/Tab/Mailchimp.php
new file mode 100644
index 000000000..930893e60
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Customer/Edit/Tab/Mailchimp.php
@@ -0,0 +1,20 @@
+
+ * @copyright Ebizmarts (http://ebizmarts.com)
+ * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
+ * @date: 6/10/16 12:38 AM
+ * @file: Grid.php
+ */
+class Ebizmarts_MailChimp_Block_Adminhtml_Customer_Edit_Tab_Mailchimp extends Mage_Adminhtml_Block_Widget_Grid
+{
+ public function __construct()
+ {
+ parent::__construct();
+ $this->setTemplate('mailchimp/customer/tab/mailchimp.phtml');
+ }
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
index 55951054a..257a2bde1 100644
--- a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
@@ -213,8 +213,6 @@ public function getInterest()
$order = Mage::getSingleton('checkout/session')->getLastRealOrder();
$subscriber->loadByEmail($order->getCustomerEmail());
$interest = $this->helper->getSubscriberInterest($subscriber->getSubscriberId(),$subscriber->getStoreId());
- Mage::log(__METHOD__, null, 'ebizmarts.log', true);
- Mage::log($interest, null, 'ebizmarts.log', true);
return $interest;
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
index a05535d5b..98fdf9af0 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
@@ -110,7 +110,7 @@ protected function getCustomerModel()
*/
public function saveConfig(Varien_Event_Observer $observer)
{
- $post = Mage::app()->getRequest()->getPost();
+ $post = $this->getRequest()->getPost();
$helper = $this->makeHelper();
$scopeArray = $helper->getCurrentScope();
@@ -133,9 +133,22 @@ public function saveConfig(Varien_Event_Observer $observer)
public function handleSubscriber(Varien_Event_Observer $observer)
{
$subscriber = $observer->getEvent()->getSubscriber();
+ $storeId = $subscriber->getStoreId();
+ $groups = $this->getRequest()->getParam('group');
$helper = $this->makeHelper();
+ try {
+ $interestGroup = Mage::getModel('mailchimp/interestgroup');
+ $interestGroup->getBySubscriberIdStoreId($subscriber->getSubscriberId(),$storeId);
+ $interestGroup->setGroupdata(serialize($groups));
+ $interestGroup->setSubscriberId($subscriber->getSubscriberId());
+ $interestGroup->setStoreId($storeId);
+ $interestGroup->setUpdatedAt(Mage::getModel('core/date')->date('d-m-Y H:i:s'));
+ $interestGroup->save();
+ } catch (Exception $e) {
+ $helper->logError($e->getMessage());
+ }
if ($subscriber->getSubscriberSource() != Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE) {
- $isEnabled = $helper->isSubscriptionEnabled($subscriber->getStoreId());
+ $isEnabled = $helper->isSubscriptionEnabled($storeId);
if ($isEnabled) {
$apiSubscriber = $this->makeApiSubscriber();
$subscriber->setImportMode(true);
@@ -531,7 +544,7 @@ public function loadCustomerToQuote(Varien_Event_Observer $observer)
if (!Mage::getSingleton('customer/session')->isLoggedIn()
&& $isEcomEnabled && $isAbandonedCartEnabled
) {
- $action = Mage::app()->getRequest()->getActionName();
+ $action = $this->getRequest()->getActionName();
$onCheckout = ($action == 'saveOrder' || $action == 'savePayment' ||
$action == 'saveShippingMethod' || $action == 'saveBilling');
if (Mage::getModel('core/cookie')->get('email')
@@ -798,7 +811,7 @@ public function salesruleDeleteAfter(Varien_Event_Observer $observer)
public function secondaryCouponsDelete(Varien_Event_Observer $observer)
{
$promoCodesApi = $this->makeApiPromoCode();
- $params = Mage::app()->getRequest()->getParams();
+ $params = $this->getRequest()->getParams();
if (isset($params['ids']) && isset($params['id'])) {
$promoRuleId = $params['id'];
$promoCodeIds = $params['ids'];
@@ -886,4 +899,24 @@ protected function removeRegistry()
{
return Mage::unregister('sort_column_dir');
}
+
+ public function addCustomerTab(Varien_Event_Observer $observer)
+ {
+// Mage::log(__METHOD__, null, 'ebizmarts.log', true);
+ $block = $observer->getEvent()->getBlock();
+ // add tab in customer edit page
+ if ($block instanceof Mage_Adminhtml_Block_Customer_Edit_Tabs) {
+ Mage::log('is instance', null, 'ebizmarts.log', true);
+ if ($this->getRequest()->getActionName() == 'edit' || $this->getRequest()->getParam('type')) {
+ Mage::log('add tab', null, 'ebizmarts.log', true);
+ $block->addTab('mailchimp', array('label' => Mage::helper('customer')->__('MailChimp'), 'url' => $block->getUrl('adminhtml/mailchimp/index', array('_current' => true)), 'class' => 'ajax'));
+ }
+ }
+ return $observer;
+ }
+
+ protected function getRequest()
+ {
+ return Mage::app()->getRequest();
+ }
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php
index d7518d520..6c5950d3d 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php
@@ -75,7 +75,7 @@ public function __construct()
$helper->deleteLocalMCStoreData($mcStoreId, $scopeArray['scope_id'], $scopeArray['scope']);
if ($listId) {
$helper->createStore($listId, $scopeArray['scope_id'], $scopeArray['scope']);
- $message = $helper->__('Looks like your MailChimp store was deleted. A new one has been created.');
+ $message = $helper->__('Looks like your MailChimp store was deleted, a new one has been created. Refresh the page to see it.');
Mage::getSingleton('adminhtml/session')->addWarning($message);
}
}
diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php
index 561314797..3cd153252 100644
--- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php
+++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php
@@ -12,6 +12,15 @@
*/
class Ebizmarts_MailChimp_Adminhtml_MailchimpController extends Mage_Adminhtml_Controller_Action
{
+ public function indexAction()
+ {
+ $this->getResponse()->setBody(
+ $this->getLayout()->createBlock('mailchimp/adminhtml_customer_edit_tab_mailchimp','admin.customer.mailchimp')->setCustomerId(Mage::registry('current_customer')->getId())
+ ->setUseAjax(true)
+ ->toHtml()
+ );
+ }
+
public function resendSubscribersAction()
{
$helper = $this->makeHelper();
diff --git a/app/code/community/Ebizmarts/MailChimp/etc/config.xml b/app/code/community/Ebizmarts/MailChimp/etc/config.xml
index 115c247ba..3e7c59bbe 100755
--- a/app/code/community/Ebizmarts/MailChimp/etc/config.xml
+++ b/app/code/community/Ebizmarts/MailChimp/etc/config.xml
@@ -304,15 +304,15 @@
-
+
-
+
model
mailchimp/observer
- addTabToCustomer
-
+ addCustomerTab
+
-
+
diff --git a/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/customer/tab/mailchimp.phtml b/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/customer/tab/mailchimp.phtml
new file mode 100644
index 000000000..d2946e8c4
--- /dev/null
+++ b/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/customer/tab/mailchimp.phtml
@@ -0,0 +1,82 @@
+getInterest();
+?>
+
+ getMessageBefore() ?>
+
+getMessageAfter() ?>
+
+
\ No newline at end of file
From a90e09612b3c285665aa7666d98f2467feb03baa Mon Sep 17 00:00:00 2001
From: Santiago
Date: Mon, 9 Apr 2018 16:41:06 -0300
Subject: [PATCH 005/113] Added new tab at Customer edit view in the back end.
---
.../Adminhtml/Customer/Edit/Tab/Mailchimp.php | 30 +++-
.../Adminhtml/MailchimpController.php | 14 +-
.../mailchimp/customer/tab/mailchimp.phtml | 144 +++++++++---------
3 files changed, 107 insertions(+), 81 deletions(-)
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Customer/Edit/Tab/Mailchimp.php b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Customer/Edit/Tab/Mailchimp.php
index 930893e60..22ed980cb 100644
--- a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Customer/Edit/Tab/Mailchimp.php
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/Customer/Edit/Tab/Mailchimp.php
@@ -12,9 +12,37 @@
*/
class Ebizmarts_MailChimp_Block_Adminhtml_Customer_Edit_Tab_Mailchimp extends Mage_Adminhtml_Block_Widget_Grid
{
+
+ protected $_lists = array();
+ protected $_info = array();
+ protected $_myLists = array();
+ protected $_generalList = array();
+ protected $_form;
+ protected $_api;
+ protected $_customer;
+ /**
+ * @var Ebizmarts_MailChimp_Helper_Data
+ */
+ protected $helper;
+ protected $storeId;
+
public function __construct()
{
parent::__construct();
- $this->setTemplate('mailchimp/customer/tab/mailchimp.phtml');
+ $this->setTemplate('ebizmarts/mailchimp/customer/tab/mailchimp.phtml');
+ $this->helper = Mage::helper('mailchimp');
+ $customerId = (int) $this->getRequest()->getParam('id');
+ if ($customerId) {
+ $this->_customer = Mage::getModel('customer/customer')->load($customerId);
+ $this->storeId = $this->_customer->getStoreId();
+ }
+ }
+
+ public function getInterest()
+ {
+ $subscriber = Mage::getModel('newsletter/subscriber');
+ $subscriber->loadByEmail($this->_customer->getEmail());
+ $interest = $this->helper->getSubscriberInterest($subscriber->getSubscriberId(), $this->storeId);
+ return $interest;
}
}
diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php
index 3cd153252..f7b00f9a1 100644
--- a/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php
+++ b/app/code/community/Ebizmarts/MailChimp/controllers/Adminhtml/MailchimpController.php
@@ -14,11 +14,14 @@ class Ebizmarts_MailChimp_Adminhtml_MailchimpController extends Mage_Adminhtml_C
{
public function indexAction()
{
- $this->getResponse()->setBody(
- $this->getLayout()->createBlock('mailchimp/adminhtml_customer_edit_tab_mailchimp','admin.customer.mailchimp')->setCustomerId(Mage::registry('current_customer')->getId())
- ->setUseAjax(true)
- ->toHtml()
- );
+ $customerId = (int) $this->getRequest()->getParam('id');
+ if ($customerId) {
+ $this->getResponse()->setBody(
+ $this->getLayout()->createBlock('mailchimp/adminhtml_customer_edit_tab_mailchimp', 'admin.customer.mailchimp')->setCustomerId($customerId)
+ ->setUseAjax(true)
+ ->toHtml()
+ );
+ }
}
public function resendSubscribersAction()
@@ -42,6 +45,7 @@ public function resendSubscribersAction()
protected function _isAllowed()
{
switch ($this->getRequest()->getActionName()) {
+ case 'index':
case 'resendSubscribers':
$acl = 'system/config/mailchimp';
break;
diff --git a/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/customer/tab/mailchimp.phtml b/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/customer/tab/mailchimp.phtml
index d2946e8c4..5507a99a7 100644
--- a/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/customer/tab/mailchimp.phtml
+++ b/app/design/adminhtml/default/default/template/ebizmarts/mailchimp/customer/tab/mailchimp.phtml
@@ -1,82 +1,76 @@
getInterest();
+$interest = $this->getInterest();
?>
-
- getMessageBefore() ?>
-
getMessageAfter() ?>
-
\ No newline at end of file
+
From 3f24e7e10920a745b7b996105ef001a62bc03e2b Mon Sep 17 00:00:00 2001
From: Santiago
Date: Tue, 31 Jul 2018 11:44:45 -0300
Subject: [PATCH 016/113] Add tests.
---
.../Block/Checkout/Success/Groups.php | 41 ++-
.../Block/Customer/Newsletter/Index.php | 23 +-
.../Ebizmarts/MailChimp/Helper/Data.php | 50 +++-
...php => mysql4-upgrade-1.1.12.3-1.1.13.php} | 0
.../Block/Checkout/Success/GroupsTest.php | 101 +++++++
.../Block/Customer/Newsletter/IndexTest.php | 92 ++++++
.../Ebizmarts/MailChimp/Helper/DataTest.php | 265 +++++++++++++++++-
lib/Ebizmarts/MailChimp.php | 8 +
lib/Ebizmarts/MailChimp/Lists.php | 8 +
.../MailChimp/ListsInterestCategory.php | 8 +
10 files changed, 574 insertions(+), 22 deletions(-)
rename app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/{mysql4-upgrade-1.1.12.2-1.1.13.php => mysql4-upgrade-1.1.12.3-1.1.13.php} (100%)
create mode 100644 dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Checkout/Success/GroupsTest.php
create mode 100644 dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Customer/Newsletter/IndexTest.php
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
index fc86af530..2e5d9dda1 100644
--- a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
@@ -38,7 +38,7 @@ public function __construct()
public function getGeneralList()
{
$storeId = $this->storeId;
- $helper = $this->helper;
+ $helper = $this->getMailChimpHelper();
$listId = $helper->getGeneralList($storeId);
return $listId;
@@ -47,7 +47,7 @@ public function getGeneralList()
public function getListInterestGroups()
{
$storeId = $this->storeId;
- $helper = $this->helper;
+ $helper = $this->getMailChimpHelper();
$return = $helper->getListInterestGroups($storeId);
return $return;
}
@@ -91,7 +91,7 @@ public function getGroupClass($type)
public function htmlGroupName($category)
{
$storeId = $this->storeId;
- $helper = $this->helper;
+ $helper = $this->getMailChimpHelper();
$listId = $helper->getGeneralList($storeId);
$htmlName = "list[{$listId}]";
$htmlName .= "[{$category['id']}]";
@@ -209,26 +209,51 @@ public function getSuccessInterestUrl()
public function getInterest()
{
- $subscriber = Mage::getModel('newsletter/subscriber');
- $order = Mage::getSingleton('checkout/session')->getLastRealOrder();
+ $subscriber = $this->getSubscriberModel();
+ $order = $this->getSessionLastRealOrder();
$subscriber->loadByEmail($order->getCustomerEmail());
$subscriberId = $subscriber->getSubscriberId();
$customerId = $order->getCustomerId();
- $interest = $this->helper->getInterestGroups($customerId, $subscriberId,$order->getStoreId());
+ $helper = $this->getMailChimpHelper();
+ $interest = $helper->getInterestGroups($customerId, $subscriberId,$order->getStoreId());
return $interest;
}
public function getMessageBefore()
{
$storeId = $this->storeId;
- return $this->helper->getCheckoutSuccessHtmlBefore($storeId);
+ return $this->getMailChimpHelper()->getCheckoutSuccessHtmlBefore($storeId);
}
public function getMessageAfter()
{
$storeId = $this->storeId;
- return $this->helper->getCheckoutSuccessHtmlAfter($storeId);
+ return $this->getMailChimpHelper()->getCheckoutSuccessHtmlAfter($storeId);
+ }
+
+ /**
+ * @return false|Mage_Core_Model_Abstract
+ */
+ protected function getSubscriberModel()
+ {
+ return Mage::getModel('newsletter/subscriber');
+ }
+
+ /**
+ * @return mixed
+ */
+ protected function getSessionLastRealOrder()
+ {
+ return Mage::getSingleton('checkout/session')->getLastRealOrder();
+ }
+
+ /**
+ * @return Ebizmarts_MailChimp_Helper_Data|Mage_Core_Helper_Abstract
+ */
+ protected function getMailChimpHelper()
+ {
+ return $this->helper;
}
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Customer/Newsletter/Index.php b/app/code/community/Ebizmarts/MailChimp/Block/Customer/Newsletter/Index.php
index 8ffa7ab80..163a4714a 100644
--- a/app/code/community/Ebizmarts/MailChimp/Block/Customer/Newsletter/Index.php
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Customer/Newsletter/Index.php
@@ -33,11 +33,12 @@ public function __construct()
public function getInterest()
{
- $subscriber = Mage::getModel('newsletter/subscriber');
+ $subscriber = $this->getSubscriberModel();
$subscriber->loadByEmail($this->_getEmail());
$helper = $this->getMailChimpHelper();
- if (!$helper->isAdmin() && Mage::getSingleton('customer/session')->isLoggedIn()) {
- $customer = Mage::getSingleton('customer/session')->getCustomer();
+ $customerSession = $this->getCustomerSession();
+ if (!$helper->isAdmin() && $customerSession->isLoggedIn()) {
+ $customer = $customerSession->getCustomer();
$customerId = $customer->getId();
$storeId = ($subscriber->getStoreId()) ? $subscriber->getStoreId() : $customer->getStoreId();
} else {
@@ -66,4 +67,20 @@ protected function getMailChimpHelper()
return $this->helper;
}
+ /**
+ * @return Mage_Customer_Model_Session
+ */
+ protected function getCustomerSession()
+ {
+ return Mage::getSingleton('customer/session');
+ }
+
+ /**
+ * @return Mage_Newsletter_Model_Subscriber
+ */
+ protected function getSubscriberModel()
+ {
+ return Mage::getModel('newsletter/subscriber');
+ }
+
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
index deedfbee7..2bda5a51a 100755
--- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
+++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
@@ -3140,7 +3140,7 @@ public function getListInterestCategories($scopeId, $scope = 'stores')
$api = $this->getApi($scopeId, $scope);
$listId = $this->getGeneralList($scopeId, $scope);
try {
- $interestCategories = $api->lists->interestCategory->getAll($listId, 'categories');
+ $interestCategories = $api->getLists()->getInterestCategory()->getAll($listId, 'categories');
foreach ($interestCategories['categories'] as $interestCategory) {
$interestGroupsArray[] = array(
'id' => $interestCategory['id'],
@@ -3160,9 +3160,10 @@ public function getListInterestGroups($scopeId, $scope = 'stores')
$api = $this->getApi($scopeId, $scope);
$listId = $this->getGeneralList($scopeId, $scope);
try {
- $interestCategories = $api->lists->interestCategory->getAll($listId, 'categories');
+ $apiInterestCategory = $api->getLists()->getInterestCategory();
+ $interestCategories = $apiInterestCategory->getAll($listId, 'categories');
foreach ($interestCategories['categories'] as $interestCategory) {
- $interestGroups = $api->lists->interestCategory->interests->getAll($listId, $interestCategory['id']);
+ $interestGroups = $apiInterestCategory->getInterests()->getAll($listId, $interestCategory['id']);
$groups = array();
foreach ($interestGroups['interests'] as $interestGroup) {
$groups[$interestGroup['id']] = $interestGroup['name'];
@@ -3206,23 +3207,27 @@ public function getInterest($storeId)
$interest = $this->getLocalInterestCategories($storeId);
if ($interest != '') {
$interest = explode(",", $interest);
+
} else {
$interest = array();
}
$api = $this->getApi($storeId);
$listId = $this->getGeneralList($storeId);
- $allInterest = $api->lists->interestCategory->getAll($listId);
+ $apiInterestCategory = $api->getLists()->getInterestCategory();
+ $allInterest = $apiInterestCategory->getAll($listId);
foreach ($allInterest['categories'] as $item) {
if (in_array($item['id'], $interest)) {
$rc[$item['id']]['interest'] = array('id' => $item['id'], 'title' => $item['title'], 'type' => $item['type']);
}
}
+ $apiInterestCategoryInterest = $apiInterestCategory->getInterests();
foreach ($interest as $interestId) {
- $mailchimpInterest = $api->lists->interestCategory->interests->getAll($listId, $interestId);
+ $mailchimpInterest = $apiInterestCategoryInterest->getAll($listId, $interestId);
foreach ($mailchimpInterest['interests'] as $mi) {
$rc[$mi['category_id']]['category'][$mi['display_order']] = array('id' => $mi['id'], 'name' => $mi['name'], 'checked' => false);
}
}
+
return $rc;
}
@@ -3239,7 +3244,7 @@ public function getInterestGroups($customerId, $subscriberId, $storeId, $interes
if (!$interest) {
$interest = $this->getInterest($storeId);
}
- $interestGroup = Mage::getModel('mailchimp/interestgroup');
+ $interestGroup = $this->getInterestGroupModel();
$interestGroup->getByRelatedIdStoreId($customerId, $subscriberId, $storeId);
if ($interestGroup->getId()) {
$groups = unserialize($interestGroup->getGroupdata());
@@ -3281,10 +3286,11 @@ public function saveInterestGroupData($params, $storeId, $customerId = null, $su
{
$groups = $this->getInterestGroupsIfAvailable($params);
if (!$customerId) {
+ $customerSession = $this->getCustomerSession();
if ($this->isAdmin()) {
$customerId = $params['customer_id'];
- } elseif (Mage::getSingleton('customer/session')->isLoggedIn()) {
- $customerData = Mage::getSingleton('customer/session')->getCustomer();
+ } elseif ($customerSession->isLoggedIn()) {
+ $customerData = $customerSession->getCustomer();
$customerId = $customerData->getId();
}
}
@@ -3292,7 +3298,7 @@ public function saveInterestGroupData($params, $storeId, $customerId = null, $su
if ($subscriber) {
$subscriberId = $subscriber->getSubscriberId();
}
- $interestGroup = Mage::getModel('mailchimp/interestgroup');
+ $interestGroup = $this->getInterestGroupModel();
$interestGroup->getByRelatedIdStoreId($customerId, $subscriberId, $storeId);
$origSubscriberId = $interestGroup->getSubscriberId();
$origCustomerId = $interestGroup->getCustomerId();
@@ -3310,7 +3316,7 @@ public function saveInterestGroupData($params, $storeId, $customerId = null, $su
if ($storeId) {
$interestGroup->setStoreId($storeId);
}
- $interestGroup->setUpdatedAt(Mage::getModel('core/date')->date('d-m-Y H:i:s'));
+ $interestGroup->setUpdatedAt($this->getCurrentDateTime());
$interestGroup->save();
}
}
@@ -3338,4 +3344,28 @@ public function isAdmin()
{
return Mage::app()->getStore()->isAdmin();
}
+
+ /**
+ * @return Ebizmarts_MailChimp_Model_Interestgroup
+ */
+ protected function getInterestGroupModel()
+ {
+ return Mage::getModel('mailchimp/interestgroup');
+ }
+
+ /**
+ * @return Mage_Customer_Model_Session
+ */
+ protected function getCustomerSession()
+ {
+ return Mage::getSingleton('customer/session');
+ }
+
+ /**
+ * @return mixed
+ */
+ protected function getCurrentDateTime()
+ {
+ return Mage::getModel('core/date')->date('d-m-Y H:i:s');
+ }
}
diff --git a/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.12.2-1.1.13.php b/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.12.3-1.1.13.php
similarity index 100%
rename from app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.12.2-1.1.13.php
rename to app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.12.3-1.1.13.php
diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Checkout/Success/GroupsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Checkout/Success/GroupsTest.php
new file mode 100644
index 000000000..a59a91e34
--- /dev/null
+++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Checkout/Success/GroupsTest.php
@@ -0,0 +1,101 @@
+getLayout();
+ $this->_block = new Ebizmarts_MailChimp_Block_Checkout_Success_Groups;
+ $this->_groupsMock = $this->getMockBuilder(Ebizmarts_MailChimp_Block_Checkout_Success_Groups::class);
+
+ /* We are required to set layouts before we can do anything with blocks */
+ $this->_block->setLayout($layout);
+ }
+
+ public function testRenderGroups()
+ {
+ $category = array();
+
+ $groupsMock = $this->_groupsMock
+ ->disableOriginalConstructor()
+ ->setMethods(array('createObject', 'addGroupOptions', 'getElementHtml'))
+ ->getMock();
+
+ $objectMock = $this->getMockBuilder(Varien_Data_Form_Element_Checkboxes::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $groupsMock->expects($this->once())->method('createObject')->with($category)->willReturn($objectMock);
+ $groupsMock->expects($this->once())->method('addGroupOptions')->with($category, $objectMock);
+ $groupsMock->expects($this->once())->method('getElementHtml')->with($category, $objectMock);
+
+ $groupsMock->renderGroups($category);
+ }
+
+ public function testGetInterest()
+ {
+ $interest = array();
+ $customerEmail = 'customer@email.com';
+ $subscriberId = 1;
+ $customerId = 2;
+ $storeId = 1;
+
+ $groupsMock = $this->_groupsMock
+ ->disableOriginalConstructor()
+ ->setMethods(array('getSubscriberModel', 'getSessionLastRealOrder', 'getElementHtml', 'getMailChimpHelper'))
+ ->getMock();
+
+ $orderMock = $this->getMockBuilder(Mage_Sales_Model_Order::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getCustomerEmail', 'getCustomerId', 'getStoreId'))
+ ->getMock();
+
+ $subscriberMock = $this->getMockBuilder(Mage_Newsletter_Model_Subscriber::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('loadByEmail', 'getSubscriberId'))
+ ->getMock();
+
+ $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getInterestGroups'))
+ ->getMock();
+
+
+ $groupsMock->expects($this->once())->method('getSubscriberModel')->willReturn($subscriberMock);
+ $groupsMock->expects($this->once())->method('getSessionLastRealOrder')->willReturn($orderMock);
+
+ $orderMock->expects($this->once())->method('getCustomerEmail')->willReturn($customerEmail);
+
+ $subscriberMock->expects($this->once())->method('loadByEmail')->with($customerEmail);
+ $subscriberMock->expects($this->once())->method('getSubscriberId')->willReturn($subscriberId);
+
+ $orderMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
+ $orderMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
+
+ $groupsMock->expects($this->once())->method('getMailChimpHelper')->willReturn($helperMock);
+
+ $orderMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
+
+ $helperMock->expects($this->once())->method('getInterestGroups')->with($customerId, $subscriberId, $storeId)->willReturn($interest);
+
+ $groupsMock->getInterest();
+ }
+
+}
diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Customer/Newsletter/IndexTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Customer/Newsletter/IndexTest.php
new file mode 100644
index 000000000..ffb92a9c3
--- /dev/null
+++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Block/Customer/Newsletter/IndexTest.php
@@ -0,0 +1,92 @@
+getLayout();
+ $this->_block = new Ebizmarts_MailChimp_Block_Customer_Newsletter_Index;
+ $this->_indexMock = $this->getMockBuilder(Ebizmarts_MailChimp_Block_Customer_Newsletter_Index::class);
+
+ /* We are required to set layouts before we can do anything with blocks */
+ $this->_block->setLayout($layout);
+ }
+
+ public function testGetInterest()
+ {
+ $interest = array();
+ $emailAddress = 'address@email.com';
+ $subscriberId = 1;
+ $customerId = 2;
+ $storeId = 1;
+
+ $indexMock = $this->_indexMock
+ ->disableOriginalConstructor()
+ ->setMethods(array('getSubscriberModel', '_getEmail', 'getMailChimpHelper', 'getCustomerSession'))
+ ->getMock();
+
+
+ $subscriberMock = $this->getMockBuilder(Mage_Newsletter_Model_Subscriber::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('loadByEmail', 'getSubscriberId', 'getStoreId'))
+ ->getMock();
+
+ $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('isAdmin', 'getInterestGroups'))
+ ->getMock();
+
+ $customerSessionMock = $this->getMockBuilder(Mage_Customer_Model_Session::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('isLoggedIn', 'getCustomer'))
+ ->getMock();
+
+ $customerMock = $this->getMockBuilder(Mage_Customer_Model_Customer::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getId', 'getStoreId'))
+ ->getMock();
+
+ $indexMock->expects($this->once())->method('getSubscriberModel')->willReturn($subscriberMock);
+ $indexMock->expects($this->once())->method('_getEmail')->willReturn($emailAddress);
+
+ $subscriberMock->expects($this->once())->method('loadByEmail')->with($emailAddress);
+
+ $indexMock->expects($this->once())->method('getMailChimpHelper')->willReturn($helperMock);
+ $indexMock->expects($this->once())->method('getCustomerSession')->willReturn($customerSessionMock);
+
+ $helperMock->expects($this->once())->method('isAdmin')->willReturn(false);
+
+ $customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true);
+ $customerSessionMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
+
+ $customerMock->expects($this->once())->method('getId')->willReturn($customerId);
+
+ $subscriberMock->expects($this->once())->method('getStoreId')->willReturn(null);
+
+ $customerMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
+
+ $subscriberMock->expects($this->once())->method('getSubscriberId')->willReturn($subscriberId);
+
+ $helperMock->expects($this->once())->method('getInterestGroups')->with($customerId, $subscriberId, $storeId)->willReturn($interest);
+
+ $indexMock->getInterest();
+ }
+
+}
diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php
index 3e3ce770f..5d10ae596 100644
--- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php
+++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php
@@ -951,7 +951,7 @@ public function testSaveLastItemsSent()
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_PCD_LAST_ID, $promoCodeLastId),
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_RESEND_ENABLED, 1),
array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_RESEND_TURN, 1)
- );
+ );
$helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
->disableOriginalConstructor()
@@ -969,4 +969,267 @@ public function testSaveLastItemsSent()
$helperMock->saveLastItemsSent($scopeId, $scope);
}
+
+ public function testGetListInterestCategories()
+ {
+ $scopeId = 1;
+ $scope = 'stores';
+ $listId = 'a1s2d3f4g5';
+ $interestCategoryId = 1;
+ $categoriesResponse = array('categories' => array(array('id' => $interestCategoryId, 'title' => 'Category Title', 'type' => 'checkbox')));
+
+ $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getApi', 'getGeneralList'))
+ ->getMock();
+
+ $apiMock = $this->getMockBuilder(Ebizmarts_MailChimp::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getLists'))
+ ->getMock();
+
+ $apiListsMock = $this->getMockBuilder(Ebizmarts_MailChimp::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getInterestCategory'))
+ ->getMock();
+
+ $apiListsInterestCategoryMock = $this->getMockBuilder(MailChimp_ListsInterestCategory::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getAll'))
+ ->getMock();
+
+ $helperMock->expects($this->once())->method('getApi')->with($scopeId, $scope)->willReturn($apiMock);
+ $helperMock->expects($this->once())->method('getGeneralList')->with($scopeId, $scope)->willReturn($listId);
+
+ $apiMock->expects($this->once())->method('getLists')->willReturn($apiListsMock);
+
+ $apiListsMock->expects($this->once())->method('getInterestCategory')->willReturn($apiListsInterestCategoryMock);
+
+ $apiListsInterestCategoryMock->expects($this->once())->method('getAll')->with($listId, 'categories')->willReturn($categoriesResponse);
+
+ $helperMock->getListInterestCategories($scopeId, $scope);
+ }
+
+ public function testGetListInterestGroups()
+ {
+ $scopeId = 1;
+ $scope = 'stores';
+ $listId = 'a1s2d3f4g5';
+ $interestCategoryId = 1;
+ $categoriesResponse = array('categories' => array(array('id' => $interestCategoryId, 'title' => 'Category Title', 'type' => 'checkbox')));
+ $interestsResponse = array('interests' => array(array('id' => 2, 'name' => 'Group Name')));
+
+ $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getApi', 'getGeneralList'))
+ ->getMock();
+
+ $apiMock = $this->getMockBuilder(Ebizmarts_MailChimp::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getLists'))
+ ->getMock();
+
+ $apiListsMock = $this->getMockBuilder(Ebizmarts_MailChimp::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getInterestCategory'))
+ ->getMock();
+
+ $apiListsInterestCategoryMock = $this->getMockBuilder(MailChimp_ListsInterestCategory::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getAll', 'getInterests'))
+ ->getMock();
+
+ $apiListsInterestCategoryInterestsMock = $this->getMockBuilder(MailChimp_ListInterestCategoryInterests::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getAll'))
+ ->getMock();
+
+ $helperMock->expects($this->once())->method('getApi')->with($scopeId, $scope)->willReturn($apiMock);
+ $helperMock->expects($this->once())->method('getGeneralList')->with($scopeId, $scope)->willReturn($listId);
+
+ $apiMock->expects($this->once())->method('getLists')->willReturn($apiListsMock);
+
+ $apiListsMock->expects($this->once())->method('getInterestCategory')->willReturn($apiListsInterestCategoryMock);
+
+ $apiListsInterestCategoryMock->expects($this->once())->method('getAll')->with($listId, 'categories')->willReturn($categoriesResponse);
+ $apiListsInterestCategoryMock->expects($this->once())->method('getInterests')->willReturn($apiListsInterestCategoryInterestsMock);
+
+ $apiListsInterestCategoryInterestsMock->expects($this->once())->method('getAll')->with($listId, $interestCategoryId)->willReturn($interestsResponse);
+
+ $helperMock->getListInterestGroups($scopeId, $scope);
+ }
+
+ public function testGetInterest()
+ {
+ $scopeId = 1;
+ $listId = 'a1s2d3f4g5';
+ $interestIdOne = 'z0x9c8v7b6';
+ $interestNameOne = 'Group One Name';
+ $displayOrderOne = 1;
+ $interestIdTwo = 'p4o5i6u7y8';
+ $interestNameTwo = 'Group Two Name';
+ $displayOrderTwo = 2;
+ $localGroups = "$interestIdOne,$interestIdTwo";
+ $interestCategoryId = 1;
+ $categoriesResponse = array('categories' => array(array('id' => $interestCategoryId, 'title' => 'Category Title', 'type' => 'checkbox')));
+ $interestsResponseOne = array('interests' => array(array('category_id' => $interestCategoryId, 'id' => $interestIdOne, 'name' => $interestNameOne, 'display_order' => $displayOrderOne)));
+ $interestsResponseTwo = array('interests' => array(array('category_id' => $interestCategoryId, 'id' => $interestIdTwo, 'name' => $interestNameTwo, 'display_order' => $displayOrderTwo)));
+ $expectedResult = array(1 => array('category' => array($displayOrderOne => array('id' => $interestIdOne, 'name' => $interestNameOne, 'checked' => false), $displayOrderTwo => array('id' => $interestIdTwo, 'name' => $interestNameTwo, 'checked' => false))));
+
+ $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getApi', 'getGeneralList', 'getLocalInterestCategories'))
+ ->getMock();
+
+ $apiMock = $this->getMockBuilder(Ebizmarts_MailChimp::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getLists'))
+ ->getMock();
+
+ $apiListsMock = $this->getMockBuilder(Ebizmarts_MailChimp::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getInterestCategory'))
+ ->getMock();
+
+ $apiListsInterestCategoryMock = $this->getMockBuilder(MailChimp_ListsInterestCategory::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getAll', 'getInterests'))
+ ->getMock();
+
+ $apiListsInterestCategoryInterestsMock = $this->getMockBuilder(MailChimp_ListInterestCategoryInterests::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getAll'))
+ ->getMock();
+
+ $helperMock->expects($this->once())->method('getLocalInterestCategories')->with($scopeId)->willReturn($localGroups);
+ $helperMock->expects($this->once())->method('getApi')->with($scopeId)->willReturn($apiMock);
+ $helperMock->expects($this->once())->method('getGeneralList')->with($scopeId)->willReturn($listId);
+
+ $apiMock->expects($this->once())->method('getLists')->willReturn($apiListsMock);
+
+ $apiListsMock->expects($this->once())->method('getInterestCategory')->willReturn($apiListsInterestCategoryMock);
+
+ $apiListsInterestCategoryMock->expects($this->once())->method('getAll')->with($listId)->willReturn($categoriesResponse);
+
+ $apiListsInterestCategoryMock->expects($this->once())->method('getInterests')->willReturn($apiListsInterestCategoryInterestsMock);
+
+ $apiListsInterestCategoryInterestsMock->expects($this->exactly(2))->method('getAll')->withConsecutive(
+ array($listId, $interestIdOne),
+ array($listId, $interestIdTwo)
+ )->willReturnOnConsecutiveCalls(
+ $interestsResponseOne,
+ $interestsResponseTwo
+ );
+
+ $result = $helperMock->getInterest($scopeId);
+
+ $this->assertEquals($expectedResult, $result);
+ }
+
+ public function testGetInterestGroups()
+ {
+ $customerId = 1;
+ $subscriberId = 1;
+ $storeId = 1;
+ $interestGroupId = 1;
+ $interestIdOne = 'z0x9c8v7b6';
+ $interestNameOne = 'Group One Name';
+ $displayOrderOne = 1;
+ $interestIdTwo = 'p4o5i6u7y8';
+ $interestNameTwo = 'Group Two Name';
+ $displayOrderTwo = 2;
+ $interest = array(1 => array('category' => array($displayOrderOne => array('id' => $interestIdOne, 'name' => $interestNameOne, 'checked' => false), $displayOrderTwo => array('id' => $interestIdTwo, 'name' => $interestNameTwo, 'checked' => false))));
+ $groupData = 'a:2:{s:10:"bc15dbe6a5";a:1:{s:10:"d6b7541ee7";s:10:"d6b7541ee7";}s:10:"2a2f23d671";s:10:"36c250eeff";}';
+ $expectedResult = $interest;
+
+ $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getInterest', 'getInterestGroupModel', 'getLocalInterestCategories'))
+ ->getMock();
+
+ $interestGroupMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Interestgroup::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getByRelatedIdStoreId', 'getId', 'getGroupdata'))
+ ->getMock();
+
+ $helperMock->expects($this->once())->method('getInterest')->with($storeId)->willReturn($interest);
+ $helperMock->expects($this->once())->method('getInterestGroupModel')->willReturn($interestGroupMock);
+
+ $interestGroupMock->expects($this->once())->method('getByRelatedIdStoreId')->with($customerId, $subscriberId, $storeId)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('getId')->willReturn($interestGroupId);
+ $interestGroupMock->expects($this->once())->method('getGroupdata')->willReturn($groupData);
+
+ $result = $helperMock->getInterestGroups($customerId, $subscriberId, $storeId);
+
+ $this->assertEquals($expectedResult, $result);
+ }
+
+ public function testSaveInterestGroupData()
+ {
+ $params = array();
+ $customerId = 2;
+ $subscriberId = 2;
+ $origCustomerId = 1;
+ $origSubscriberId = 1;
+ $storeId = 1;
+ $groupData = 'a:2:{s:10:"bc15dbe6a5";a:1:{s:10:"d6b7541ee7";s:10:"d6b7541ee7";}s:10:"2a2f23d671";s:10:"36c250eeff";}';
+ $unserializedGroupData = unserialize($groupData);
+ $currentDateTime = '2018-07-26 12:43:40';
+
+ $helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getInterestGroupsIfAvailable', 'isAdmin', 'getCustomerSession', 'getInterestGroupModel',
+ 'getCurrentDateTime'))
+ ->getMock();
+
+ $interestGroupMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Interestgroup::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getByRelatedIdStoreId', 'getSubscriberId', 'getCustomerId', 'setSubscriberId',
+ 'setCustomerId', 'setGroupdata', 'getGroupdata', 'setStoreId', 'setUpdatedAt', 'save'))
+ ->getMock();
+
+ $subscriberMock = $this->getMockBuilder(Mage_Newsletter_Model_Subscriber::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getSubscriberId'))
+ ->getMock();
+
+ $customerSessionMock = $this->getMockBuilder(Mage_Customer_Model_Session::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('isLoggedIn', 'getCustomer'))
+ ->getMock();
+
+ $customerMock = $this->getMockBuilder(Mage_Customer_Model_Customer::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getId'))
+ ->getMock();
+
+ $helperMock->expects($this->once())->method('getInterestGroupsIfAvailable')->with($params)->willReturn($unserializedGroupData);
+ $helperMock->expects($this->once())->method('getCustomerSession')->willReturn($customerSessionMock);
+ $helperMock->expects($this->once())->method('isAdmin')->willReturn(false);
+
+ $customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(true);
+ $customerSessionMock->expects($this->once())->method('getCustomer')->willReturn($customerMock);
+
+ $customerMock->expects($this->once())->method('getId')->willReturn($customerId);
+
+ $subscriberMock->expects($this->once())->method('getSubscriberId')->willReturn($subscriberId);
+
+ $helperMock->expects($this->once())->method('getInterestGroupModel')->willReturn($interestGroupMock);
+
+ $interestGroupMock->expects($this->once())->method('getByRelatedIdStoreId')->with($customerId, $subscriberId, $storeId)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('getSubscriberId')->willReturn($origSubscriberId);
+ $interestGroupMock->expects($this->once())->method('getCustomerId')->willReturn($origCustomerId);
+ $interestGroupMock->expects($this->once())->method('setSubscriberId')->with($subscriberId)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('setGroupdata')->with($groupData)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('getGroupdata')->willReturn($groupData);
+ $interestGroupMock->expects($this->once())->method('setStoreId')->with($storeId)->willReturnSelf();
+
+ $helperMock->expects($this->once())->method('getCurrentDateTime')->willReturn($currentDateTime);
+
+ $interestGroupMock->expects($this->once())->method('setUpdatedAt')->with($currentDateTime)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('save')->willReturnSelf();
+
+ $helperMock->saveInterestGroupData($params, $storeId, null, $subscriberMock);
+ }
}
diff --git a/lib/Ebizmarts/MailChimp.php b/lib/Ebizmarts/MailChimp.php
index 3cdec2e26..f9a10c91d 100755
--- a/lib/Ebizmarts/MailChimp.php
+++ b/lib/Ebizmarts/MailChimp.php
@@ -308,6 +308,14 @@ public function getBatchOperation()
return $this->batchOperation;
}
+ /**
+ * @return MailChimp_Lists
+ */
+ public function getLists()
+ {
+ return $this->lists;
+ }
+
public function call($url,$params,$method=Ebizmarts_MailChimp::GET,$encodeJson=true)
{
$paramsOrig = $params;
diff --git a/lib/Ebizmarts/MailChimp/Lists.php b/lib/Ebizmarts/MailChimp/Lists.php
index ba56f78aa..d98635f6b 100644
--- a/lib/Ebizmarts/MailChimp/Lists.php
+++ b/lib/Ebizmarts/MailChimp/Lists.php
@@ -50,6 +50,14 @@ class MailChimp_Lists extends MailChimp_Abstract
*/
public $webhooks;
+ /**
+ * @return MailChimp_ListsInterestCategory
+ */
+ public function getInterestCategory()
+ {
+ return $this->interestCategory;
+ }
+
/**
* @param $name
* @param $contact
diff --git a/lib/Ebizmarts/MailChimp/ListsInterestCategory.php b/lib/Ebizmarts/MailChimp/ListsInterestCategory.php
index 7f6a4bb5a..8faa1c35e 100644
--- a/lib/Ebizmarts/MailChimp/ListsInterestCategory.php
+++ b/lib/Ebizmarts/MailChimp/ListsInterestCategory.php
@@ -17,6 +17,14 @@ class MailChimp_ListsInterestCategory extends MailChimp_Abstract
*/
public $interests;
+ /**
+ * @return MailChimp_ListInterestCategoryInterests
+ */
+ public function getInterests()
+ {
+ return $this->interests;
+ }
+
/**
* @param $listId The unique id for the list.
* @param $title The text description of this category. This field appears on signup forms and is
From 950643acd24539d0e29fff31385f8841cefd6962 Mon Sep 17 00:00:00 2001
From: Santiago
Date: Tue, 31 Jul 2018 14:08:53 -0300
Subject: [PATCH 017/113] Add tests.
---
.../MailChimp/controllers/GroupController.php | 67 ++++++++--
.../controllers/GroupControllerTest.php | 120 ++++++++++++++++++
2 files changed, 174 insertions(+), 13 deletions(-)
create mode 100644 dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/GroupControllerTest.php
diff --git a/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php b/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php
index 5cf95fac3..0071bf8b7 100644
--- a/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php
+++ b/app/code/community/Ebizmarts/MailChimp/controllers/GroupController.php
@@ -16,35 +16,36 @@ class Ebizmarts_MailChimp_GroupController extends Mage_Core_Controller_Front_Act
{
public function indexAction()
{
- $order = Mage::getSingleton('checkout/session')->getLastRealOrder();
- $session = Mage::getSingleton('core/session');
- $helper = $this->getHelper();
+ $order = $this->getSessionLastRealOrder();
+ $session = $this->getCoreSession();
+ $interestGroup = $this->getInterestGroupModel();
$params = $this->getRequest()->getParams();
$storeId = $order->getStoreId();
- $interestGroup = Mage::getModel('mailchimp/interestgroup');
- $subscriber = Mage::getModel('newsletter/subscriber')
- ->loadByEmail($order->getCustomerEmail());
+ $customerEmail = $order->getCustomerEmail();
$customerId = $order->getCustomerId();
+ $subscriber = $this->getSubscriberModel()
+ ->loadByEmail($customerEmail);
try {
if (!$subscriber->getSubscriberId()) {
- $subscriber->setSubscriberEmail($order->getCustomerEmail());
+ $subscriber->setSubscriberEmail($customerEmail);
$subscriber->setSubscriberFirstname($order->getCustomerFirstname());
$subscriber->setSubscriberLastname($order->getCustomerLastname());
- $subscriber->subscribe($order->getCustomerEmail());
+ $subscriber->subscribe($customerEmail);
}
- $interestGroup->getByRelatedIdStoreId($customerId, $subscriber->getSubscriberId(),$storeId);
+ $subscriberId = $subscriber->getSubscriberId();
+ $interestGroup->getByRelatedIdStoreId($customerId, $subscriberId, $storeId);
$interestGroup->setGroupdata(serialize($params));
- $interestGroup->setSubscriberId($subscriber->getSubscriberId());
- $interestGroup->setCustomerId($order->getCustomerId());
+ $interestGroup->setSubscriberId($subscriberId);
+ $interestGroup->setCustomerId($customerId);
$interestGroup->setStoreId($storeId);
- $interestGroup->setUpdatedAt(Mage::getModel('core/date')->date('d-m-Y H:i:s'));
+ $interestGroup->setUpdatedAt($this->getCurrentDateTime());
$interestGroup->save();
$this->getApiSubscriber()->update($subscriber->getSubscriberEmail(), $storeId, '', 1);
$session->addSuccess($this->__('Thanks for share your interest with us.'));
} catch (Exception $e) {
- $helper->logError($e->getMessage());
+ $this->getHelper()->logError($e->getMessage());
$session->addWarning($this->__('Something went wrong with the interests subscription. Please go to the account subscription menu to subscriber to the interests successfully.'));
}
$this->_redirect('/');
@@ -59,4 +60,44 @@ protected function getApiSubscriber()
{
return Mage::getModel('mailchimp/api_subscribers');
}
+
+ /**
+ * @return mixed
+ */
+ protected function getSessionLastRealOrder()
+ {
+ return Mage::getSingleton('checkout/session')->getLastRealOrder();
+ }
+
+ /**
+ * @return Mage_Core_Model_Session
+ */
+ protected function getCoreSession()
+ {
+ return Mage::getSingleton('core/session');
+ }
+
+ /**
+ * @return Ebizmarts_MailChimp_Model_Interestgroup
+ */
+ protected function getInterestGroupModel()
+ {
+ return Mage::getModel('mailchimp/interestgroup');
+ }
+
+ /**
+ * @return Mage_Newsletter_Model_Subscriber
+ */
+ protected function getSubscriberModel()
+ {
+ return Mage::getModel('newsletter/subscriber');
+ }
+
+ /**
+ * @return mixed
+ */
+ protected function getCurrentDateTime()
+ {
+ return Mage::getModel('core/date')->date('d-m-Y H:i:s');
+ }
}
diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/GroupControllerTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/GroupControllerTest.php
new file mode 100644
index 000000000..dfa989fa6
--- /dev/null
+++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/controllers/GroupControllerTest.php
@@ -0,0 +1,120 @@
+groupController = $this->getMockBuilder(Ebizmarts_MailChimp_GroupController::class);
+ }
+
+ public function tearDown()
+ {
+ $this->groupController = null;
+ }
+
+ public function testIndexAction()
+ {
+ $storeId = 1;
+ $customerId = 1;
+ $subscriberId = 1;
+ $customerEmail = 'customer@email.com';
+ $customerFirstName = "First Name";
+ $customerLastName = "Last Name";
+ $groupData = 'a:2:{s:10:"bc15dbe6a5";a:1:{s:10:"d6b7541ee7";s:10:"d6b7541ee7";}s:10:"2a2f23d671";s:10:"36c250eeff";}';
+ $params = unserialize($groupData);
+ $currentDateTime = '2018-07-26 12:43:40';
+ $successMessage = 'Thanks for share your interest with us.';
+
+ $groupControllerMock = $this->groupController
+ ->disableOriginalConstructor()
+ ->setMethods(array('getSessionLastRealOrder', 'getCoreSession', 'getHelper', 'getRequest',
+ 'getInterestGroupModel', 'getSubscriberModel', 'getApiSubscriber', '_redirect',
+ 'getCurrentDateTime','__'))
+ ->getMock();
+
+ $requestMock = $this->getMockBuilder(Mage_Core_Controller_Request_Http::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getParams'))
+ ->getMock();
+
+ $orderMock = $this->getMockBuilder(Mage_Sales_Model_Order::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getStoreId', 'getCustomerEmail', 'getCustomerId', 'getCustomerFirstname', 'getCustomerLastname'))
+ ->getMock();
+
+ $subscriberMock = $this->getMockBuilder(Mage_Newsletter_Model_Subscriber::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getSubscriberId', 'setSubscriberEmail', 'setSubscriberFirstname',
+ 'setSubscriberLastname', 'subscribe', 'getSubscriberEmail', 'loadByEmail'))
+ ->getMock();
+
+ $coreSessionMock = $this->getMockBuilder(Mage_Core_Model_Session::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('addSuccess'))
+ ->getMock();
+
+ $interestGroupMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Interestgroup::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getByRelatedIdStoreId', 'setGroupdata', 'setSubscriberId', 'setCustomerId',
+ 'setStoreId', 'setUpdatedAt', 'save'))
+ ->getMock();
+
+ $apiSubscriberMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Subscribers::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('update'))
+ ->getMock();
+
+ $groupControllerMock->expects($this->once())->method('getSessionLastRealOrder')->willReturn($orderMock);
+ $groupControllerMock->expects($this->once())->method('getCoreSession')->willReturn($coreSessionMock);
+ $groupControllerMock->expects($this->once())->method('getInterestGroupModel')->willReturn($interestGroupMock);
+ $groupControllerMock->expects($this->once())->method('getRequest')->willReturn($requestMock);
+
+ $requestMock->expects($this->once())->method('getParams')->willReturn($params);
+
+ $orderMock->expects($this->once())->method('getStoreId')->willReturn($storeId);
+ $orderMock->expects($this->once())->method('getCustomerEmail')->willReturn($customerEmail);
+ $orderMock->expects($this->once())->method('getCustomerId')->willReturn($customerId);
+ $orderMock->expects($this->once())->method('getCustomerFirstname')->willReturn($customerFirstName);
+ $orderMock->expects($this->once())->method('getCustomerLastname')->willReturn($customerLastName);
+
+ $groupControllerMock->expects($this->once())->method('getSubscriberModel')->willReturn($subscriberMock);
+ $groupControllerMock->expects($this->once())->method('getCurrentDateTime')->willReturn($currentDateTime);
+
+ $subscriberMock->expects($this->once())->method('loadByEmail')->with($customerEmail)->willReturnSelf();
+ $subscriberMock->expects($this->exactly(2))->method('getSubscriberId')
+ ->willReturnOnConsecutiveCalls(null, $subscriberId);
+ $subscriberMock->expects($this->once())->method('setSubscriberEmail')->with($customerEmail)->willReturnSelf();
+ $subscriberMock->expects($this->once())->method('setSubscriberFirstname')->with($customerFirstName)->willReturnSelf();
+ $subscriberMock->expects($this->once())->method('setSubscriberLastname')->with($customerLastName)->willReturnSelf();
+ $subscriberMock->expects($this->once())->method('subscribe')->willReturnSelf();
+
+ $interestGroupMock->expects($this->once())->method('getByRelatedIdStoreId')->with($customerId, $subscriberId, $storeId)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('setGroupdata')->with($groupData)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('setSubscriberId')->with($subscriberId)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('setStoreId')->with($storeId)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('setUpdatedAt')->with($currentDateTime)->willReturnSelf();
+ $interestGroupMock->expects($this->once())->method('save')->willReturnSelf();
+
+ $groupControllerMock->expects($this->once())->method('getApiSubscriber')->willReturn($apiSubscriberMock);
+
+ $subscriberMock->expects($this->once())->method('getSubscriberEmail')->willReturn($customerEmail);
+
+ $apiSubscriberMock->expects($this->once())->method('update')->with($customerEmail, $storeId, '', 1);
+
+ $groupControllerMock->expects($this->once())->method('__')->with($successMessage)->willReturn($successMessage);
+
+ $coreSessionMock->expects($this->once())->method('addSuccess')->with($successMessage);
+
+ $groupControllerMock->expects($this->once())->method('_redirect')->with('/');
+ $groupControllerMock->indexAction();
+ }
+}
From 872b1113e6b71dc6adf2fc7c197bbafac4a6d501 Mon Sep 17 00:00:00 2001
From: keller
Date: Thu, 18 Oct 2018 10:47:34 -0300
Subject: [PATCH 018/113] closes #793 Add option to send subscription emails
via Magento
---
.../Ebizmarts/MailChimp/Model/Config.php | 1 +
.../Ebizmarts/MailChimp/Model/Observer.php | 4 +++-
.../Ebizmarts/MailChimp/Model/Subscriber.php | 6 ++---
.../Ebizmarts/MailChimp/etc/system.xml | 11 ++++++++++
.../MailChimp/Model/ObserverTest.php | 22 ++++++++++++++++---
5 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Config.php b/app/code/community/Ebizmarts/MailChimp/Model/Config.php
index a12280a70..55ab2c402 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Config.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Config.php
@@ -35,6 +35,7 @@ class Ebizmarts_MailChimp_Model_Config
const GENERAL_MIGRATE_FROM_1164 = 'mailchimp/general/migrate_from_1164';
const GENERAL_MIGRATE_LAST_ORDER_ID = 'mailchimp/general/migrate_last_order_id';
const GENERAL_SUBSCRIBER_AMOUNT = 'mailchimp/general/subscriber_batch_amount';
+ const GENERAL_MAGENTO_MAIL = 'mailchimp/general/magento_mail';
const ECOMMERCE_ACTIVE = 'mailchimp/ecommerce/active';
const ECOMMERCE_CUSTOMERS_OPTIN = 'mailchimp/ecommerce/customers_optin';
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
index 4eeb69bc9..7b650fc0e 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
@@ -147,7 +147,9 @@ public function handleSubscriber(Varien_Event_Observer $observer)
$this->addSuccessIfRequired($helper);
}
$apiSubscriber = $this->makeApiSubscriber();
- $subscriber->setImportMode(true);
+ if($helper->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL, $storeId) != 1){
+ $subscriber->setImportMode(true);
+ }
$this->createEmailCookie($subscriber);
if ($statusChanged) {
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php b/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
index ba61537a5..1e1026e17 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
@@ -12,7 +12,7 @@ class Ebizmarts_MailChimp_Model_Subscriber extends Mage_Newsletter_Model_Subscri
public function sendUnsubscriptionEmail()
{
- if (Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_ACTIVE)) {
+ if (Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_ACTIVE) && Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL) != 1) {
return $this;
} else {
return parent::sendUnsubscriptionEmail();
@@ -21,7 +21,7 @@ public function sendUnsubscriptionEmail()
public function sendConfirmationRequestEmail()
{
- if (Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_ACTIVE)) {
+ if (Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_ACTIVE) && Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL) != 1) {
return $this;
} else {
return parent::sendConfirmationRequestEmail();
@@ -30,7 +30,7 @@ public function sendConfirmationRequestEmail()
public function sendConfirmationSuccessEmail()
{
- if (Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_ACTIVE)) {
+ if (Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_ACTIVE) && Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL) != 1) {
return $this;
} else {
return parent::sendConfirmationSuccessEmail();
diff --git a/app/code/community/Ebizmarts/MailChimp/etc/system.xml b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
index 7e85f3eae..512b011cd 100755
--- a/app/code/community/Ebizmarts/MailChimp/etc/system.xml
+++ b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
@@ -182,6 +182,17 @@
1
+
+ Use Magento emails
+ select
+ adminhtml/system_config_source_yesno
+ 61
+ 1
+ 1
+ 1
+ 1
+
+
Webhooks Delete action
select
diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php
index 877adf3d3..bf978701f 100644
--- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php
+++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php
@@ -649,8 +649,15 @@ public function testAddColumnToSalesOrderGridCollection()
$observerMock->addColumnToSalesOrderGridCollection($eventObserverMock);
}
- public function testHandleSubscriber()
+ /**
+ * @param array $data
+ * @dataProvider handleSubscriberDataProvider
+ */
+
+ public function testHandleSubscriber($data)
{
+ $setImportMode = $data['setImportMode'];
+ $magentoMail = $data['magentoMail'];
$storeId = 1;
$eventObserverMock = $this->getMockBuilder(Varien_Event_Observer::class)
@@ -667,7 +674,7 @@ public function testHandleSubscriber()
$helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
->disableOriginalConstructor()
->setMethods(array('isSubscriptionEnabled', 'isEcomSyncDataEnabledInAnyScope',
- 'isSubscriptionConfirmationEnabled'))
+ 'isSubscriptionConfirmationEnabled', 'getConfigValueForScope'))
->getMock();
$eventMock = $this->getMockBuilder(Varien_Event::class)
@@ -701,13 +708,14 @@ public function testHandleSubscriber()
$subscriberMock->expects($this->once())->method('getStatus')->willReturn(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
$helperMock->expects($this->once())->method('isSubscriptionConfirmationEnabled')->with($storeId)->willReturn(true);
+ $helperMock->expects($this->once())->method('getConfigValueForScope')->with(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL, $storeId)->willReturn($magentoMail);
$subscriberMock->expects($this->once())->method('setStatus')->with(Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE);
$observerMock->expects($this->once())->method('addSuccessIfRequired')->with($helperMock);
$observerMock->expects($this->once())->method('makeApiSubscriber')->willReturn($apiSubscriberMock);
- $subscriberMock->expects($this->once())->method('setImportMode')->with(true);
+ $subscriberMock->expects($this->exactly($setImportMode))->method('setImportMode')->with(true);
$observerMock->expects($this->once())->method('createEmailCookie')->with($subscriberMock);
@@ -716,6 +724,14 @@ public function testHandleSubscriber()
$observerMock->handleSubscriber($eventObserverMock);
}
+ public function handleSubscriberDataProvider()
+ {
+ return array(
+ array(array('magentoMail' => 0, 'setImportMode' => 1)),
+ array(array('magentoMail' => 1, 'setImportMode' => 0))
+ );
+ }
+
/**
* @param array $cookieData
* @dataProvider loadCustomerToQuoteDataProvider
From 93288430ccbb7974c3e0767dfe1a1d91195868d0 Mon Sep 17 00:00:00 2001
From: keller
Date: Fri, 19 Oct 2018 16:17:06 -0300
Subject: [PATCH 019/113] #793 Don't send subscriber to Mailchimp automatically
when using Magento email
---
.../Ebizmarts/MailChimp/Model/Observer.php | 29 ++++++++++---------
.../MailChimp/Model/ObserverTest.php | 24 ++++++++++-----
2 files changed, 31 insertions(+), 22 deletions(-)
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
index 7b650fc0e..4a41e864c 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
@@ -141,26 +141,27 @@ public function handleSubscriber(Varien_Event_Observer $observer)
$isEnabled = $helper->isSubscriptionEnabled($storeId);
if ($isEnabled) {
$statusChanged = $subscriber->getIsStatusChanged();
- //Override Magento status to always send double opt-in confirmation.
- if($statusChanged && $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED && $helper->isSubscriptionConfirmationEnabled($storeId)) {
- $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE);
- $this->addSuccessIfRequired($helper);
- }
$apiSubscriber = $this->makeApiSubscriber();
if($helper->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL, $storeId) != 1){
- $subscriber->setImportMode(true);
+ //Override Magento status to always send double opt-in confirmation.
+ if($statusChanged && $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED && $helper->isSubscriptionConfirmationEnabled($storeId)) {
+ $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE);
+ $this->addSuccessIfRequired($helper);
}
- $this->createEmailCookie($subscriber);
+ $subscriber->setImportMode(true);
- if ($statusChanged) {
- $apiSubscriber->updateSubscriber($subscriber, true);
- } else {
- $origData = $subscriber->getOrigData();
+ $this->createEmailCookie($subscriber);
- if (is_array($origData) && isset($origData['subscriber_status'])
- && $origData['subscriber_status'] != $subscriber->getSubscriberStatus()
- ) {
+ if ($statusChanged) {
$apiSubscriber->updateSubscriber($subscriber, true);
+ } else {
+ $origData = $subscriber->getOrigData();
+
+ if (is_array($origData) && isset($origData['subscriber_status'])
+ && $origData['subscriber_status'] != $subscriber->getSubscriberStatus()
+ ) {
+ $apiSubscriber->updateSubscriber($subscriber, true);
+ }
}
}
}
diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php
index bf978701f..8908e058f 100644
--- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php
+++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php
@@ -658,6 +658,12 @@ public function testHandleSubscriber($data)
{
$setImportMode = $data['setImportMode'];
$magentoMail = $data['magentoMail'];
+ $addSuccessIfRequired = $data['addSuccessIfRequired'];
+ $createEmailCookie = $data['createEmailCookie'];
+ $isSubscriptionConfirmationEnabled = $data['isSubscriptionConfirmationEnabled'];
+ $getStatus = $data['getStatus'];
+ $setStatus = $data['setStatus'];
+ $updateSubscriber = $data['updateSubscriber'];
$storeId = 1;
$eventObserverMock = $this->getMockBuilder(Varien_Event_Observer::class)
@@ -705,21 +711,21 @@ public function testHandleSubscriber($data)
$helperMock->expects($this->once())->method('isSubscriptionEnabled')->with($storeId)->willReturn(true);
$subscriberMock->expects($this->once())->method('getIsStatusChanged')->willReturn(true);
- $subscriberMock->expects($this->once())->method('getStatus')->willReturn(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
+ $subscriberMock->expects($this->exactly($getStatus))->method('getStatus')->willReturn(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
- $helperMock->expects($this->once())->method('isSubscriptionConfirmationEnabled')->with($storeId)->willReturn(true);
+ $helperMock->expects($this->exactly($isSubscriptionConfirmationEnabled))->method('isSubscriptionConfirmationEnabled')->with($storeId)->willReturn(true);
$helperMock->expects($this->once())->method('getConfigValueForScope')->with(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL, $storeId)->willReturn($magentoMail);
- $subscriberMock->expects($this->once())->method('setStatus')->with(Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE);
+ $subscriberMock->expects($this->exactly($setStatus))->method('setStatus')->with(Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE);
- $observerMock->expects($this->once())->method('addSuccessIfRequired')->with($helperMock);
+ $observerMock->expects($this->exactly($addSuccessIfRequired))->method('addSuccessIfRequired')->with($helperMock);
$observerMock->expects($this->once())->method('makeApiSubscriber')->willReturn($apiSubscriberMock);
$subscriberMock->expects($this->exactly($setImportMode))->method('setImportMode')->with(true);
- $observerMock->expects($this->once())->method('createEmailCookie')->with($subscriberMock);
+ $observerMock->expects($this->exactly($createEmailCookie))->method('createEmailCookie')->with($subscriberMock);
- $apiSubscriberMock->expects($this->once())->method('updateSubscriber')->with($subscriberMock, true);
+ $apiSubscriberMock->expects($this->exactly($updateSubscriber))->method('updateSubscriber')->with($subscriberMock, true);
$observerMock->handleSubscriber($eventObserverMock);
}
@@ -727,8 +733,10 @@ public function testHandleSubscriber($data)
public function handleSubscriberDataProvider()
{
return array(
- array(array('magentoMail' => 0, 'setImportMode' => 1)),
- array(array('magentoMail' => 1, 'setImportMode' => 0))
+ array(array('magentoMail' => 0, 'setImportMode' => 1, 'addSuccessIfRequired' => 1, 'createEmailCookie' => 1, 'isSubscriptionConfirmationEnabled' => 1, 'getStatus' => 1,
+ 'setStatus' => 1, 'updateSubscriber' => 1)),
+ array(array('magentoMail' => 1, 'setImportMode' => 0, 'addSuccessIfRequired' => 0, 'createEmailCookie' => 0, 'isSubscriptionConfirmationEnabled' => 0, 'getStatus' => 0,
+ 'setStatus' => 0, 'updateSubscriber' => 0))
);
}
From 1e720c40b662cde1bb2b9464c65c6cd06381bdb8 Mon Sep 17 00:00:00 2001
From: Santiago
Date: Fri, 19 Oct 2018 17:35:06 -0300
Subject: [PATCH 020/113] Add translations.
---
.../MailChimp/Block/Checkout/Success/Groups.php | 2 +-
.../community/Ebizmarts/MailChimp/etc/system.xml | 12 ++++++------
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
index 2e5d9dda1..b9b8aeca2 100644
--- a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
@@ -148,7 +148,7 @@ protected function createOptionArray($category)
$type = $category['type'];
if ($type == 'dropdown') {
- $options[''] = '-- Select Group --';
+ $options[''] = $this->__('-- Select Group --');
}
return $options;
}
diff --git a/app/code/community/Ebizmarts/MailChimp/etc/system.xml b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
index a7e980f20..dbdd1cdd6 100755
--- a/app/code/community/Ebizmarts/MailChimp/etc/system.xml
+++ b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
@@ -141,7 +141,7 @@
1
- Add html code before the interest groups are displayed
+ Add html code before the interest groups are displayed
textarea
50
1
@@ -153,7 +153,7 @@
1
-
+
Add html code after the interest groups are displayed
textarea
51
@@ -166,7 +166,7 @@
1
-
+
Subscriber amount to be sent per run
select
mailchimp/system_config_source_batchLimit
@@ -207,7 +207,7 @@
- Create Webhook
+ Create Webhook
button
mailchimp/adminhtml_system_config_createWebhook
58
@@ -217,7 +217,7 @@
- Enable Two Way Sync
+ Enable Two Way Sync
select
adminhtml/system_config_source_yesno
mailchimp/system_config_backend_twowaysync
@@ -260,7 +260,7 @@
- Ecommerce
+ Ecommerce
200
text
1
From 94353fcbfcc7abc22bbe26b7fbf1315f062af8c4 Mon Sep 17 00:00:00 2001
From: keller
Date: Mon, 22 Oct 2018 15:04:04 -0300
Subject: [PATCH 021/113] #793 Force double-opt in for registered customers if
"Need to Confirm" enabled
---
.../Ebizmarts/MailChimp/Model/Subscriber.php | 55 +++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php b/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
index 1e1026e17..3b980d3f5 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
@@ -36,4 +36,59 @@ public function sendConfirmationSuccessEmail()
return parent::sendConfirmationSuccessEmail();
}
}
+
+ //Force double-opt in for registered customers if "Need to Confirm" is enabled
+ public function subscribe($email)
+ {
+ $this->loadByEmail($email);
+ $customerSession = Mage::getSingleton('customer/session');
+
+ if(!$this->getId()) {
+ $this->setSubscriberConfirmCode($this->randomSequence());
+ }
+
+ $isConfirmNeed = (Mage::getStoreConfig(self::XML_PATH_CONFIRMATION_FLAG) == 1) ? true : false;
+ $isOwnSubscribes = false;
+ $ownerId = Mage::getModel('customer/customer')
+ ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
+ ->loadByEmail($email)
+ ->getId();
+ $isSubscribeOwnEmail = $customerSession->isLoggedIn() && $ownerId == $customerSession->getId();
+
+ if (!$this->getId() || $this->getStatus() == self::STATUS_UNSUBSCRIBED
+ || $this->getStatus() == self::STATUS_NOT_ACTIVE
+ ) {
+ if ($isConfirmNeed === true) {
+ $this->setStatus(self::STATUS_NOT_ACTIVE);
+ } else {
+ $this->setStatus(self::STATUS_SUBSCRIBED);
+ }
+ $this->setSubscriberEmail($email);
+ }
+
+ if ($isSubscribeOwnEmail) {
+ $this->setStoreId($customerSession->getCustomer()->getStoreId());
+ $this->setCustomerId($customerSession->getCustomerId());
+ } else {
+ $this->setStoreId(Mage::app()->getStore()->getId());
+ $this->setCustomerId(0);
+ }
+
+ $this->setIsStatusChanged(true);
+
+ try {
+ $this->save();
+ if ($isConfirmNeed === true
+ && $isOwnSubscribes === false
+ ) {
+ $this->sendConfirmationRequestEmail();
+ } else {
+ $this->sendConfirmationSuccessEmail();
+ }
+
+ return $this->getStatus();
+ } catch (Exception $e) {
+ throw new Exception($e->getMessage());
+ }
+ }
}
From c9c08ded4c4d39f965deedb4dc2183429a3700e1 Mon Sep 17 00:00:00 2001
From: keller
Date: Thu, 25 Oct 2018 16:21:08 -0300
Subject: [PATCH 022/113] #793 Change how customers are forcefully subscribed
---
.../community/Ebizmarts/MailChimp/Model/Api/Customers.php | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php
index acc89eb62..88fcb2f0f 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php
@@ -49,6 +49,8 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId)
$this->optInStatusForStore = $this->getOptin($this->getBatchMagentoStoreId());
+ $subscriber = Mage::getModel('newsletter/subscriber');
+
$counter = 0;
foreach ($customersCollection as $customer) {
$data = $this->_buildCustomerData($customer);
@@ -60,6 +62,10 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId)
$this->logCouldNotEncodeCustomerError($customer);
}
+ if ($this->optInStatusForStore && !$subscriber->loadByEmail($customer->getEmail())){
+ $subscriber->subscribe($customer->getEmail());
+ }
+
$counter++;
}
return $customerArray;
@@ -88,7 +94,6 @@ protected function _buildCustomerData($customer)
$data["email_address"] = $this->getCustomerEmail($customer);
$data["first_name"] = $this->getCustomerFirstname($customer);
$data["last_name"] = $this->getCustomerLastname($customer);
- $data["opt_in_status"] = $this->optInStatusForStore;
$data["orders_count"] = (int)$customer->getOrdersCount();
$data["total_spent"] = (float)$customer->getTotalSpent();
From 29b4e48ea391baf85551b9180ffd3dc5c4ca209e Mon Sep 17 00:00:00 2001
From: keller
Date: Mon, 5 Nov 2018 11:56:21 -0300
Subject: [PATCH 023/113] #793 Tests corrected
---
.../MailChimp/Model/Api/Customers.php | 16 +++++++++++--
.../MailChimp/Model/Api/CustomersTest.php | 23 +++++++++++++++++--
2 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php
index 88fcb2f0f..9007eb7ed 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php
@@ -49,7 +49,7 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId)
$this->optInStatusForStore = $this->getOptin($this->getBatchMagentoStoreId());
- $subscriber = Mage::getModel('newsletter/subscriber');
+ $subscriber = $this->getSubscriberModel();
$counter = 0;
foreach ($customersCollection as $customer) {
@@ -62,7 +62,9 @@ public function createBatchJson($mailchimpStoreId, $magentoStoreId)
$this->logCouldNotEncodeCustomerError($customer);
}
- if ($this->optInStatusForStore && !$subscriber->loadByEmail($customer->getEmail())){
+ $isSubscribed = $subscriber->loadByEmail($customer->getEmail())->getSubscriberId();
+
+ if ($this->optInStatusForStore && !$isSubscribed){
$subscriber->subscribe($customer->getEmail());
}
@@ -97,6 +99,7 @@ protected function _buildCustomerData($customer)
$data["orders_count"] = (int)$customer->getOrdersCount();
$data["total_spent"] = (float)$customer->getTotalSpent();
+ $data["opt_in_status"] = false;
$data += $this->getCustomerAddressData($customer);
@@ -437,4 +440,13 @@ protected function setMagentoStoreId($magentoStoreId)
$this->magentoStoreId = $magentoStoreId;
}
+ /**
+ * @return false|Mage_Core_Model_Abstract
+ */
+ protected function getSubscriberModel()
+ {
+ $subscriber = Mage::getModel('newsletter/subscriber');
+ return $subscriber;
+ }
+
}
diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php
index 7c217474a..8db205bf2 100644
--- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php
+++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/CustomersTest.php
@@ -54,6 +54,8 @@ public function testGetOptInNoDefaultStore()
public function testCreateBatchJson()
{
$mailchimpStoreId = 'a1s2d3f4g5h6j7k8l9n0';
+ $customerEmail = 'keller@ebizmarts.com';
+ $subscriberId = 1;
$storeId = 1;
$optInStatus = true;
$customerId = 142;
@@ -77,7 +79,7 @@ public function testCreateBatchJson()
$this->customersApiMock = $this->customersApiMock->setMethods(
array('makeBatchId', 'joinMailchimpSyncData', 'makeCustomersNotSentCollection', 'getOptin',
'getBatchMagentoStoreId', '_buildCustomerData', 'makePutBatchStructure',
- '_updateSyncData', 'setMailchimpStoreId', 'setMagentoStoreId', 'getCustomerResourceCollection'
+ '_updateSyncData', 'setMailchimpStoreId', 'setMagentoStoreId', 'getCustomerResourceCollection', 'getSubscriberModel'
)
)
->getMock();
@@ -88,11 +90,27 @@ public function testCreateBatchJson()
$customerMock = $this->getMockBuilder(Mage_Customer_Model_Customer::class)
->disableOriginalConstructor()
- ->setMethods(array('getId'))
+ ->setMethods(array('getId', 'getEmail'))
->getMock();
+ $subscriberMock = $this->getMockBuilder(Mage_Newsletter_Model_Subscriber::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('loadByEmail'))
+ ->getMock();
+
+ $subscribersMailchimpMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Subscriber::class)
+ ->disableOriginalConstructor()
+ ->setMethods(array('getSubscriberId'))
+ ->getMock();
+
$customerArray = array($customerMock);
+ $this->customersApiMock->expects($this->once())->method('getSubscriberModel')->willReturn($subscriberMock);
+
+ $subscriberMock->expects($this->once())->method('loadByEmail')->with($customerEmail)->willReturn($subscribersMailchimpMock);
+
+ $subscribersMailchimpMock->expects($this->once())->method('getSubscriberId')->willReturn($subscriberId);
+
$this->customersApiMock->expects($this->once())->method('setMailchimpStoreId')->with($mailchimpStoreId);
$this->customersApiMock->expects($this->once())->method('setMagentoStoreId')->with($storeId);
@@ -112,6 +130,7 @@ public function testCreateBatchJson()
$this->customersApiMock->expects($this->once())->method('makePutBatchStructure')->with($customerJson)->willReturn($operationData);
$customerMock->expects($this->once())->method('getId')->willReturn($customerId);
+ $customerMock->expects($this->any())->method('getEmail')->willReturn($customerEmail);
$this->customersApiMock->expects($this->once())->method('_updateSyncData')->with($customerId, $mailchimpStoreId);
From 2ae9475e8a46067cd73a496f670455c6ef4304e4 Mon Sep 17 00:00:00 2001
From: keller
Date: Tue, 6 Nov 2018 10:39:16 -0300
Subject: [PATCH 024/113] #793 Override original subscribe method only if
extension is enabled
---
.../community/Ebizmarts/MailChimp/Model/Subscriber.php | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php b/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
index 3b980d3f5..4ac84fc6c 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
@@ -40,10 +40,11 @@ public function sendConfirmationSuccessEmail()
//Force double-opt in for registered customers if "Need to Confirm" is enabled
public function subscribe($email)
{
+ if (Mage::getStoreConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_ACTIVE)) {
$this->loadByEmail($email);
$customerSession = Mage::getSingleton('customer/session');
- if(!$this->getId()) {
+ if (!$this->getId()) {
$this->setSubscriberConfirmCode($this->randomSequence());
}
@@ -59,7 +60,7 @@ public function subscribe($email)
|| $this->getStatus() == self::STATUS_NOT_ACTIVE
) {
if ($isConfirmNeed === true) {
- $this->setStatus(self::STATUS_NOT_ACTIVE);
+ $this->setStatus(self::STATUS_NOT_ACTIVE);
} else {
$this->setStatus(self::STATUS_SUBSCRIBED);
}
@@ -90,5 +91,9 @@ public function subscribe($email)
} catch (Exception $e) {
throw new Exception($e->getMessage());
}
+ } else {
+ return parent::subscribe($email);
+ }
+
}
}
From e81e38f2aa1a2db7cbbcc0df568e7544b9cb1f98 Mon Sep 17 00:00:00 2001
From: Santiago
Date: Thu, 8 Nov 2018 17:54:54 -0300
Subject: [PATCH 025/113] Separate each template type.
---
.../Block/Checkout/Success/CheckboxGroups.php | 14 ++
.../Block/Checkout/Success/DropdownGroups.php | 14 ++
.../Block/Checkout/Success/Groups.php | 191 ++----------------
.../Block/Checkout/Success/RadioGroups.php | 14 ++
.../Block/Checkout/Success/SelectGroups.php | 14 ++
.../Ebizmarts/MailChimp/etc/system.xml | 2 -
.../default/layout/ebizmarts/mailchimp.xml | 6 +-
.../checkout/success/checkbox_groups.phtml | 19 ++
.../checkout/success/dropdown_groups.phtml | 15 ++
.../mailchimp/checkout/success/groups.phtml | 56 +----
.../checkout/success/radio_groups.phtml | 19 ++
11 files changed, 134 insertions(+), 230 deletions(-)
create mode 100644 app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/CheckboxGroups.php
create mode 100644 app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/DropdownGroups.php
create mode 100644 app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/RadioGroups.php
create mode 100644 app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/SelectGroups.php
create mode 100644 app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/checkbox_groups.phtml
create mode 100644 app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/dropdown_groups.phtml
create mode 100644 app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/radio_groups.phtml
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/CheckboxGroups.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/CheckboxGroups.php
new file mode 100644
index 000000000..cf43d3741
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/CheckboxGroups.php
@@ -0,0 +1,14 @@
+
+ * @license http://opensource.org/licenses/osl-3.0.php
+ */
+class Ebizmarts_MailChimp_Block_Checkout_Success_CheckboxGroups extends Ebizmarts_MailChimp_Block_Checkout_Success_Groups
+{
+
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/DropdownGroups.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/DropdownGroups.php
new file mode 100644
index 000000000..2ffe62f1e
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/DropdownGroups.php
@@ -0,0 +1,14 @@
+
+ * @license http://opensource.org/licenses/osl-3.0.php
+ */
+class Ebizmarts_MailChimp_Block_Checkout_Success_DropdownGroups extends Ebizmarts_MailChimp_Block_Checkout_Success_Groups
+{
+
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
index b9b8aeca2..7c8d8638a 100644
--- a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/Groups.php
@@ -4,19 +4,13 @@
* Checkout subscribe checkbox block renderer
*
* @category Ebizmarts
- * @package Ebizmarts_MageMonkey
+ * @package Ebizmarts_MailChimp
* @author Ebizmarts Team
* @license http://opensource.org/licenses/osl-3.0.php
*/
class Ebizmarts_MailChimp_Block_Checkout_Success_Groups extends Mage_Core_Block_Template
{
-
- protected $_lists = array();
- protected $_info = array();
- protected $_myLists = array();
- protected $_generalList = array();
- protected $_form;
- protected $_api;
+ protected $_currentIntesrest;
/**
* @var Ebizmarts_MailChimp_Helper_Data
*/
@@ -30,172 +24,6 @@ public function __construct()
$this->storeId = Mage::app()->getStore()->getId();
}
- /**
- * Get list data from MC
- *
- * @return array
- */
- public function getGeneralList()
- {
- $storeId = $this->storeId;
- $helper = $this->getMailChimpHelper();
- $listId = $helper->getGeneralList($storeId);
-
- return $listId;
- }
-
- public function getListInterestGroups()
- {
- $storeId = $this->storeId;
- $helper = $this->getMailChimpHelper();
- $return = $helper->getListInterestGroups($storeId);
- return $return;
- }
-
- public function getCategoryTitle($category)
- {
- return $category['title'];
- }
-
- public function renderGroups($category)
- {
- $object = $this->createObject($category);
-
- $this->addGroupOptions($category, $object);
-
- $html = $this->getElementHtml($category, $object);
-
- return $html;
- }
-
- public function getGroupClass($type)
- {
- switch ($type) {
- case 'radio':
- $class = 'Varien_Data_Form_Element_Radios';
- break;
- case 'checkboxes':
- $class = 'Varien_Data_Form_Element_Checkboxes';
- break;
- case 'dropdown':
- $class = 'Varien_Data_Form_Element_Select';
- break;
- default:
- $class = 'Varien_Data_Form_Element_Text';
- break;
- }
-
- return $class;
- }
-
- public function htmlGroupName($category)
- {
- $storeId = $this->storeId;
- $helper = $this->getMailChimpHelper();
- $listId = $helper->getGeneralList($storeId);
- $htmlName = "list[{$listId}]";
- $htmlName .= "[{$category['id']}]";
-
- if ($category['type'] == 'checkboxes') {
- $htmlName .= '[]';
- }
-
- return $htmlName;
- }
-
- /**
- * Form getter/instantiation
- *
- * @return Varien_Data_Form
- */
- public function getForm()
- {
- if ($this->_form instanceof Varien_Data_Form) {
- return $this->_form;
- }
- $form = new Varien_Data_Form();
- return $form;
- }
-
- /**
- * @param $category
- * @param $object
- */
- protected function addGroupOptions($category, $object)
- {
- $type = $category['type'];
-
- if ($type == 'checkboxes' || $type == 'dropdown') {
- $options = $this->createOptionArray($category);
-
- if (isset($category['groups'])) {
- foreach ($category['groups'] as $key => $group) {
- $options[$key] = $group;
- }
-
- $object->setValues($options);
- }
- }
- }
-
- /**
- * @param $category
- * @return mixed
- */
- protected function createOptionArray($category)
- {
- $options = array();
- $type = $category['type'];
-
- if ($type == 'dropdown') {
- $options[''] = $this->__('-- Select Group --');
- }
- return $options;
- }
-
- /**
- * @param $category
- * @param $html
- * @return string
- */
- protected function addGroupContainer($category, $html)
- {
- $type = $category['type'];
- if ($type != 'checkboxes') {
- $html = "{$html}
";
- }
- return $html;
- }
-
- /**
- * @param $category
- * @return mixed
- */
- protected function createObject($category)
- {
- $type = $category['type'];
- $class = $this->getGroupClass($type);
- $object = new $class;
- $object->setForm($this->getForm());
- $object->setName($this->htmlGroupName($category));
- $object->setHtmlId('interest-group');
-
- return $object;
- }
-
- /**
- * @param $category
- * @param $object
- * @return string
- */
- protected function getElementHtml($category, $object)
- {
- $html = $object->getElementHtml();
- $html = $this->addGroupContainer($category, $html);
-
- return $html;
- }
-
public function getFormUrl()
{
return $this->getSuccessInterestUrl();
@@ -214,9 +42,8 @@ public function getInterest()
$subscriber->loadByEmail($order->getCustomerEmail());
$subscriberId = $subscriber->getSubscriberId();
$customerId = $order->getCustomerId();
-
$helper = $this->getMailChimpHelper();
- $interest = $helper->getInterestGroups($customerId, $subscriberId,$order->getStoreId());
+ $interest = $helper->getInterestGroups($customerId, $subscriberId, $order->getStoreId());
return $interest;
}
@@ -256,4 +83,16 @@ protected function getMailChimpHelper()
return $this->helper;
}
+ /**
+ * @return mixed
+ */
+ protected function getCurrentInterest()
+ {
+ return $this->_currentIntesrest;
+ }
+
+ protected function setCurrentInterest($interest)
+ {
+ $this->_currentIntesrest = $interest;
+ }
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/RadioGroups.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/RadioGroups.php
new file mode 100644
index 000000000..f6d8b0901
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/RadioGroups.php
@@ -0,0 +1,14 @@
+
+ * @license http://opensource.org/licenses/osl-3.0.php
+ */
+class Ebizmarts_MailChimp_Block_Checkout_Success_RadioGroups extends Ebizmarts_MailChimp_Block_Checkout_Success_Groups
+{
+
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/SelectGroups.php b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/SelectGroups.php
new file mode 100644
index 000000000..4c9661204
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Checkout/Success/SelectGroups.php
@@ -0,0 +1,14 @@
+
+ * @license http://opensource.org/licenses/osl-3.0.php
+ */
+class Ebizmarts_MailChimp_Block_Checkout_Success_SelectGroups extends Ebizmarts_MailChimp_Block_Checkout_Success_Groups
+{
+
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/etc/system.xml b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
index dbdd1cdd6..d3e959581 100755
--- a/app/code/community/Ebizmarts/MailChimp/etc/system.xml
+++ b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
@@ -148,7 +148,6 @@
1
1
1
-
1
@@ -161,7 +160,6 @@
1
1
1
-
1
diff --git a/app/design/frontend/base/default/layout/ebizmarts/mailchimp.xml b/app/design/frontend/base/default/layout/ebizmarts/mailchimp.xml
index 513809c8c..489962854 100755
--- a/app/design/frontend/base/default/layout/ebizmarts/mailchimp.xml
+++ b/app/design/frontend/base/default/layout/ebizmarts/mailchimp.xml
@@ -55,7 +55,11 @@
+ template="ebizmarts/mailchimp/checkout/success/groups.phtml">
+
+
+
+
diff --git a/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/checkbox_groups.phtml b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/checkbox_groups.phtml
new file mode 100644
index 000000000..44e17f6a5
--- /dev/null
+++ b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/checkbox_groups.phtml
@@ -0,0 +1,19 @@
+getCurrentInterest();
+?>
+
diff --git a/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/dropdown_groups.phtml b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/dropdown_groups.phtml
new file mode 100644
index 000000000..280268ed5
--- /dev/null
+++ b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/dropdown_groups.phtml
@@ -0,0 +1,15 @@
+getCurrentInterest();
+?>
+
+
+
+
+ >
+
+
+
\ No newline at end of file
diff --git a/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/groups.phtml b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/groups.phtml
index c7608ec5e..d52ad6b51 100644
--- a/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/groups.phtml
+++ b/app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/success/groups.phtml
@@ -6,62 +6,16 @@ $interest = $block->getInterest();
getMessageBefore() ?>