Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue423 #424

Merged
merged 4 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion Block/Adminhtml/System/Config/Form/Field/CustomerMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class CustomerMap extends \Magento\Config\Block\System\Config\Form\Field\FieldA
* @var VarsMap
*/
protected $_varsRenderer=null;
protected $_mailchimpRenderer=null;

protected function _getVarsRenderer()
{
Expand All @@ -32,10 +33,26 @@ protected function _getVarsRenderer()
}
return $this->_varsRenderer;
}
protected function _getMailchimpRenderer()
{
if (!$this->_mailchimpRenderer) {
$this->_mailchimpRenderer = $this->getLayout()->createBlock(
'Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field\MailchimpMap',
'',
['data' => ['is_render_to_js_template' => true]]
);
$this->_mailchimpRenderer->setClass('mailchimp_field_select');
}
return $this->_mailchimpRenderer;
}

protected function _prepareToRender()
{
$this->addColumn('mailchimp', ['label' => __('Mailchimp')]);
// $this->addColumn('mailchimp', ['label' => __('Mailchimp')]);
$this->addColumn(
'mailchimp_field_id',
['label' => __('Mailchimp'), 'renderer' => $this->_getMailchimpRenderer()]
);
$this->addColumn(
'customer_field_id',
['label' => __('Magento'), 'renderer' => $this->_getVarsRenderer()]
Expand All @@ -48,6 +65,8 @@ protected function _prepareArrayRow(\Magento\Framework\DataObject $row)
$optionExtraAttr = [];
$optionExtraAttr['option_' . $this->_getVarsRenderer()->calcOptionHash($row->getData('customer_field_id'))] =
'selected="selected"';
$optionExtraAttr['option_' . $this->_getMailchimpRenderer()->calcOptionHash($row->getData('mailchimp_field_id'))] =
'selected="selected"';
$row->setData(
'option_extra_attrs',
$optionExtraAttr
Expand Down
75 changes: 75 additions & 0 deletions Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/**
* mc-magento2 Magento Component
*
* @category Ebizmarts
* @package mc-magento2
* @author Ebizmarts Team <info@ebizmarts.com>
* @copyright Ebizmarts (http://ebizmarts.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @date: 10/9/18 1:17 PM
* @file: MailchimpMap.php
*/

namespace Ebizmarts\MailChimp\Block\Adminhtml\System\Config\Form\Field;

class MailchimpMap extends \Magento\Framework\View\Element\Html\Select
{
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
private $_helper;
/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
private $_storeManager;

/**
* MailchimpMap constructor.
* @param \Magento\Framework\View\Element\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Ebizmarts\MailChimp\Helper\Data $helper
* @param array $data
*/
public function __construct(
\Magento\Framework\View\Element\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Ebizmarts\MailChimp\Helper\Data $helper,
array $data=[]
)
{
parent::__construct($context, $data);
$this->_helper = $helper;
$this->_storeManager = $storeManager;
}

protected function _getMailchimpTags()
{
$ret = [];
$api = $this->_helper->getApi($this->_storeManager->getStore()->getId());
$merge = $api->lists->mergeFields->getAll($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_LIST));
foreach($merge['merge_fields'] as $item) {
$ret[$item['tag']] = $item['tag'].' ('.$item['name'].' : '.$item['type'].')';
}
return $ret;
}
public function setInputName($value)
{
return $this->setName($value);
}

/**
* Render block HTML
*
* @return string
*/
public function _toHtml()
{
if (!$this->getOptions()) {
foreach ($this->_getMailchimpTags() as $attId => $attLabel) {
$this->addOption($attId, addslashes($attLabel));
}
}
return parent::_toHtml();
}
}
12 changes: 6 additions & 6 deletions Helper/VarsMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function isEncodedArrayFieldValue($value)
foreach ($value as $row) {
if (!is_array($row)
|| !array_key_exists('customer_field_id', $row)
|| !array_key_exists('mailchimp', $row)
|| !array_key_exists('mailchimp_field_id', $row)
) {
return false;
}
Expand All @@ -77,13 +77,13 @@ protected function decodeArrayFieldValue(array $value)
foreach ($value as $row) {
if (!is_array($row)
|| !array_key_exists('customer_field_id', $row)
|| !array_key_exists('mailchimp', $row)
|| !array_key_exists('mailchimp_field_id', $row)
) {
continue;
}
$groupId = $row['customer_field_id'];
$qty = $row['mailchimp'];
$result[$groupId] = $qty;
$customer_field_id = $row['customer_field_id'];
$mailchimp_field_id = $row['mailchimp_field_id'];
$result[$customer_field_id] = $mailchimp_field_id;
}
return $result;
}
Expand Down Expand Up @@ -114,7 +114,7 @@ protected function encodeArrayFieldValue(array $value)
$result = [];
foreach ($value as $customerFieldId => $mailchimpName) {
$resultId = $this->mathRandom->getUniqueHash('_');
$result[$resultId] = ['mailchimp' => $mailchimpName ,'customer_field_id' => $customerFieldId];
$result[$resultId] = ['mailchimp_field_id' => $mailchimpName ,'customer_field_id' => $customerFieldId];
}
return $result;
}
Expand Down