-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1442 from mailchimp/issue1439-2.1
Added sync status field to the customer table on magento 2.1 #1439
- Loading branch information
Showing
3 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |