campaignmonitor / magento-extension

Campaign Monitor extension for the Magento E-Commerce Platform
https://www.magentocommerce.com/magento-connect/catalog/product/view/id/30754/s/campaign-monitor/
MIT License
4 stars 7 forks source link

First Name / Last Name not populating in Campaign Monitor #14

Open thefreshlab opened 6 years ago

thefreshlab commented 6 years ago

We previously had the Fontis Campaign Monitor extension installed which was sending subscriber details through to campaign monitor. Due to a conflict, we upgraded to the "official" campaign monitor extension which is built on the original Fontis extension (with a lot of updates and enhancements).

since then, our subscriber form for newsletters (which asks for first name and last name) is not sending this data through to campaign monitor - instead all subscribers that use the form are coming through as (GUEST) in CM.

in addition to this, we also have a custom date of birth field within the form, which again was being sent through and populated within CM - this no longer is being captured or inserted into CM.

I referred to the previous fontis extension, and found this code in the file: controllers > ConfirmController.php

<?php

include "Mage/Newsletter/controllers/SubscriberController.php";
class Fontis_CampaignMonitor_ConfirmController extends Mage_Newsletter_SubscriberController
{

    private function getStyle($id)
    {
        $style = array(
            '1' => 'quick_and_uncomplicated',
            '2' => 'naturally_polished_and_well_defined',
            '3' => 'glamourous_and_dramatic'
        );

        return $style[$id];
    }

    public function confirmAction()
    {
        $id = (int) $this->getRequest()->getParam('id');
        $session = Mage::getSingleton('core/session');
        $subscriber = Mage::getModel('newsletter/subscriber')->load($id);
        $email = $subscriber->getSubscriberEmail();

        Mage::log("Fontis_CampaignMonitor: Adding newsletter subscription via frontend 'Sign up' block for $email");

        $apiKey = trim(Mage::getStoreConfig('newsletter/campaignmonitor/api_key'));
        $listID = trim(Mage::getStoreConfig('newsletter/campaignmonitor/list_id'));

        if ($apiKey && $listID)
        {
            try
            {
                $client = new SoapClient("http://api.createsend.com/api/api.asmx?wsdl", array("trace" => true));
            }
            catch (Exception $e)
            {
                Mage::log("Fontis_CampaignMonitor: Error connecting to CampaignMonitor server: " . $e->getMessage());
                $session->addException($e, $this->__('There was a problem with the subscription'));
                $this->_redirectReferer();
            }
            try
            {

                $customFields = array(
                    0 => array(
                        'Key' => 'style',
                        'Value' => $this->getStyle($subscriber->getStyleType())
                    )
                );

                if ($subscriber->getBirthdate())
                {
                    $customFields[] = array(
                        'Key' => 'birthday',
                        'Value' => $subscriber->getBirthdate()
                    );
                }
                //var_dump($customFields); exit;
                $result = $client->AddAndResubscribeWithCustomFields(array(
                    "ApiKey" => $apiKey,
                    "ListID" => $listID,
                    "Email" => $email,
                    "Name" => $subscriber->getFirstname() . ' ' . $subscriber->getLastname(),
                    "CustomFields" => $customFields
                ));
            }
            catch (Exception $e)
            {
                Mage::log("Fontis_CampaignMonitor: Error in CampaignMonitor SOAP call: " . $e->getMessage());
                $session->addException($e, $this->__('There was a problem with the subscription'));
                $this->_redirectReferer();
            }
            //}
        }
        else
        {
            Mage::log("Fontis_CampaignMonitor: Error: Campaign Monitor API key and/or list ID not set in Magento Newsletter options.");
        }

        parent::confirmAction();
    }

}

This file isnt included within the official extension and cant see anywhere that I can add custom values to be inserted into campaign monitor (for the purpose of the date of birth). This still doesnt answer the question as to why the name is not being sent through correctly.

can you help?