Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiagoebizmarts committed Sep 12, 2016
2 parents abd2a16 + 0166e06 commit c9e668d
Show file tree
Hide file tree
Showing 57 changed files with 4,592 additions and 333 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Author : Ebizmarts <[email protected]>
* Date : 4/24/13
* Time : 1:15 PM
* File : Add.php
* Module : Ebizmarts_MailChimp
*/
class Ebizmarts_Mailchimp_Block_Adminhtml_Mergevars_Add extends Mage_Adminhtml_Block_Widget_Form_Container {
protected $_mode = 'add';
public function __construct() {
$this->_controller = 'adminhtml_mergevars';
$this->_blockGroup = 'mailchimp';

parent::__construct();
$this->_removeButton("delete");
$this->_removeButton("back");
$this->_removeButton("reset");
}
// public function getMovtypes()
// {
// $types = Mage::getSingleton('mailchimp/system_config_source_movtype')->getMovtypes();
// return $types;
// }
public function getHeaderText()
{
return Mage::helper('mailchimp')->__('New Field Type');
}
public function _prepareForm() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* Author : Ebizmarts <[email protected]>
* Date : 4/24/13
* Time : 4:00 PM
* File : Form.php
* Module : Ebizmarts_MailChimp
*/
class Ebizmarts_Mailchimp_Block_Adminhtml_Mergevars_Add_Form extends Mage_Adminhtml_Block_Widget_Form
{
protected function _prepareForm() {
$form = new Varien_Data_Form(array('id' => 'edit_form', 'action' => $this->getUrl('*/*/saveadd'), 'method' => 'post'));
$fieldset = $form->addFieldset('base_fieldset', array('legend' => Mage::helper('mailchimp')->__('Mergevars Data')));


$fieldset->addField('mergevar_label', 'text', array(
'name' => 'mergevar[label]',
'label' => Mage::helper('mailchimp')->__('MergeVar Name'),
'id' => 'mergevar_label',
'title' => Mage::helper('mailchimp')->__('MergeVar Name'),
'required' => true
));
$fieldset->addField('mergevar_fieldtype','select',array(
'name' => 'mergevar[fieldtype]',
'label' => Mage::helper('mailchimp')->__('Field Type'),
'id' => 'mergevar_fieldtype',
'values' => Mage::getSingleton('mailchimp/system_config_source_fieldtype')->getFieldTypes(),
'required' => true
));

$fieldset->addField('mergevar_value', 'text', array(
'name' => 'mergevar[value]',
'label' => Mage::helper('mailchimp')->__('Value for case entry'),
'id' => 'mergevar_value',
'title' => Mage::helper('mailchimp')->__('Value for case entry'),
'note' => 'This value should be added in the case of Data.php file',
'required' => true
));



$form->setUseContainer(true);
$this->setForm($form);
return parent::_prepareForm();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
* @date: 7/7/16 1:31 PM
* @file: Abandoned.php
*/
class Ebizmarts_MailChimp_Block_Adminhtml_Sales_Order_Grid_Renderer_Abandoned extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
class Ebizmarts_MailChimp_Block_Adminhtml_Sales_Order_Grid_Renderer_Mailchimp extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
public function render(Varien_Object $row)
{
$order = Mage::getModel('sales/order')->load($row->getData('entity_id'));
if ($order->getMailchimpAbandonedcartFlag()) {
$result = '<img src="' . $this->getSkinUrl("mailchimp/images/logo-freddie-monocolor-200.png") . '" width="40" title="recovered cart by Mailchimp" />';
if ($order->getMailchimpAbandonedcartFlag() || $order->getMailchimpCampaignId()) {
$result = '<img src="' . $this->getSkinUrl("ebizmarts/mailchimp/images/logo-freddie-monocolor-200.png") . '" width="40" title="hep hep thanks MailChimp" />';
} else {
$result = '';
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* mc-magento Magento Component
*
* @category Ebizmarts
* @package mc-magento
* @author Ebizmarts Team <[email protected]>
* @copyright Ebizmarts (http://ebizmarts.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @date: 30/8/16 1:02 PM
* @file: CreateMergeFields.php
*/
class Ebizmarts_MailChimp_Block_Adminhtml_System_Config_CreateMergeFields
extends Mage_Adminhtml_Block_System_Config_Form_Field
{
protected function _construct()
{
parent::_construct();
$this->setTemplate('ebizmarts/mailchimp/system/config/createmergefields.phtml');
}

protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
return $this->_toHtml();
}

public function getButtonHtml()
{
$button = $this->getLayout()->createBlock('adminhtml/widget_button')
->setData(
array(
'id' => 'createmergefields_button',
'label' => $this->helper('mailchimp')->__('Create Merge Fields'),
'onclick' => 'javascript:createMergeFields(); return false;'
)
);

return $button->toHtml();
}
public function getAjaxCheckUrl()
{
return Mage::helper('adminhtml')->getUrl('adminhtml/ecommerce/createMergeFields');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @date: 4/29/16 3:55 PM
* @file: Hint.php
*/
class Ebizmarts_MailChimp_Block_Adminhtml_System_Config_Fieldset_Hint
class Ebizmarts_MailChimp_Block_Adminhtml_System_Config_Fieldset_Mailchimp_Hint
extends Mage_Adminhtml_Block_Abstract
implements Varien_Data_Form_Element_Renderer_Interface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* MailChimp For Magento
*
* @category Ebizmarts_MailChimp
* @author Ebizmarts Team <[email protected]>
* @copyright Ebizmarts (http://ebizmarts.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @date: 4/29/16 3:55 PM
* @file: Hint.php
*/
class Ebizmarts_MailChimp_Block_Adminhtml_System_Config_Fieldset_Mandrill_Hint
extends Mage_Adminhtml_Block_Abstract
implements Varien_Data_Form_Element_Renderer_Interface
{
protected $_template = 'ebizmarts/mandrill/system/config/fieldset/hint.phtml';

/**
* Render fieldset html
*
* @param Varien_Data_Form_Element_Abstract $element
* @return string
*/
public function render(Varien_Data_Form_Element_Abstract $element)
{
return $this->toHtml();
}

public function getMandrillVersion()
{
return (string)Mage::getConfig()->getNode('modules/Ebizmarts_Mandrill/version');
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function __construct()
)
);
$this->_addAfter = false;
$this->_addButtonLabel = Mage::helper('mailchimp')->__('Add new field');
parent::__construct();
$this->setTemplate('ebizmarts/mailchimp/system/config/form/field/array_dropdown.phtml');

Expand All @@ -44,6 +43,16 @@ public function __construct()
$this->_customerAttributes[$option['attribute_id']] = $option['frontend_label'];
}
}
$customFieldTypes = unserialize(
Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_CUSTOM_MAP_FIELDS)
);
if(is_array($customFieldTypes)) {
foreach ($customFieldTypes as $customFieldType) {
$label = $customFieldType['label'];
$value = $customFieldType['value'];
$this->_customerAttributes[$value] = $label;
}
}
ksort($this->_customerAttributes);
}

Expand All @@ -66,4 +75,12 @@ protected function _renderCellTemplate($columnName)
}
return $rendered;
}

protected function _getMailChimpValue(){
return Mage::getSingleton('core/session')->getMailchimpValue();
}

protected function _getMailChimpLabel(){
return Mage::getSingleton('core/session')->getMailchimpLabel();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

/**
* Account details renderer for configuration settings
*
* @category Ebizmarts
* @package Ebizmarts_Mandrill
* @author Ebizmarts Team <[email protected]>
* @license http://opensource.org/licenses/osl-3.0.php
*/
class Ebizmarts_MailChimp_Block_Adminhtml_System_Config_Userinfo
extends Mage_Adminhtml_Block_System_Config_Form_Field
{

protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
{
$values = $element->getValues();

$html = '<ul class="checkboxes">';

foreach ($values as $dat) {
$html .= "<li>{$dat['label']}</li>";
}

$html .= '</ul>';

return $html;
}

}
72 changes: 72 additions & 0 deletions app/code/community/Ebizmarts/MailChimp/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,76 @@ public function deleteStore()
Mage::getConfig()->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID);
}
}

public function createMergeFields()
{
$listId = Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_LIST);
$apiKey = Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_APIKEY);
$maps = unserialize(Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_MAP_FIELDS));
$customFieldTypes = unserialize(
Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::GENERAL_CUSTOM_MAP_FIELDS)
);

if ($apiKey != null && $apiKey != "") {
$api = new Ebizmarts_Mailchimp($apiKey, null, 'Mailchimp4Magento' . (string)Mage::getConfig()->getNode('modules/Ebizmarts_MailChimp/version'));
try {
$mailchimpFields = $api->lists->mergeFields->getAll($listId, null, null, 50);
} catch (Mailchimp_Error $e) {
Mage::helper('mailchimp')->logErrors($e->getFriendlyMessage());
}
if(count($mailchimpFields) > 0) {
foreach ($maps as $map) {
$customAtt = $map['magento'];
$chimpTag = $map['mailchimp'];
$alreadyExists = false;
$created = false;
foreach ($mailchimpFields['merge_fields'] as $mailchimpField) {
if ($mailchimpField['tag'] == $chimpTag || strtoupper($chimpTag) == 'EMAIL') {
$alreadyExists = true;
}
}
if (!$alreadyExists) {
foreach ($customFieldTypes as $customFieldType) {
if($customFieldType['value'] == $chimpTag) {
try {
$api->lists->mergeFields->add($listId, $customFieldType['label'], $customFieldType['field_type'], null, $chimpTag);
} catch (Mailchimp_Error $e) {
Mage::helper('mailchimp')->logErrors($e->getFriendlyMessage());
}
$created = true;
}
}
if (!$created) {
$attrSetId = Mage::getResourceModel('eav/entity_attribute_collection')
->setEntityTypeFilter(1)
->addSetInfo()
->getData();
$label = null;
foreach ($attrSetId as $option) {
if ($option['attribute_id'] == $customAtt && $option['frontend_label']) {
$label = $option['frontend_label'];
}
}
try {
if($label) {
//Shipping and Billing Address
if ($customAtt == 13 || $customAtt == 14) {
$api->lists->mergeFields->add($listId, $label, 'address', null, $chimpTag);
//Birthday
} elseif ($customAtt == 11) {
$api->lists->mergeFields->add($listId, $label, 'date', null, $chimpTag);
} else {
$response = $api->lists->mergeFields->add($listId, $label, 'text', null, $chimpTag);
}
}
} catch (Mailchimp_Error $e) {
Mage::helper('mailchimp')->logErrors($e->getFriendlyMessage());
}
}
}
}
}
}

}
}
39 changes: 39 additions & 0 deletions app/code/community/Ebizmarts/MailChimp/Helper/Mandrill.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php
/**
* mc-magento Magento Component
*
* @category Ebizmarts
* @package mc-magento
* @author Ebizmarts Team <[email protected]>
* @copyright Ebizmarts (http://ebizmarts.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @date: 8/30/16 3:31 PM
* @file: Mandrill.php
*/
class Ebizmarts_MailChimp_Helper_Mandrill extends Mage_Core_Helper_Abstract
{
/**
* @param $message
*/
public function log($message)
{
if (Mage::helper('mailchimp')->getConfigValue(Ebizmarts_MailChimp_Model_Config::MANDRILL_LOG)) {
Mage::log($message, null, 'Mandrill_Request.log', true);
}
}
/**
* Get module User-Agent to use on API requests
*
* @return string
*/
public function getUserAgent()
{
$modules = Mage::getConfig()->getNode('modules')->children();
$modulesArray = (array)$modules;

$aux = (array_key_exists('Enterprise_Enterprise', $modulesArray)) ? 'EE' : 'CE';
$v = (string)Mage::getConfig()->getNode('modules/Ebizmarts_Mandrill/version');
$version = strpos(Mage::getVersion(), '-') ? substr(Mage::getVersion(), 0, strpos(Mage::getVersion(), '-')) : Mage::getVersion();
return (string)'Ebizmarts_Mandrill' . $v . '/Mage' . $aux . $version;
}
}
Loading

0 comments on commit c9e668d

Please sign in to comment.