diff --git a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/System/Config/Account.php b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/System/Config/Account.php
index dd76eea7a..da1699901 100755
--- a/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/System/Config/Account.php
+++ b/app/code/community/Ebizmarts/MailChimp/Block/Adminhtml/System/Config/Account.php
@@ -13,16 +13,19 @@ class Ebizmarts_MailChimp_Block_Adminhtml_System_Config_Account extends Mage_Adm
{
protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
+ $firstErrorKey = Ebizmarts_MailChimp_Model_System_Config_Source_Account::NO_STORE_TEXT_KEY;
+ $firstMigrationKey = Ebizmarts_MailChimp_Model_System_Config_Source_Account::STORE_MIGRATION_TEXT_KEY;
+ $syncLabelKey = Ebizmarts_MailChimp_Model_System_Config_Source_Account::SYNC_LABEL_KEY;
$values = $element->getValues();
$html = '
';
foreach ($values as $dat) {
- if ($dat['value'] > 7 && $dat['value'] < 10) {
+ if ($dat['value'] >= $firstErrorKey && $dat['value'] < $firstMigrationKey) {
$html .= "- {$dat['label']}
";
- } elseif ($dat['value'] == 10) {
+ } elseif ($dat['value'] == $firstMigrationKey) {
$html .= "- {$dat['label']}
";
- } elseif($dat['value'] == 3) {
+ } elseif($dat['value'] == $syncLabelKey) {
$textArray = explode(':', $dat['label']);
if (strstr($textArray[1], $this->__('Finished'))) {
$html .= "- {$textArray[0]} : {$textArray[1]}
";
diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
index ee0120bbf..4b0a0143f 100755
--- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
+++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php
@@ -1029,29 +1029,42 @@ public function getMailChimpProductImageUrl($parentImageUrl, $productImageUrl)
* Returns product image url by id, if it does not have one returns null.
*
* @param $productId
+ * @param $magentoStoreId
* @return null
*/
- public function getImageUrlById($productId)
+ public function getImageUrlById($productId, $magentoStoreId)
{
- $productMediaConfig = $this->getProductMediaConfig();
- $product = $this->loadProductById($productId);
- $productImage = $product->getImage();
+ $model = Mage::getResourceModel('catalog/product');
+ $configImageSize = $this->getImageSize($magentoStoreId);
+
+ if ($configImageSize == 0) {
+ $productImage = $model->getAttributeRawValue($productId, 'image', $magentoStoreId);
+ } else if ($configImageSize == 1){
+ $productImage = $model->getAttributeRawValue($productId, 'small_image', $magentoStoreId);
+ } else {
+ $productImage = $model->getAttributeRawValue($productId, 'thumbnail', $magentoStoreId);
+ }
+
if ($productImage == 'no_selection' || $productImage == null) {
$imageUrl = null;
} else {
+ $oldStoreId = Mage::app()->getStore()->getId();
+ Mage::app()->setCurrentStore($magentoStoreId);
+ $productMediaConfig = $this->getProductMediaConfig();
$imageUrl = $productMediaConfig->getMediaUrl($productImage);
+ Mage::app()->setCurrentStore($oldStoreId);
}
return $imageUrl;
}
- private function getProductMediaConfig()
+ public function getImageSize($scopeId, $scope = null)
{
- return Mage::getModel('catalog/product_media_config');
+ return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_IMAGE_SIZE, $scopeId, $scope);
}
- private function loadProductById($productId)
+ private function getProductMediaConfig()
{
- return Mage::getModel('catalog/product')->load($productId);
+ return Mage::getModel('catalog/product_media_config');
}
/**
@@ -1126,9 +1139,14 @@ protected function getOrderCollectionByCustomerEmail($subscriberEmail)
public function getMCJs()
{
$script = '';
+ $url = null;
$storeId = Mage::app()->getStore()->getId();
if ($this->isEcomSyncDataEnabled($storeId)) {
- $url = $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $storeId);
+ $currentUrl = $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $storeId);
+ if ($this->areJsUrlAndListScopesEqual($storeId)) {
+ $url = $currentUrl;
+ }
+
if (!$url) {
$url = $this->getApiStores()->getMCJsUrl($storeId, 'stores');
}
@@ -1651,6 +1669,7 @@ public function loadListSubscriber($listId, $email)
$customer = $this->loadListCustomer($listId, $email);
if ($customer) {
$subscriber->setStoreId($customer->getStoreId());
+ $subscriber->setCustomerId($customer->getId());
} else {
/**
* No customer with that address. Just assume the first
@@ -1822,7 +1841,7 @@ public function getRealScopeForConfig($path, $scopeId, $scope = 'stores')
$scopeSoFar = null;
foreach ($configCollection as $config) {
//Discard possible extra website or store
- if ($this->isExtraEntry($config, $scope, $websiteId)) {
+ if ($this->isExtraEntry($config, $scope, $scopeId, $websiteId)) {
continue;
}
switch ($config->getScope()) {
@@ -1850,12 +1869,13 @@ public function getRealScopeForConfig($path, $scopeId, $scope = 'stores')
*
* @param $config
* @param $scope
+ * @param $scopeId
* @param $websiteId
* @return bool
*/
- protected function isExtraEntry($config, $scope, $websiteId)
+ protected function isExtraEntry($config, $scope, $scopeId, $websiteId)
{
- return $config->getScopeId() != 0 && (($config->getScope() == 'stores' && $scope != 'stores') || ($config->getScope() == 'websites' && $scope == 'stores' && $config->getScopeId() != $websiteId));
+ return $this->isNotDefaultScope($config) && ($this->isIncorrectScope($config, $scope) || $this->isDifferentWebsite($config, $scope, $websiteId) || $this->isDifferentStoreView($config, $scope, $scopeId));
}
public function updateSubscriberSyndData($itemId, $syncDelta = null, $syncError = null, $syncModified = 0, $syncDeleted = null)
@@ -2310,4 +2330,96 @@ public function getStorePhone($scopeId, $scope = 'stores')
{
return $this->getConfigValueForScope('general/store_information/phone', $scopeId, $scope);
}
+
+ public function getAllMailChimpStoreIds()
+ {
+ $collection = Mage::getResourceModel('core/config_data_collection')
+ ->addFieldToFilter('path', array('eq' => Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID));
+ $mailchimpStoreIdsArray = array();
+ foreach ($collection as $row) {
+ $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);
+ $subscriber->setSubscriberConfirmCode($subscriber->randomSequence());
+ if ($forceUpdateStatus) {
+ $subscriber->setMailchimpSyncModified(1);
+ }
+ $this->setMemberGeneralData($subscriber);
+ }
+
+ public function unsubscribeMember($subscriber)
+ {
+ $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
+ $this->setMemberGeneralData($subscriber);
+ }
+
+ protected function setMemberGeneralData($subscriber)
+ {
+ $subscriber->setImportMode(true);
+ $subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE);
+ $subscriber->setIsStatusChanged(true);
+ $subscriber->save();
+ }
+
+ /**
+ * @param $config
+ * @param $scope
+ * @param $scopeId
+ * @return bool
+ */
+ protected function isDifferentStoreView($config, $scope, $scopeId)
+ {
+ return $config->getScope() == 'stores' && $scope == 'stores' && $scopeId != $config->getScopeId();
+ }
+
+ /**
+ * @param $config
+ * @param $scope
+ * @param $websiteId
+ * @return bool
+ */
+ protected function isDifferentWebsite($config, $scope, $websiteId)
+ {
+ return ($config->getScope() == 'websites' && $scope == 'stores' && $config->getScopeId() != $websiteId);
+ }
+
+ /**
+ * @param $config
+ * @param $scope
+ * @return bool
+ */
+ protected function isIncorrectScope($config, $scope)
+ {
+ return ($config->getScope() == 'stores' && $scope != 'stores');
+ }
+
+ /**
+ * @param $config
+ * @return bool
+ */
+ protected function isNotDefaultScope($config)
+ {
+ return $config->getScopeId() != 0;
+ }
+
+ /**
+ * @param $storeId
+ * @return bool
+ */
+ protected function areJsUrlAndListScopesEqual($storeId)
+ {
+ $scopesMatch = false;
+ $realScopeList = Mage::helper('mailchimp')->getRealScopeForConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_LIST, $storeId);
+ $realScopeJs = Mage::helper('mailchimp')->getRealScopeForConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $storeId);
+ if ($realScopeList && $realScopeJs && $realScopeList['scope'] == $realScopeJs['scope'] && $realScopeList['scope_id'] == $realScopeJs['scope_id']) {
+ $scopesMatch = true;
+ }
+ return $scopesMatch;
+ }
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php
index 5338b88be..6e732c1a4 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Orders.php
@@ -406,14 +406,14 @@ protected function GeneratePOSTPayload($order, $mailchimpStoreId, $magentoStoreI
)
)
->addAttributeToFilter('customer_email', array('eq' => $order->getCustomerEmail()));
- $totalOrders = 1;
+ $totalOrders = 0;
$totalAmountSpent = (int)$order->getGrandTotal();
foreach ($orderCollection as $customerOrder) {
$totalOrders++;
$totalAmountSpent += ($customerOrder->getGrandTotal() - $customerOrder->getTotalRefunded() - $customerOrder->getTotalCanceled());
}
- $data["customer"]["orders_count"] = $totalOrders;
+ $data["customer"]["orders_count"] = (int)$totalOrders;
$data["customer"]["total_spent"] = $totalAmountSpent;
$jsonData = "";
//enconde to JSON
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php
index 8f3c1e6ab..b88b5cd90 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Products.php
@@ -220,7 +220,7 @@ protected function _buildProductData($product, $magentoStoreId, $isVariant = tru
$data["url"] = $url;
//image
- $imageUrl = $this->getMailChimpHelper()->getMailChimpProductImageUrl($this->_parentImageUrl, $this->getMailChimpHelper()->getImageUrlById($product->getId()));
+ $imageUrl = $this->getMailChimpHelper()->getMailChimpProductImageUrl($this->_parentImageUrl, $this->getMailChimpHelper()->getImageUrlById($product->getId(), $magentoStoreId));
if ($imageUrl) {
$data["image_url"] = $imageUrl;
}
@@ -236,11 +236,10 @@ protected function _buildProductData($product, $magentoStoreId, $isVariant = tru
$data["description"] = ($product->getDescription()) ? $product->getDescription() : $product->getDefaultDescription();
}
- //mailchimp product type (magento category)
- $categoryId = $product->getCategoryId();
- if ($categoryId) {
- $category = Mage::getResourceModel('catalog/category')->checkId($categoryId);
- $data["type"] = $category->getName();
+ //mailchimp product type and vendor (magento category)
+ $categoryName = $this->getProductCategories($product, $magentoStoreId);
+ if ($categoryName) {
+ $data["type"] = $categoryName;
$data["vendor"] = $data["type"];
}
@@ -257,7 +256,7 @@ protected function _buildProductData($product, $magentoStoreId, $isVariant = tru
if ($visibility != Mage_Catalog_Model_Product_Visibility::VISIBILITY_NOT_VISIBLE) {
$this->_parentUrl = $data['url'];
}
- $price = (float)$product->getDefaultPrice();
+ $price = ((float)$product->getPrice()) ? (float)$product->getPrice() : (float)$product->getDefaultPrice();
if ($price) {
$this->_parentPrice = $price;
}
@@ -522,13 +521,11 @@ public function joinProductAttributes($collection, $magentoStoreId)
foreach ($attributeCodes as $_code) {
$attributeName = $config->getAttribute("catalog_product", $_code);
- if ($_code != 'price') {
- $collection->joinField(
- $_code, $attributeName->getBackendTable(), 'value', 'entity_id = entity_id',
- '{{table}}.store_id = ' . $magentoStoreId . ' AND {{table}}.attribute_id = ' . $attributeName->getId(), 'left'
- );
- }
-
+ $collection->joinField(
+ $_code, $attributeName->getBackendTable(), 'value', 'entity_id = entity_id',
+ '{{table}}.store_id = ' . $magentoStoreId . ' AND {{table}}.attribute_id = ' . $attributeName->getId(), 'left'
+ );
+
$collection->joinField(
'default_' . $_code, $attributeName->getBackendTable(), 'value', 'entity_id = entity_id',
'{{table}}.store_id = 0 AND {{table}}.attribute_id = ' . $attributeName->getId(), 'left'
@@ -736,4 +733,27 @@ protected function getProductUrl($product, $magentoStoreId)
Mage::app()->setCurrentStore($oldStoreId);
return $url;
}
+
+ protected function getProductCategories($product, $magentoStoreId)
+ {
+ $categoryIds = $product->getCategoryIds();
+ $categoryNames = array();
+ $categoryName = null;
+ if (is_array($categoryIds) && count($categoryIds)) {
+ /* @var $collection Mage_Catalog_Model_Resource_Category_Collection */
+ $collection = Mage::getModel('catalog/category')->getCollection();
+ $collection->addAttributeToSelect(array('name'))
+ ->setStoreId($magentoStoreId)
+ ->addAttributeToFilter('is_active', array('eq'=>'1'))
+ ->addAttributeToFilter('entity_id', array('in' => $categoryIds))
+ ->addAttributeToSort('level', 'asc');
+
+ /* @var $category Mage_Catalog_Model_Category */
+ foreach ($collection as $category) {
+ $categoryNames[] = $category->getName();
+ }
+ $categoryName = (count($categoryNames)) ? implode(" - ", $categoryNames) : 'None';
+ }
+ return $categoryName;
+ }
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php
index df3291f30..f7598d34c 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Stores.php
@@ -109,11 +109,11 @@ public function getMCJsUrl($scopeId, $scope)
try {
$api = Mage::helper('mailchimp')->getApi($scopeId, $scope);
$mailchimpStoreId = Mage::helper('mailchimp')->getMCStoreId($scopeId, $scope);
- $response = $api->ecommerce->stores->get($mailchimpStoreId, 'connected_site');
+ $response = $this->getStoreConnectedSiteData($api, $mailchimpStoreId);
if (isset($response['connected_site']['site_script']['url'])) {
$url = $response['connected_site']['site_script']['url'];
$configValues = array(array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $url));
- $realScope = Mage::helper('mailchimp')->getRealScopeForConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $scopeId, $scope);
+ $realScope = Mage::helper('mailchimp')->getRealScopeForConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_LIST, $scopeId, $scope);
Mage::helper('mailchimp')->saveMailchimpConfig($configValues, $realScope['scope_id'], $realScope['scope']);
return $url;
}
@@ -139,4 +139,15 @@ public function editIsSyncing($mailchimpApi, $isSincingValue, $mailchimpStoreId,
$configValue = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING, (int)$isSincingValue));
Mage::helper('mailchimp')->saveMailchimpConfig($configValue, $scopeToEdit['scope_id'], $scopeToEdit['scope']);
}
+
+ /**
+ * @param $api
+ * @param $mailchimpStoreId
+ * @return mixed
+ */
+ protected function getStoreConnectedSiteData($api, $mailchimpStoreId)
+ {
+ $response = $api->ecommerce->stores->get($mailchimpStoreId, 'connected_site');
+ return $response;
+ }
}
\ No newline at end of file
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php
index 969fbe2f6..2ebe3e037 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Subscribers.php
@@ -105,7 +105,11 @@ protected function _buildSubscriberData($subscriber)
$data["merge_fields"] = $mergeVars;
}
- $data["status_if_new"] = $this->translateMagentoStatusToMailchimpStatus($subscriber->getStatus(), $storeId);
+ $status = $this->translateMagentoStatusToMailchimpStatus($subscriber->getStatus(), $storeId);
+ $data["status_if_new"] = $status;
+ if ($subscriber->getMailchimpSyncModified()) {
+ $data["status"] = $status;
+ }
$data["language"] = $helper->getStoreLanguageCode($storeId);
return $data;
@@ -300,6 +304,20 @@ public function getMergeVars($subscriber)
}
}
+ $newVars = new Varien_Object;
+
+ Mage::dispatchEvent(
+ 'mailchimp_merge_field_send_after', array(
+ 'subscriber' => $subscriber,
+ 'vars' => $mergeVars,
+ 'new_vars' => $newVars
+ )
+ );
+
+ if ($newVars->hasData()) {
+ $mergeVars = array_merge($mergeVars, $newVars->getData());
+ }
+
return (!empty($mergeVars)) ? $mergeVars : null;
}
@@ -309,6 +327,7 @@ public function getMergeVars($subscriber)
*/
public function updateSubscriber($subscriber, $updateStatus = false)
{
+ $isAdmin = Mage::app()->getStore()->isAdmin();
$helper = $this->mcHelper;
$storeId = $subscriber->getStoreId();
$listId = $helper->getGeneralList($storeId);
@@ -335,21 +354,19 @@ public function updateSubscriber($subscriber, $updateStatus = false)
Mage::getSingleton('core/session')->addWarning($message);
} catch (MailChimp_Error $e) {
$helper->logError($e->getFriendlyMessage(), $storeId);
- Mage::getSingleton('core/session')->addError($e->getFriendlyMessage());
+ $this->addError($isAdmin, $e);
$subscriber->unsubscribe();
- $this->_processUpdateSubscriberError($e, $storeId);
} catch (Exception $e) {
$helper->logError($e->getMessage(), $storeId);
}
} else {
$helper->logError($e->getFriendlyMessage(), $storeId);
- Mage::getSingleton('core/session')->addError($e->getFriendlyMessage());
+ $this->addError($isAdmin, $e);
$subscriber->unsubscribe();
- $this->_processUpdateSubscriberError($e, $storeId);
}
} else {
$helper->logError($e->getFriendlyMessage(), $storeId);
- Mage::getSingleton('core/session')->addError($e->getFriendlyMessage());
+ $this->addError($isAdmin, $e);
}
} catch (Exception $e) {
$helper->logError($e->getMessage(), $storeId);
@@ -507,4 +524,15 @@ protected function getAddressData($address)
}
return $addressData;
}
+
+ /**
+ * @param $isAdmin
+ * @param $e
+ */
+ protected function addError($isAdmin, $e)
+ {
+ if ($isAdmin) {
+ Mage::getSingleton('core/session')->addError($e->getFriendlyMessage());
+ }
+ }
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Config.php b/app/code/community/Ebizmarts/MailChimp/Model/Config.php
index f2efa8d2d..7cd058788 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Config.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Config.php
@@ -49,6 +49,7 @@ class Ebizmarts_MailChimp_Model_Config
const ECOMMERCE_CUSTOMER_AMOUNT = 'mailchimp/ecommerce/customer_batch_amount';
const ECOMMERCE_PRODUCT_AMOUNT = 'mailchimp/ecommerce/product_batch_amount';
const ECOMMERCE_ORDER_AMOUNT = 'mailchimp/ecommerce/order_batch_amount';
+ const ECOMMERCE_IMAGE_SIZE = 'mailchimp/ecommerce/image_size';
const ENABLE_POPUP = 'mailchimp/emailcatcher/popup_general';
const POPUP_HEADING = 'mailchimp/emailcatcher/popup_heading';
@@ -80,4 +81,4 @@ class Ebizmarts_MailChimp_Model_Config
const IS_ORDER = "ORD";
const IS_QUOTE = "QUO";
const IS_SUBSCRIBER = "SUB";
-}
\ No newline at end of file
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Cron.php b/app/code/community/Ebizmarts/MailChimp/Model/Cron.php
index 4f8e5ea97..80dd3ea59 100644
--- a/app/code/community/Ebizmarts/MailChimp/Model/Cron.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Cron.php
@@ -41,8 +41,13 @@ public function processWebhookData($cron)
Mage::getModel('mailchimp/processWebhook')->processWebhookData();
}
+ public function deleteWebhookRequests($cron)
+ {
+ Mage::getModel('mailchimp/processWebhook')->deleteProcessed();
+ }
+
private function getHelper()
{
return $this->mailChimpHelper;
}
-}
\ 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 a47c9a1a7..3b88e4e67 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php
@@ -209,20 +209,16 @@ public function saveCampaignData(Varien_Event_Observer $observer)
public function orderSaveBefore(Varien_Event_Observer $observer)
{
$order = $observer->getEvent()->getOrder();
- $storeId = Mage::app()->getStore()->getStoreId();
-
- //update mailchimp ecommerce data for that product variant
- Mage::getModel('mailchimp/api_orders')->update($order->getId(), $storeId);
+ $this->handleOrderUpdate($order);
}
/**
- * Delete campaign cookie after it was added to the order object.
+ * Delete campaign and landing cookies.
*
- * @param Varien_Event_Observer $observer
* @return Varien_Event_Observer
* @throws Exception
*/
- public function removeCampaignData(Varien_Event_Observer $observer)
+ public function removeCampaignData()
{
if ($this->_getCampaignCookie()) {
Mage::getModel('core/cookie')->delete('mailchimp_campaign_id');
@@ -231,8 +227,6 @@ public function removeCampaignData(Varien_Event_Observer $observer)
if ($this->_getLandingCookie()) {
Mage::getModel('core/cookie')->delete('mailchimp_landing_page');
}
-
- return $observer;
}
/**
@@ -343,16 +337,11 @@ public function newOrder(Varien_Event_Observer $observer)
$email = $order->getCustomerEmail();
$subscriber = $helper->loadListSubscriber($post, $email);
if ($subscriber) {
- Mage::getModel('mailchimp/processWebhook')->subscribeMember($subscriber);
+ $helper->subscribeMember($subscriber, true);
}
}
- if(($this->_getLandingCookie())) {
- Mage::getModel('core/cookie')->delete('mailchimp_landing_page');
- }
- if ($this->_getCampaignCookie()) {
- Mage::getModel('core/cookie')->delete('mailchimp_campaign_id');
- }
+ $this->removeCampaignData();
$order = $observer->getEvent()->getOrder();
$items = $order->getAllItems();
@@ -524,4 +513,38 @@ protected function makeApiProducts()
{
return Mage::getModel('mailchimp/api_products');
}
+
+ /**
+ * @param $order
+ */
+ protected function handleAdminOrderUpdate($order)
+ {
+ $mailchimpStoreIdsArray = $this->makeHelper()->getAllMailChimpStoreIds();
+ foreach ($mailchimpStoreIdsArray as $scopeData => $mailchimpStoreId) {
+ $scopeArray = explode('_', $scopeData);
+ if ($scopeArray[0] != 'websites') {
+ Mage::getModel('mailchimp/api_orders')->update($order->getId(), $scopeArray[1]);
+ } else {
+ $website = Mage::getModel('core/website')->load($scopeArray[1]);
+ $storeIds = $website->getStoreIds();
+ foreach ($storeIds as $storeId) {
+ Mage::getModel('mailchimp/api_orders')->update($order->getId(), $storeId);
+ }
+ }
+ }
+ }
+
+ /**
+ * @param $order
+ */
+ protected function handleOrderUpdate($order)
+ {
+ $storeId = Mage::app()->getStore()->getStoreId();
+
+ if ($storeId == 0) {
+ $this->handleAdminOrderUpdate($order);
+ } else {
+ Mage::getModel('mailchimp/api_orders')->update($order->getId(), $storeId);
+ }
+ }
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php b/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php
index eacf0b073..056cb92ab 100755
--- a/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php
+++ b/app/code/community/Ebizmarts/MailChimp/Model/ProcessWebhook.php
@@ -13,6 +13,7 @@
class Ebizmarts_MailChimp_Model_ProcessWebhook
{
const BATCH_LIMIT = 200;
+ private $helper;
/**
* Webhooks request url path
*
@@ -21,6 +22,16 @@ class Ebizmarts_MailChimp_Model_ProcessWebhook
const WEBHOOKS_PATH = 'mailchimp/webhook/index/';
+ public function __construct()
+ {
+ $this->helper = Mage::helper('mailchimp');
+ }
+
+ protected function getHelper()
+ {
+ return $this->helper;
+ }
+
public function saveWebhookRequest(array $data)
{
Mage::getModel('mailchimp/webhookrequest')
@@ -73,12 +84,13 @@ public function processWebhookData()
*/
protected function _updateEmail(array $data)
{
+ $helper = $this->getHelper();
$listId = $data['list_id'];
$old = $data['old_email'];
$new = $data['new_email'];
- $oldSubscriber = Mage::helper('mailchimp')->loadListSubscriber($listId, $old);
- $newSubscriber = Mage::helper('mailchimp')->loadListSubscriber($listId, $new);
+ $oldSubscriber = $helper->loadListSubscriber($listId, $old);
+ $newSubscriber = $helper->loadListSubscriber($listId, $new);
if ($oldSubscriber) {
if (!$newSubscriber->getId()) {
@@ -87,7 +99,7 @@ protected function _updateEmail(array $data)
$oldSubscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE);
$oldSubscriber->save();
} else {
- $this->subscribeMember($newSubscriber);
+ $helper->subscribeMember($newSubscriber);
}
}
}
@@ -102,7 +114,8 @@ protected function _updateEmail(array $data)
protected function _clean(array $data)
{
//Delete subscriber from Magento
- $s = Mage::helper('mailchimp')->loadListSubscriber($data['list_id'], $data['email']);
+ $helper = $this->getHelper();
+ $s = $helper->loadListSubscriber($data['list_id'], $data['email']);
if ($s && $s->getId()) {
try {
@@ -121,14 +134,15 @@ protected function _clean(array $data)
*/
protected function _subscribe(array $data)
{
+ $helper = $this->getHelper();
try {
$listId = $data['list_id'];
$email = $data['email'];
- $subscriber = Mage::helper('mailchimp')->loadListSubscriber($listId, $email);
+ $subscriber = $helper->loadListSubscriber($listId, $email);
if ($subscriber) {
if ($subscriber->getId()) {
if ($subscriber->getSubscriberStatus() != Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
- $this->subscribeMember($subscriber);
+ $helper->subscribeMember($subscriber);
}
} else {
if (isset($data['merges']['FNAME'])) {
@@ -140,7 +154,7 @@ protected function _subscribe(array $data)
$subscriberLname = filter_var($data['merges']['LNAME'], FILTER_SANITIZE_STRING);
$subscriber->setSubscriberLastname($subscriberLname);
}
- $this->subscribeMember($subscriber);
+ $helper->subscribeMember($subscriber);
}
}
} catch (Exception $e) {
@@ -148,27 +162,6 @@ protected function _subscribe(array $data)
}
}
- public function subscribeMember($subscriber)
- {
- $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
- $subscriber->setSubscriberConfirmCode($subscriber->randomSequence());
- $this->setMemberGeneralData($subscriber);
- }
-
- protected function unsubscribeMember($subscriber)
- {
- $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED);
- $this->setMemberGeneralData($subscriber);
- }
-
- protected function setMemberGeneralData($subscriber)
- {
- $subscriber->setImportMode(true);
- $subscriber->setSubscriberSource(Ebizmarts_MailChimp_Model_Subscriber::SUBSCRIBE_SOURCE);
- $subscriber->setIsStatusChanged(true);
- $subscriber->save();
- }
-
/**
* Unsubscribe or delete email from Magento list, store aware
*
@@ -177,7 +170,8 @@ protected function setMemberGeneralData($subscriber)
*/
protected function _unsubscribe(array $data)
{
- $subscriber = Mage::helper('mailchimp')->loadListSubscriber($data['list_id'], $data['email']);
+ $helper = $this->getHelper();
+ $subscriber = $helper->loadListSubscriber($data['list_id'], $data['email']);
if ($subscriber && $subscriber->getId()) {
try {
$action = isset($data['action']) ? $data['action'] : 'delete';
@@ -187,12 +181,12 @@ protected function _unsubscribe(array $data)
if (Mage::getStoreConfig("mailchimp/general/webhook_delete", $subscriber->getStoreId())) {
$subscriber->delete();
} elseif ($subscriber->getSubscriberStatus() != Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) {
- $this->unsubscribeMember($subscriber);
+ $helper->unsubscribeMember($subscriber);
}
break;
case 'unsub':
if ($subscriber->getSubscriberStatus() != Mage_Newsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) {
- $this->unsubscribeMember($subscriber);
+ $helper->unsubscribeMember($subscriber);
}
break;
}
@@ -204,11 +198,12 @@ protected function _unsubscribe(array $data)
protected function _profile(array $data)
{
+ $helper = $this->getHelper();
$listId = $data['list_id'];
$email = $data['email'];
$fname = isset($data['merges']['FNAME']) ? $data['merges']['FNAME'] : null;
$lname = isset($data['merges']['LNAME']) ? $data['merges']['LNAME'] : null;
- $customer = Mage::helper('mailchimp')->loadListCustomer($listId, $email);
+ $customer = $helper->loadListCustomer($listId, $email);
$saveRequired = false;
if ($customer) {
if ($fname && $fname !== $customer->getFirstname()) {
@@ -223,7 +218,7 @@ protected function _profile(array $data)
$customer->save();
}
} else {
- $subscriber = Mage::helper('mailchimp')->loadListSubscriber($listId, $email);
+ $subscriber = $helper->loadListSubscriber($listId, $email);
if ($subscriber) {
if ($subscriber->getId()) {
if ($fname && $fname !== $subscriber->getSubscriberFirstname()) {
@@ -243,27 +238,45 @@ protected function _profile(array $data)
* Mailchimp subscriber not currently in magento newsletter subscribers.
* Get mailchimp subscriber status and add missing newsletter subscriber.
*/
- $api = Mage::helper('mailchimp')->getApi($subscriber->getStoreId());
+ $api = $helper->getApi($subscriber->getStoreId());
try {
$subscriber->setSubscriberFirstname($fname);
$subscriber->setSubscriberLastname($lname);
$md5HashEmail = md5(strtolower($email));
$member = $api->lists->members->get($listId, $md5HashEmail, null, null);
if ($member['status'] == 'subscribed') {
- $this->subscribeMember($subscriber);
+ $helper->subscribeMember($subscriber);
} elseif ($member['status'] == 'unsubscribed') {
if (!Mage::getStoreConfig("mailchimp/general/webhook_delete", $subscriber->getStoreId())) {
- $this->unsubscribeMember($subscriber);
+ $helper->unsubscribeMember($subscriber);
}
}
} catch (MailChimp_Error $e) {
- Mage::helper('mailchimp')->logError($e->getFriendlyMessage(), $subscriber->getStoreId());
+ $helper->logError($e->getFriendlyMessage(), $subscriber->getStoreId());
} catch (Exception $e) {
- Mage::helper('mailchimp')->logError($e->getMessage(), $subscriber->getStoreId());
+ $helper->logError($e->getMessage(), $subscriber->getStoreId());
}
}
}
}
}
+ public function deleteProcessed()
+ {
+ $to= Mage::app()->getLocale()->date()->sub(30,Zend_Date::DAY);
+ $to=$to->toString('yyyy-MM-dd');
+
+ $collection = Mage::getModel('mailchimp/webhookrequest')->getCollection()
+ ->addFieldToFilter('processed', 1)
+ ->addFieldToFilter('fired_at', array(
+ 'lt'=>$to
+ ));
+ $collection->getSelect()->limit(self::BATCH_LIMIT);
+
+ foreach ($collection as $row) {
+ $row->delete();
+ }
+
+ }
+
}
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 eb837b878..694e6c90e 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
@@ -21,6 +21,18 @@ class Ebizmarts_MailChimp_Model_System_Config_Source_Account
*/
protected $_accountDetails = false;
protected $helper;
+ const USERNAME_KEY = 0;
+ const TOTAL_ACCOUNT_SUB_KEY = 1;
+ const TOTAL_LIST_SUB_KEY = 2;
+ const STORENAME_KEY = 10;
+ const SYNC_LABEL_KEY = 11;
+ const TOTAL_CUS_KEY = 12;
+ const TOTAL_PRO_KEY = 13;
+ const TOTAL_ORD_KEY = 14;
+ const TOTAL_QUO_KEY = 15;
+ const NO_STORE_TEXT_KEY = 20;
+ const NEW_STORE_TEXT_KEY = 21;
+ const STORE_MIGRATION_TEXT_KEY = 30;
/**
* Set AccountDetails on class property if not already set
@@ -36,6 +48,8 @@ public function __construct()
if ($api) {
try {
$this->_accountDetails = $api->root->info('account_name,total_subscribers');
+ $listData = $api->lists->getLists($listId, 'stats');
+ $this->_accountDetails['list_subscribers'] = $listData['stats']['member_count'];
if ($mcStoreId && $helper->getIfConfigExistsForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scopeArray[1], $scopeArray[0])) {
try {
$storeData = $api->ecommerce->stores->get($mcStoreId, 'name,is_syncing');
@@ -80,12 +94,15 @@ public function toOptionArray()
$helper = $this->helper;
$scopeArray = explode('-', $helper->getScopeString());
if (is_array($this->_accountDetails)) {
- $totalSubscribersText = $helper->__('Total subscribers:');
- $totalSubscribers = $totalSubscribersText . ' ' . $this->_accountDetails['total_subscribers'];
+ $totalAccountSubscribersText = $helper->__('Total Account Subscribers:');
+ $totalAccountSubscribers = $totalAccountSubscribersText . ' ' . $this->_accountDetails['total_subscribers'];
+ $totalListSubscribersText = $helper->__('Total List Subscribers:');
+ $totalListSubscribers = $totalListSubscribersText . ' ' . $this->_accountDetails['list_subscribers'];
$username = $helper->__('Username:') . ' ' . $this->_accountDetails['account_name'];
$returnArray = array(
- array('value' => 0, 'label' => $username),
- array('value' => 1, 'label' => $totalSubscribers)
+ array('value' => self::USERNAME_KEY, 'label' => $username),
+ array('value' => self::TOTAL_ACCOUNT_SUB_KEY, 'label' => $totalAccountSubscribers),
+ array('value' => self::TOTAL_LIST_SUB_KEY, 'label' => $totalListSubscribers)
);
if ($this->_accountDetails['store_exists']) {
$totalCustomersText = $helper->__(' Total Customers:');
@@ -106,12 +123,12 @@ public function toOptionArray()
$returnArray = array_merge(
$returnArray,
array(
- array('value' => 2, 'label' => $title),
- array('value' => 3, 'label' => $syncLabel),
- array('value' => 4, 'label' => $totalCustomers),
- array('value' => 5, 'label' => $totalProducts),
- array('value' => 6, 'label' => $totalOrders),
- array('value' => 7, 'label' => $totalCarts)
+ array('value' => self::STORENAME_KEY, 'label' => $title),
+ array('value' => self::SYNC_LABEL_KEY, 'label' => $syncLabel),
+ array('value' => self::TOTAL_CUS_KEY, 'label' => $totalCustomers),
+ array('value' => self::TOTAL_PRO_KEY, 'label' => $totalProducts),
+ array('value' => self::TOTAL_ORD_KEY, 'label' => $totalOrders),
+ array('value' => self::TOTAL_QUO_KEY, 'label' => $totalCarts)
)
);
} elseif ($helper->isEcomSyncDataEnabled($scopeArray[1], $scopeArray[0], true)) {
@@ -120,8 +137,8 @@ public function toOptionArray()
$returnArray = array_merge(
$returnArray,
array(
- array('value' => 8, 'label' => $noStoreText),
- array('value' => 9, 'label' => $newStoreText)
+ array('value' => self::NO_STORE_TEXT_KEY, 'label' => $noStoreText),
+ array('value' => self::NEW_STORE_TEXT_KEY, 'label' => $newStoreText)
)
);
}
@@ -131,7 +148,7 @@ public function toOptionArray()
$returnArray = array_merge(
$returnArray,
array(
- array('value' => 10, 'label' => $storeMigrationText)
+ array('value' => self::STORE_MIGRATION_TEXT_KEY, 'label' => $storeMigrationText)
)
);
}
diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/ImageSize.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/ImageSize.php
new file mode 100644
index 000000000..b1373fef4
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/ImageSize.php
@@ -0,0 +1,32 @@
+
+ * @license http://opensource.org/licenses/osl-3.0.php
+ */
+class Ebizmarts_MailChimp_Model_System_Config_Source_ImageSize
+{
+ const BASE = 0;
+ const SMALL = 1;
+ const THUMBNAIL = 2;
+
+
+ /**
+ * Options getter
+ *
+ * @return array
+ */
+ public function toOptionArray()
+ {
+ $helper = Mage::helper('mailchimp');
+ return array(
+ array('value' => self::BASE, 'label' => $helper->__('Base')),
+ array('value' => self::SMALL, 'label' => $helper->__('Small')),
+ array('value' => self::THUMBNAIL, 'label' => $helper->__('Thumbnail'))
+
+ );
+ }
+}
diff --git a/app/code/community/Ebizmarts/MailChimp/etc/config.xml b/app/code/community/Ebizmarts/MailChimp/etc/config.xml
index 9196a714a..6ddf7659a 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.9.1
+ 1.1.9.2
- 1.1.9.1
+ 1.1.9.2
@@ -366,6 +366,14 @@
mailchimp/cron::processWebhookData
+
+
+ 0 0 * * *
+
+
+ mailchimp/cron::deleteWebhookRequests
+
+
diff --git a/app/code/community/Ebizmarts/MailChimp/etc/system.xml b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
index ece559afc..6572470b4 100755
--- a/app/code/community/Ebizmarts/MailChimp/etc/system.xml
+++ b/app/code/community/Ebizmarts/MailChimp/etc/system.xml
@@ -225,11 +225,23 @@
1
+
+
+ select
+ mailchimp/system_config_source_imageSize
+ 209
+ 1
+ 1
+ 1
+
+ 1
+
+
date
mailchimp/adminhtml_system_config_date
- 209
+ 210
1
1
1
diff --git a/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.9.1-1.1.9.2.php b/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.9.1-1.1.9.2.php
new file mode 100755
index 000000000..a08c3f847
--- /dev/null
+++ b/app/code/community/Ebizmarts/MailChimp/sql/mailchimp_setup/mysql4-upgrade-1.1.9.1-1.1.9.2.php
@@ -0,0 +1,7 @@
+deleteConfigData(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL);
+
+$installer->endSetup();
\ No newline at end of file
diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php
index e3c707e19..72db51486 100644
--- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php
+++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/ProductsTest.php
@@ -97,20 +97,20 @@ private function productCollection()
"getProductUrl",
"getDescription",
"getDefaultDescription",
- "getCategoryId",
+ "getCategoryIds"
)
)
->getMock();
$productMock->method('_getResource')->willReturn(new Varien_Object());
$productMock->expects($this->once())->method('getMailchimpSyncDeleted')->willReturn(null);
$productMock->expects($this->any())->method('getId')->willReturn(self::PRODUCT_ID);
- $productMock->expects($this->exactly(3))->method('getTypeId')->willReturn("configurable");
+ $productMock->expects($this->exactly(4))->method('getTypeId')->willReturn("configurable");
$productMock->expects($this->exactly(2))->method('getName')->willReturn(null);
$productMock->expects($this->exactly(2))->method('getDefaultName')->willReturn("Lorem ipsum dolor sit amet 445452340");
$productMock->expects($this->exactly(2))->method('getProductUrl')->willReturn("http://a.example");
$productMock->expects($this->exactly(2))->method('getDescription')->willReturn(null);
$productMock->expects($this->exactly(2))->method('getDefaultDescription')->willReturn("Lorem ipsum dolor sit amet. LONG");
- $productMock->expects($this->once())->method('getCategoryId')->willReturn(null);
+ $productMock->expects($this->once())->method('getCategoryIds')->willReturn(null);
$products []= $productMock;
@@ -168,4 +168,4 @@ private function configurableNoChildren()
{
return \Ebizmarts_MailChimp_Model_Api_Products::$noChildrenIds;
}
-}
\ No newline at end of file
+}
diff --git a/js/ebizmarts/mailchimp/campaignCatcher.js b/js/ebizmarts/mailchimp/campaignCatcher.js
index 9b700f38d..0ed903d26 100755
--- a/js/ebizmarts/mailchimp/campaignCatcher.js
+++ b/js/ebizmarts/mailchimp/campaignCatcher.js
@@ -1,9 +1,9 @@
-function getCampaign()
-{
- var urlparams = location.search.substr(1).split('&');
- var params = new Array();
- var mc_cid = null;
- var isMailchimp = false;
+function getCampaign() {
+ var urlparams = location.search.substr(1).split('&');
+ var params = new Array();
+ var mc_cid = null;
+ var campaign = null;
+ var isMailchimp = false;
for (var i = 0; i < urlparams.length; i++) {
var param = urlparams[i].split('=');
var key = param[0];
@@ -11,30 +11,32 @@ function getCampaign()
if (key && val) {
params[key] = val;
}
-
- if(key=='utm_source') {
+ if (key == 'utm_source') {
var reg = /^mailchimp$/;
- if(reg.exec(val)) {
+ if (reg.exec(val)) {
isMailchimp = true;
}
}
- else {
- if (key=='mc_cid') {
- mc_cid = val;
- }
+ if (key == 'mc_cid') {
+ mc_cid = val;
+ }
+ if (key == 'utm_campaign') {
+ var campaignArray = val.split("-");
+ var campaignValue = campaignArray[0];
+ if (campaignValue.length == 10)
+ campaign = campaignValue;
}
}
-
- if (mc_cid&&!isMailchimp) {
- Mage.Cookies.set('mailchimp_campaign_id' , mc_cid);
- Mage.Cookies.set('mailchimp_landing_page', location);
- }
-
- if(isMailchimp) {
- Mage.Cookies.clear('mailchimp_campaign_id');
- Mage.Cookies.set('mailchimp_landing_page', location);
+ if (mc_cid) {
+ Mage.Cookies.set('mailchimp_campaign_id', mc_cid);
+ } else {
+ if (campaign) {
+ Mage.Cookies.set('mailchimp_campaign_id', campaign);
+ }
}
+ Mage.Cookies.set('mailchimp_landing_page', location);
}
+
if (document.loaded) {
getCampaign;
} else {