diff --git a/Helper/Data.php b/Helper/Data.php
index ad80aa14..ea56a678 100644
--- a/Helper/Data.php
+++ b/Helper/Data.php
@@ -739,6 +739,7 @@ public function getWebhooksKey()
public function createWebHook($apikey, $listId)
{
+ $this->log(__METHOD__);
$events = [
'subscribe' => true,
'unsubscribe' => true,
@@ -758,6 +759,7 @@ public function createWebHook($apikey, $listId)
'_nosid' => true,
'_secure' => true]);
try {
+ $this->log($hookUrl);
$ret = $api->lists->webhooks->add($listId, urlencode($hookUrl), $events, $sources);
} catch (\Mailchimp_Error $e) {
$this->log($e->getMessage());
diff --git a/Observer/Sales/Order/SubmitBefore.php b/Observer/Sales/Order/SubmitBefore.php
index 2014f2f3..6899cfd8 100644
--- a/Observer/Sales/Order/SubmitBefore.php
+++ b/Observer/Sales/Order/SubmitBefore.php
@@ -27,13 +27,17 @@ public function execute(\Magento\Framework\Event\Observer $observer)
$order = $observer->getEvent()->getData('order');
/* @var \Magento\Quote\Model\Quote $quote */
$quote = $observer->getEvent()->getData('quote');
+ $flag = 0;
foreach ($this->attributes as $attribute) {
if ($quote->hasData($attribute)) {
$order->setData($attribute, $quote->getData($attribute));
+ if($quote->getData($attribute)) {
+ $flag = 1;
+ }
}
}
-
+ $order->setData('mailchimp_flag',$flag);
return $this;
}
}
diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php
index a50dc40b..2561a600 100644
--- a/Setup/UpgradeData.php
+++ b/Setup/UpgradeData.php
@@ -13,18 +13,29 @@
namespace Ebizmarts\MailChimp\Setup;
use Magento\Framework\Setup\ModuleContextInterface;
-use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
class UpgradeData implements UpgradeDataInterface
{
-
-// public function __construct(EavSetupFactory $eavSetupFactory)
-// {
-// $this->eavSetupFactory = $eavSetupFactory;
-// }
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
+ if (version_compare($context->getVersion(), '1.0.24') < 0)
+ {
+ $setup->startSetup();
+
+ $table = $setup->getConnection()->getTableName('sales_order');
+ $select = $setup->getConnection()->select()
+ ->from(
+ false,
+ ['mailchimp_flag' => new \Zend_Db_Expr('IF(mailchimp_abandonedcart_flag OR mailchimp_campaign_id OR mailchimp_landing_page, 1, 0)')]
+ )->join(['O'=>$table],'O.entity_id = G.entity_id',[]);
+
+ $query = $setup->getConnection()->updateFromSelect($select, ['G' => $setup->getConnection()->getTableName('sales_order_grid')]);
+ $setup->getConnection()->query($query);
+
+ $setup->endSetup();
+
+ }
}
}
diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php
index c755c5a4..6570e5a8 100644
--- a/Setup/UpgradeSchema.php
+++ b/Setup/UpgradeSchema.php
@@ -393,5 +393,25 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
);
$connection->createTable($table);
}
+ if (version_compare($context->getVersion(), '1.0.24') < 0) {
+ $salesConnection->addColumn(
+ $salesConnection->getTableName('sales_order_grid'),
+ 'mailchimp_flag',
+ [
+ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN,
+ 'default' => 0,
+ 'comment' => 'Retrieved from Mailchimp'
+ ]
+ );
+ $salesConnection->addColumn(
+ $salesConnection->getTableName('sales_order'),
+ 'mailchimp_flag',
+ [
+ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_BOOLEAN,
+ 'default' => 0,
+ 'comment' => 'Retrieved from Mailchimp'
+ ]
+ );
+ }
}
}
diff --git a/Ui/Component/Listing/Column/Monkey.php b/Ui/Component/Listing/Column/Monkey.php
index 0ce0e76d..0291445f 100644
--- a/Ui/Component/Listing/Column/Monkey.php
+++ b/Ui/Component/Listing/Column/Monkey.php
@@ -37,6 +37,10 @@ class Monkey extends Column
* @var \Magento\Framework\App\RequestInterface
*/
protected $_requestInterfase;
+ /**
+ * @var \Ebizmarts\MailChimp\Helper\Data
+ */
+ protected $_helper;
/**
* Monkey constructor.
@@ -46,6 +50,7 @@ class Monkey extends Column
* @param \Magento\Framework\View\Asset\Repository $assetRepository
* @param \Magento\Framework\App\RequestInterface $requestInterface
* @param SearchCriteriaBuilder $criteria
+ * @param \Ebizmarts\MailChimp\Helper\Data $helper
* @param array $components
* @param array $data
*/
@@ -56,6 +61,7 @@ public function __construct(
\Magento\Framework\View\Asset\Repository $assetRepository,
\Magento\Framework\App\RequestInterface $requestInterface,
SearchCriteriaBuilder $criteria,
+ \Ebizmarts\MailChimp\Helper\Data $helper,
array $components = [],
array $data = []
) {
@@ -64,6 +70,7 @@ public function __construct(
$this->_searchCriteria = $criteria;
$this->_assetRepository = $assetRepository;
$this->_requestInterfase= $requestInterface;
+ $this->_helper = $helper;
parent::__construct($context, $uiComponentFactory, $components, $data);
}
@@ -71,11 +78,7 @@ public function prepareDataSource(array $dataSource)
{
if (isset($dataSource['data']['items'])) {
foreach ($dataSource['data']['items'] as & $item) {
- $order = $this->_orderRepository->get($item["entity_id"]);
- $status = $order->getData("mailchimp_abandonedcart_flag");
- if ($order->getMailchimpCampaignId() || $order->getMailchimpLandingPage()) {
- $status = 1;
- }
+ $status = $item['mailchimp_flag'];
$fieldName = $this->getData('name');
switch ($status) {
@@ -92,7 +95,6 @@ public function prepareDataSource(array $dataSource)
$item[$fieldName . '_src'] = $url;
$item[$fieldName . '_alt'] = 'hep hep thanks MailChimp';
$item[$fieldName . '_link'] = '';
-// $item[$fieldName . '_orig_src'] = $url;
break;
}
}
diff --git a/composer.json b/composer.json
index 2bd272fa..432bec49 100644
--- a/composer.json
+++ b/composer.json
@@ -6,7 +6,7 @@
},
"description": "Connect MailChimp with Magento",
"type": "magento2-module",
- "version": "1.0.23",
+ "version": "1.0.24",
"authors": [
{
"name": "Ebizmarts Corp",
diff --git a/etc/di.xml b/etc/di.xml
index 9959a2eb..63f9bec2 100644
--- a/etc/di.xml
+++ b/etc/di.xml
@@ -56,4 +56,11 @@
+
+
+
+ - sales_order.mailchimp_flag
+
+
+
\ No newline at end of file
diff --git a/etc/module.xml b/etc/module.xml
index dc933887..9238cd61 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -11,7 +11,7 @@
*/
-->
-
+