From f327a7bb3ec0c394b88552a630c2a6f0709c0dc2 Mon Sep 17 00:00:00 2001 From: Santiago Date: Mon, 6 Jun 2016 11:00:35 -0300 Subject: [PATCH] Removed array creation with []. Added title for displayed account data on configuration. --- .../Ebizmarts/MailChimp/Helper/Data.php | 18 +++++++++ .../MailChimp/Model/Api/Customers.php | 4 +- .../Ebizmarts/MailChimp/Model/Observer.php | 38 +++++++++++++++++++ .../Model/System/Config/Source/Account.php | 9 +++-- .../Ebizmarts/MailChimp/etc/config.xml | 18 +++++++++ 5 files changed, 81 insertions(+), 6 deletions(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 99d67e7fb..7435a8741 100755 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -198,4 +198,22 @@ public function resetErrors() $connection->update($resource->getMainTable(),array('mailchimp_sync_error'=>'','mailchimp_sync_delta'=>'0000-00-00 00:00:00'),"mailchimp_sync_error <> ''"); } + /** + * Get status to send confirmation if Need to Confirm enabled on Magento + * + * @return string + */ + public function getStatus() + { + if($this->getConfigValue(Mage_Newsletter_Model_Subscriber::XML_PATH_CONFIRMATION_FLAG)) + { + $status = 'pending'; + } + else + { + $status = 'subscribed'; + } + return $status; + } + } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php index d447c9353..fdd446d88 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Customers.php @@ -94,7 +94,7 @@ protected function _buildCustomerData($customer) if (!array_key_exists("address", $data)) //send only first address { $street = $address->getStreet(); - $data["address"] = [ + $data["address"] = array( "address1" => $street[0], "address2" => count($street)>1 ? $street[1] : "", "city" => $address->getCity(), @@ -103,7 +103,7 @@ protected function _buildCustomerData($customer) "postal_code" => $address->getPostcode(), "country" => Mage::getModel('directory/country')->loadByCode($address->getCountry())->getName(), "country_code" => $address->getCountry() - ]; + ); //company if ($address->getCompany()) { diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php index 13842984b..3a73f2c7f 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php @@ -95,6 +95,44 @@ protected function _saveCustomerGroups($listId, $apiKey, $hookUrl) } } + public function handleSubscriber(Varien_Event_Observer $observer) + { + $isEnabled = Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_ACTIVE); + if($isEnabled){ + $subscriber = $observer->getEvent()->getSubscriber(); + if (TRUE === $subscriber->getIsStatusChanged()) { + $apiKey = Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_APIKEY); + $listId = Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_LIST); + //@Todo Create Api/Subscriber class for subscriber functions + $status = Mage::helper('mailchimp')->getStatus(); + $api = new Ebizmarts_Mailchimp($apiKey); + try { + $api->lists->members->add($listId, null, $status, $subscriber->getEmail()); + }catch (Exception $e){ + Mage::helper('mailchimp')->logError($e->getMessage()); + } + } + } + } + + public function handleSubscriberDeletion(Varien_Event_Observer $observer) + { + $isEnabled = Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_ACTIVE); + if($isEnabled){ + $subscriber = $observer->getEvent()->getSubscriber(); + if (TRUE === $subscriber->getIsStatusChanged()) { + $apiKey = Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_APIKEY); + $listId = Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_LIST); + $api = new Ebizmarts_Mailchimp($apiKey); + try { + $api->lists->members->add($listId, null, 'unsubscribed', $subscriber->getEmail()); + }catch (Exception $e){ + Mage::helper('mailchimp')->logError($e->getMessage()); + } + } + } + } + public function alterNewsletterGrid(Varien_Event_Observer $observer){ $block = $observer->getEvent()->getBlock(); 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 ea9ce7dc2..2d1e65a49 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 @@ -63,10 +63,11 @@ public function toOptionArray() return array( array('value' => 0, 'label' => Mage::helper('mailchimp')->__('Username:') . ' ' . $this->_account_details['account_name']), array('value' => 1, 'label' => Mage::helper('mailchimp')->__('Plan type:') . ' ' . ($this->_account_details['pro_enabled'] ? 'Pro' : 'Free')), - array('value' => 2, 'label' => Mage::helper('mailchimp')->__('Total Subscribers:') . ' ' . $this->_account_details['total_subscribers']), - array('value' => 3, 'label' => Mage::helper('mailchimp')->__('Total Customers:') . ' ' . $this->_account_details['total_customers']), - array('value' => 4, 'label' => Mage::helper('mailchimp')->__('Total Products:') . ' ' . $this->_account_details['total_products']), - array('value' => 5, 'label' => Mage::helper('mailchimp')->__('Total Orders:') . ' ' . $this->_account_details['total_orders']) + array('value' => 2, 'label' => Mage::helper('mailchimp')->__('Data uploaded to MailChimp:')), + array('value' => 3, 'label' => Mage::helper('mailchimp')->__(' Total Subscribers:') . ' ' . $this->_account_details['total_subscribers']), + array('value' => 4, 'label' => Mage::helper('mailchimp')->__(' Total Customers:') . ' ' . $this->_account_details['total_customers']), + array('value' => 5, 'label' => Mage::helper('mailchimp')->__(' Total Products:') . ' ' . $this->_account_details['total_products']), + array('value' => 6, 'label' => Mage::helper('mailchimp')->__(' Total Orders:') . ' ' . $this->_account_details['total_orders']) ); } elseif(!$this->_account_details) { return array(array('value' => '', 'label' => $helper->__('--- Enter your API KEY first ---'))); diff --git a/app/code/community/Ebizmarts/MailChimp/etc/config.xml b/app/code/community/Ebizmarts/MailChimp/etc/config.xml index 838462229..bc718d17f 100755 --- a/app/code/community/Ebizmarts/MailChimp/etc/config.xml +++ b/app/code/community/Ebizmarts/MailChimp/etc/config.xml @@ -7,6 +7,24 @@ + + + + + mailchimp/observer + handleSubscriber + + + + + + + monkey/observer + handleSubscriberDeletion + + + + Ebizmarts_MailChimp_Model