Our client wanted to integrate mailchimp with magento. So I dig for extension and found this awesome free magento extension called mageMonkey. I installed it through magento connect using key: http://connect20.magentocommerce.com/community/Ebizmarts_MageMonkey
I was able to sync Firstname, Lastname and Email but it didn't work for other fields. Specially street name came as 'Array' instead of actual street name.
So tried to update this file: trunk/app/code/community/Ebizmarts/MageMonkey/Model/MCAPI.php and added new function _merge_vars as:
function _merge_vars($merge_vars=NULL){ $params = array(); if(is_array($merge_vars)){ foreach($merge_vars as $k => $v){ if(is_array($v)){ foreach($v as $k2 => $v2){ $params["{$k}_{$k2}"] = $v2; } } else { $params[$k] = $v; } } } else { $params = $merge_vars; } return $params; }
And, where ever there was $merge_vars, i changed to $this->_merge_vars($merge_vars)
But that didn't solve my issue. Finally found a function 'getMergeVars' that generates '$merge_vars' in: app/code/community/Ebizmarts/MageMonkey/Helper/Data.php Here I added couple of new lines which solved my issue.
/* * added these new conditions * case 'city': * case 'street': * case 'region': * case 'state': * case 'zip': * case 'postcode': * case 'country': * case 'telephone': * case 'phone': */ public function getMergeVars($customer, $includeEmail = FALSE, $websiteId = NULL) { $merge_vars = array(); $maps = $this->getMergeMaps($customer->getStoreId()); if(!$maps){ return; } $request = Mage::app()->getRequest(); //Add Customer data to Subscriber if is Newsletter_Subscriber is Customer if(!$customer->getDefaultShipping() && $customer->getEntityId()){ $customer->addData(Mage::getModel('customer/customer')->load($customer->getEntityId()) ->setStoreId($customer->getStoreId()) ->toArray()); } // new:: get primary billing address of the customer $address = $customer->getPrimaryBillingAddress(); foreach($maps as $map){ $customAtt = $map['magento']; $chimpTag = $map['mailchimp']; if($chimpTag && $customAtt){ $key = strtoupper($chimpTag); switch ($customAtt) { case 'gender': $val = (int)$customer->getData(strtolower($customAtt)); if($val == 1){ $merge_vars[$key] = 'Male'; }elseif($val == 2){ $merge_vars[$key] = 'Female'; } break; case 'dob': $dob = (string)$customer->getData(strtolower($customAtt)); if($dob){ $merge_vars[$key] = (substr($dob, 5, 2) . '/' . substr($dob, 8, 2)); } break; case 'city': if($address){ $merge_vars[$key] = $address->getCity(); } break; case 'street': if($address){ $merge_vars[$key] = $address->getStreet(1) . ', ' . $address->getStreet(2); } break; case 'region': case 'state': if($address){ $merge_vars[$key] = (!$address->getRegion() ? $address->getCity() : $address->getRegion()); } break; case 'zip': case 'postcode': if($address){ $merge_vars[$key] = $address->getPostcode(); } break; case 'country': if($address){ $merge_vars[$key] = $address->getCountryId(); } break; case 'telephone': case 'phone': if($address){ $merge_vars[$key] = $address->getTelephone(); } break; case 'billing_address': ...
Is there other easier method to sync fields like street, postcode phone etc?
Also there was another issue.
When you subscribe/unsubscribe from my account area it saves fine in admin but doesn’t update (subscribe or unsubscribe) in mailchimp. So I had to update:
File: app/code/community/Ebizmarts/MageMonkey/Helper/Data.php Line: around 804 After: $subscriber->setMcStoreId(Mage::app()->getStore()->getId());
Added 2 more lines:
$mergeVars = Mage::helper('monkey')->getMergeVars($customer); $api->listSubscribe($listId, $email, $mergeVars, 'html', $isConfirmNeed);
Then I was able to subscribe and unsubscribe again.
kristenhanna posted on - Wednesday 10th of July 2013 12:21:50 AM
Dele Agagu posted on - Thursday 19th of September 2013 01:57:35 AM
Evince posted on - Tuesday 20th of May 2014 07:21:54 AM