Skip to content

Commit

Permalink
Merge branch 'develop' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiagoebizmarts authored Jul 22, 2019
2 parents 98c1456 + 5a854c0 commit b613647
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 39 deletions.
6 changes: 3 additions & 3 deletions app/code/community/Ebizmarts/MailChimp/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public function isMailChimpEnabled($scopeId, $scope = null)
*/
public function isUseMagentoEmailsEnabled($scopeId)
{
return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL, $scopeId);
return (int) $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MAGENTO_MAIL, $scopeId);
}

/**
Expand Down Expand Up @@ -2825,7 +2825,7 @@ public function updateSubscriberSyndData($itemId, $syncDelta = null, $syncError
if ($syncDeleted) {
$subscriber->setData("mailchimp_sync_deleted", $syncDeleted);
}
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE);
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::MAILCHIMP_SUBSCRIBE);
$subscriber->save();
}
}
Expand Down Expand Up @@ -3510,7 +3510,7 @@ public function unsubscribeMember($subscriber)
protected function setMemberGeneralData($subscriber)
{
$subscriber->setImportMode(true);
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE);
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::MAILCHIMP_SUBSCRIBE);
$subscriber->setIsStatusChanged(true);
$subscriber->save();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function createBatchJson($listId, $storeId, $limit)
$subscriber->setData("mailchimp_sync_delta", Varien_Date::now());
$subscriber->setData("mailchimp_sync_error", "");
$subscriber->setData("mailchimp_sync_modified", 0);
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE);
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::MAILCHIMP_SUBSCRIBE);
$subscriber->save();
}

Expand Down Expand Up @@ -288,7 +288,7 @@ public function updateSubscriber($subscriber, $updateStatus = false)
}

if ($saveSubscriber) {
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE);
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::MAILCHIMP_SUBSCRIBE);
$subscriber->save();
}
}
Expand Down
42 changes: 37 additions & 5 deletions app/code/community/Ebizmarts/MailChimp/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,17 @@ protected function isListXorStoreInherited($configData)
public function subscriberSaveBefore(Varien_Event_Observer $observer)
{
$subscriber = $observer->getEvent()->getSubscriber();
$subscriberSource = $subscriber->getSubscriberSource();
$storeId = $subscriber->getStoreId();
$helper = $this->makeHelper();
$isEnabled = $helper->isSubscriptionEnabled($storeId);

if ($isEnabled && $subscriber->getSubscriberSource() != Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE) {
if ($isEnabled && !$this->isMailchimpSave($subscriberSource)) {
$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) && !$helper->isUseMagentoEmailsEnabled($storeId)) {
if ($statusChanged && $subscriber->getStatus() == Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED &&
$helper->isSubscriptionConfirmationEnabled($storeId) && !$helper->isUseMagentoEmailsEnabled($storeId)) {
$subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE);
$this->addSuccessIfRequired($helper);
}
Expand All @@ -210,16 +212,19 @@ public function subscriberSaveAfter(Varien_Event_Observer $observer)
$storeViewId = $this->getStoreViewIdBySubscriber($subscriber);
$helper = $this->makeHelper();
$isEnabled = $helper->isSubscriptionEnabled($storeViewId);
$subscriberSource = $subscriber->getSubscriberSource();

if ($isEnabled && $subscriber->getSubscriberSource() != Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE) {
if ($isEnabled && !$this->isMailchimpSave($subscriberSource)) {
$params = $this->getRequest()->getParams();
$helper->saveInterestGroupData($params, $storeViewId, null, $subscriber);

$this->createEmailCookie($subscriber);

if ($helper->isUseMagentoEmailsEnabled($storeViewId) != 1) {
$apiSubscriber = $this->makeApiSubscriber();
$apiSubscriber = $this->makeApiSubscriber();

if ($helper->isUseMagentoEmailsEnabled($storeViewId) !== 1
&& $this->isMagentoSubscription($subscriberSource)
|| $this->isEmailConfirmationRequired($subscriberSource)) {
if ($subscriber->getIsStatusChanged()) {
$apiSubscriber->updateSubscriber($subscriber, true);
} else {
Expand Down Expand Up @@ -1167,4 +1172,31 @@ protected function getStoreViewIdBySubscriber($subscriber)
return $storeViewId;
}

/**
* @param string $subscriberSource
* @return bool
*/
protected function isEmailConfirmationRequired($subscriberSource)
{
return $subscriberSource === Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_CONFIRMATION;
}

/**
* @param string $subscriberSource
* @return bool
*/
protected function isMagentoSubscription($subscriberSource)
{
return empty($subscriberSource);
}

/**
* @param string $subscriberSource
* @return bool
*/
protected function isMailchimpSave($subscriberSource)
{
return $subscriberSource === Ebizmarts_MailChimp_Model_Subscriber::MAILCHIMP_SUBSCRIBE;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected function _updateEmail(array $data)
if (!$newSubscriber->getId()) {
if ($oldSubscriber->getId()) {
$oldSubscriber->setSubscriberEmail($new);
$oldSubscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE);
$oldSubscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::MAILCHIMP_SUBSCRIBE);
$oldSubscriber->save();
} else {
$helper->subscribeMember($newSubscriber);
Expand Down Expand Up @@ -236,7 +236,7 @@ public function _profile(array $data)
$saveRequired = true;
}
if ($saveRequired) {
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE);
$subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::MAILCHIMP_SUBSCRIBE);
$subscriber->save();
}
} else {
Expand Down
5 changes: 3 additions & 2 deletions app/code/community/Ebizmarts/MailChimp/Model/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
*/
class Ebizmarts_MailChimp_Model_Subscriber extends Mage_Newsletter_Model_Subscriber
{
const SUBSCRIBE_SOURCE = 'MailChimp';
const MAILCHIMP_SUBSCRIBE = 'MailChimp';
const SUBSCRIBE_CONFIRMATION = 'MailChimp_Confirmation';

public function sendUnsubscriptionEmail()
{
Expand Down Expand Up @@ -42,7 +43,7 @@ public function confirm($code)
if ($this->getCode()==$code) {
$this->setStatus(self::STATUS_SUBSCRIBED)
->setIsStatusChanged(true)
->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE)
->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_CONFIRMATION)
->save();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ class Ebizmarts_MailChimp_Model_System_Config_Source_WebhookDelete
*/
public function toOptionArray()
{
$mailchimpHelper = Mage::helper('mailchimp');

return array(
array('value' => 0, 'label' => Mage::helper('mailchimp')->__('Unsubscribe customers')),
array('value' => 1, 'label' => Mage::helper('mailchimp')->__('Delete customer account'))
array('value' => 0, 'label' => $mailchimpHelper->__('Unsubscribe')),
array('value' => 1, 'label' => $mailchimpHelper->__('Delete subscriber'))
);
}
}
18 changes: 9 additions & 9 deletions app/code/community/Ebizmarts/MailChimp/etc/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,15 @@
<show_in_store>1</show_in_store>
<comment><![CDATA[Click this button to create the webhook manually, it will only work if the webhook doesn't already exist.]]></comment>
</create_webhook>
<webhook_delete translate="label">
<label>Webhook Delete Subscriber Action</label>
<frontend_type>select</frontend_type>
<source_model>mailchimp/system_config_source_webhookDelete</source_model>
<sort_order>59</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</webhook_delete>
<webhook_active translate="label comment">
<label>Enable Two Way Sync</label>
<frontend_type>select</frontend_type>
Expand All @@ -242,15 +251,6 @@
<can_be_empty>1</can_be_empty>
<comment><![CDATA[If you enable this Magento confirmation email will be sent for subscribers instead of Mailchimp email.]]></comment>
</magento_mail>
<webhook_delete translate="label">
<label>Webhooks Delete action</label>
<frontend_type>select</frontend_type>
<source_model>mailchimp/system_config_source_webhookDelete</source_model>
<sort_order>70</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>1</show_in_store>
</webhook_delete>
<enable_log translate="label comment">
<label>Enable Log</label>
<frontend_type>select</frontend_type>
Expand Down
Loading

0 comments on commit b613647

Please sign in to comment.