Skip to content

Commit

Permalink
Merge pull request #1442 from mailchimp/issue1439-2.1
Browse files Browse the repository at this point in the history
Added sync status field to the customer table on magento 2.1 #1439
  • Loading branch information
federicocanedo authored Jun 29, 2022
2 parents 7963325 + 19e4f8d commit ef693ea
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Model/Api/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ protected function _updateCustomer($storeId, $entityId, $sync_delta = null, $syn
\Ebizmarts\MailChimp\Helper\Data::IS_CUSTOMER,
$sync_delta,
$sync_error,
$sync_modified
$sync_modified,
null,
null,
\Ebizmarts\MailChimp\Helper\Data::WAITINGSYNC
);
}
}
165 changes: 165 additions & 0 deletions Ui/Component/Listing/Column/Customers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
<?php

namespace Ebizmarts\MailChimp\Ui\Component\Listing\Column;

use Magento\Framework\App\RequestInterface;
use Magento\Framework\View\Element\UiComponent\ContextInterface;
use Magento\Framework\View\Element\UiComponentFactory;
use \Magento\Ui\Component\Listing\Columns\Column;
use Magento\Customer\Model\CustomerFactory;

class Customers extends Column
{
/**
* @var RequestInterface
*/
protected $_requestInterface;
/**
* @var \Magento\Framework\View\Asset\Repository
*/
protected $_assetRepository;
/**
* @var CustomerFactory
*/
protected $_customerFactory;
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
protected $_helper;
/**
* @var \Ebizmarts\MailChimp\Model\MailChimpErrorsFactory
*/
protected $_mailChimpErrorsFactory;

/**
* @param ContextInterface $context
* @param UiComponentFactory $uiComponentFactory
* @param RequestInterface $requestInterface
* @param \Magento\Framework\View\Asset\Repository $assetRepository
* @param CustomerFactory $customerFactory
* @param \Ebizmarts\MailChimp\Helper\Data $helper
* @param \Ebizmarts\MailChimp\Model\MailChimpErrorsFactory $mailChimpErrorsFactory
* @param array $components
* @param array $data
*/
public function __construct(
ContextInterface $context,
UiComponentFactory $uiComponentFactory,
RequestInterface $requestInterface,
\Magento\Framework\View\Asset\Repository $assetRepository,
CustomerFactory $customerFactory,
\Ebizmarts\MailChimp\Helper\Data $helper,
\Ebizmarts\MailChimp\Model\MailChimpErrorsFactory $mailChimpErrorsFactory,
array $components = [],
array $data = [])
{
$this->_requestInterface = $requestInterface;
$this->_assetRepository = $assetRepository;
$this->_customerFactory = $customerFactory;
$this->_helper = $helper;
$this->_mailChimpErrorsFactory = $mailChimpErrorsFactory;
parent::__construct($context, $uiComponentFactory, $components, $data);
}

public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
$params = ['_secure' => $this->_requestInterface->isSecure()];
foreach ($dataSource['data']['items'] as & $item) {
/**
* @var $customer \Magento\Customer\Model\Customer
*/
$customer = $this->_customerFactory->create()->load($item['entity_id']);
$params = ['_secure' => $this->_requestInterface->isSecure()];
$alt = '';
if ($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_ACTIVE, $customer->getStoreId())) {
$mailchimpStoreId = $this->_helper->getConfigValue(
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,
$customer->getStoreId()
);
$syncData = $this->_helper->getChimpSyncEcommerce(
$mailchimpStoreId,
$customer->getId(),
\Ebizmarts\MailChimp\Helper\Data::IS_CUSTOMER
);
if (!$syncData || $syncData->getMailchimpStoreId() != $mailchimpStoreId ||
$syncData->getRelatedId() != $customer->getId() ||
$syncData->getType() != \Ebizmarts\MailChimp\Helper\Data::IS_CUSTOMER) {
$url = $this->_assetRepository->getUrlWithParams(
'Ebizmarts_MailChimp::images/no.png',
$params
);
$text = __('Syncing');
} else {
$sync = $syncData->getMailchimpSent();
switch ($sync) {
case \Ebizmarts\MailChimp\Helper\Data::SYNCED:
$url = $this->_assetRepository->getUrlWithParams(
'Ebizmarts_MailChimp::images/yes.png',
$params
);
$text = __('Synced');
$alt = $syncData->getMailchimpSyncDelta();
break;
case \Ebizmarts\MailChimp\Helper\Data::WAITINGSYNC:
$url = $this->_assetRepository->getUrlWithParams(
'Ebizmarts_MailChimp::images/waiting.png',
$params
);
$text = __('Waiting');
$alt = $syncData->getMailchimpSyncDelta();
break;
case \Ebizmarts\MailChimp\Helper\Data::SYNCERROR:
$url = $this->_assetRepository->getUrlWithParams(
'Ebizmarts_MailChimp::images/error.png',
$params
);
$text = __('Error');
$customerError = $this->_getError($customer->getId(), $customer->getStoreId());
if ($customerError) {
$alt = $customerError->getErrors();
}
break;
case \Ebizmarts\MailChimp\Helper\Data::NEEDTORESYNC:
$url = $this->_assetRepository->getUrlWithParams(
'Ebizmarts_MailChimp::images/resync.png',
$params
);
$text = __('Resyncing');
$alt = $syncData->getMailchimpSyncDelta();
break;
case \Ebizmarts\MailChimp\Helper\Data::NOTSYNCED:
$url = $this->_assetRepository->getUrlWithParams(
'Ebizmarts_MailChimp::images/never.png',
$params
);
$text = __('With error');
$alt = $syncData->getMailchimpSyncError();
break;
default:
$url = $this->_assetRepository->getUrlWithParams(
'Ebizmarts_MailChimp::images/error.png',
$params
);
$text = __('Error');
}

}

}
$item['mailchimp_sync'] =
"<div style='width: 100%;margin: 0 auto;text-align: center'><div><img src='".$url."' style='border: none; width: 5rem; text-align: center; max-width: 100%' title='$alt' /></div><div>$text</div></div>";
}
}
return $dataSource;
}
private function _getError($customerId, $storeId)
{
/**
* @var $error \Ebizmarts\MailChimp\Model\MailChimpErrors
*/
$error = $this->_mailChimpErrorsFactory->create();
return $error->getByStoreIdType($storeId, $customerId, \Ebizmarts\MailChimp\Helper\Data::IS_CUSTOMER);
}

}
16 changes: 16 additions & 0 deletions view/adminhtml/ui_component/customer_listing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="customer_columns">
<column name="mailchimp_sync" class="\Ebizmarts\MailChimp\Ui\Component\Listing\Column\Customers">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="bodyTmpl" xsi:type="string">ui/grid/cells/html</item>
<item name="sortable" xsi:type="boolean">false</item>
<item name="has_preview" xsi:type="string">1</item>
<item name="label" xsi:type="string" translate="true">Mailchimp</item>
<item name="sortOrder" xsi:type="number">20</item>
</item>
</argument>
</column>
</columns>
</listing>

0 comments on commit ef693ea

Please sign in to comment.