Skip to content

Commit

Permalink
Removed array creation with [].
Browse files Browse the repository at this point in the history
Added title for displayed account data on configuration.
  • Loading branch information
Santiagoebizmarts committed Jun 6, 2016
1 parent d1dd797 commit f327a7b
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 6 deletions.
18 changes: 18 additions & 0 deletions app/code/community/Ebizmarts/MailChimp/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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()) {
Expand Down
38 changes: 38 additions & 0 deletions app/code/community/Ebizmarts/MailChimp/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ---')));
Expand Down
18 changes: 18 additions & 0 deletions app/code/community/Ebizmarts/MailChimp/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,24 @@
</Ebizmarts_MailChimp>
</modules>
<global>
<events>
<newsletter_subscriber_save_before>
<observers>
<monkey_subscribe_observer>
<class>mailchimp/observer</class>
<method>handleSubscriber</method>
</monkey_subscribe_observer>
</observers>
</newsletter_subscriber_save_before>
<newsletter_subscriber_delete_after>
<observers>
<monkey_subscribe_delete_observer>
<class>monkey/observer</class>
<method>handleSubscriberDeletion</method>
</monkey_subscribe_delete_observer>
</observers>
</newsletter_subscriber_delete_after>
</events>
<models>
<mailchimp>
<class>Ebizmarts_MailChimp_Model</class>
Expand Down

0 comments on commit f327a7b

Please sign in to comment.