0

Is it possible to create subscribers when the customer is creating an order? I have installed the Magemonkey extension and connect it to my MailChimp account. However, nothing happens. On my MailChimp account, I have 8 subscribers, on my Magento site 89.

Am I missing some step? Do I need to set Customer Fields Mapping? I don't understand how to know what fields should I map.

I also run the cron job, but still, nothing happens. How to sync my subscribers with my MailChimp account. API key is ok, and magemonkey can see my list group in MailChimp. I know that I am missing something but I can't figure out what.

1 Answer 1

3

Seems you have installed Ebizmarts Magemonkey extension. This extension works only with Magento Newsletter module. So Magemonkey extension calls server when your customer subscribed or unsubcsribed on your site. No cron jobs, no sync, only newsletter events. All additional events required custom coding.

Do I need to set Customer Fields Mapping?

yes sure. Here is example...

Magento mailchimp configs

Magento field accept only:

  • fname - $customer->getFirstname();
  • lname - $customer->getLastname();
  • gender
  • dob
  • billing_address
  • shipping_address
  • telephone
  • company
  • group_id

or any customer attribute

$customer->getData(strtolower(CUTSOMER_ATTRIBUTE))

In Mailchimp account navigate to Lists > [Select your list] > Settings > List fields and |MERGE| tags Mailchimp account

Mailchimp field in Magento should match to Put this tag in you content field

Is it possible to create subscribers when the customer is creating an order?

yes, you need to extend magemonkey module and add new event

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="sales_model_service_quote_submit_success">
        <observer name="quote_to_order_success" instance="Vendor\Module\Observer\SalesQuoteSubmitSuccess" />
    </event>
</config>

Vendor/Module/Observer/SalesQuoteSubmitSuccess.php

namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;

class SalesQuoteSubmitSuccess implements ObserverInterface {

    /**
     * @var \Ebizmarts\MageMonkey\Helper\Data
     */
    protected $_helper;

    /**
     * @var \Ebizmarts\MageMonkey\Model\Api
     */
    protected $_api = null;

    /**
     * @param \Ebizmarts\MageMonkey\Helper\Data $helper
     * @param \Ebizmarts\MageMonkey\Model\Api $api
     */
    public function __construct(
        \Ebizmarts\MageMonkey\Helper\Data $helper,
        \Ebizmarts\MageMonkey\Model\Api $api
    ) {
        $this->_helper          = $helper;
        $this->_api             = $api;
    }

    /**
     * @param Observer $observer
     * @return $this
     */
    public function execute(Observer $observer) {

        $quote = $observer->getEvent()->getQuote();
        $customer = $quote->getCustomer();

        $mergeVars = $this->_helper->getMergeVars($customer);
        $api = $this->_api;
        if ($this->_helper->isDoubleOptInEnabled($customer->getStoreId())) {
            $status = 'pending';
        } else {
            $status = 'subscribed';
        }

        if ($mergeVars) {
            $data = ['list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => $mergeVars];
        } else {
            $data = ['list_id' => $this->_helper->getDefaultList(), 'email_address' => $customer->getEmail(), 'email_type' => 'html', 'status' => $status, 'merge_fields' => ['EMAIL'=>$customer->getEmail()]];
        }
        try {
            $emailHash = md5(strtolower($customer->getEmail()));
            $return = $api->getMember($this->_helper->getDefaultList(), $emailHash);
            if (!isset($return->id)) {
                $return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
            }
        } catch (\Exception $e) {
            $this->_helper->log($e->getMessage());
        }

        return $this;
    }
}

How to sync my subscribers with my MailChimp account.

you need to add new cron job and walk through all customers.

Use this to check the customer

$emailHash = md5(strtolower($customer->getEmail()));
$return = $api->getMember($this->_helper->getDefaultList(), $emailHash);

and this to send customer data to server

$return = $api->listCreateMember($this->_helper->getDefaultList(), json_encode($data));
2
  • Magento Newsletter module - Is this also an extension that I need to install, or do you mean magento newsletter that is already part of magento? I tried to browse for magento newsletter module, but there is a lot of them. How to know which is the best to work with magemonkey?
    – Milo
    Commented Jun 26, 2017 at 8:19
  • 1
    I mean default Magento_Newsletter module Commented Jun 26, 2017 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.