Skip to content

Commit

Permalink
closes #88
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Sep 18, 2017
1 parent aa8b6e5 commit 23d089e
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 15 deletions.
2 changes: 2 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,7 @@ public function getWebhooksKey()

public function createWebHook($apikey, $listId)
{
$this->log(__METHOD__);
$events = [
'subscribe' => true,
'unsubscribe' => true,
Expand All @@ -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());
Expand Down
6 changes: 5 additions & 1 deletion Observer/Sales/Order/SubmitBefore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
23 changes: 17 additions & 6 deletions Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

}
}
}
20 changes: 20 additions & 0 deletions Setup/UpgradeSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
);
}
}
}
14 changes: 8 additions & 6 deletions Ui/Component/Listing/Column/Monkey.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Monkey extends Column
* @var \Magento\Framework\App\RequestInterface
*/
protected $_requestInterfase;
/**
* @var \Ebizmarts\MailChimp\Helper\Data
*/
protected $_helper;

/**
* Monkey constructor.
Expand All @@ -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
*/
Expand All @@ -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 = []
) {
Expand All @@ -64,18 +70,15 @@ public function __construct(
$this->_searchCriteria = $criteria;
$this->_assetRepository = $assetRepository;
$this->_requestInterfase= $requestInterface;
$this->_helper = $helper;
parent::__construct($context, $uiComponentFactory, $components, $data);
}

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) {
Expand All @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"description": "Connect MailChimp with Magento",
"type": "magento2-module",
"version": "1.0.23",
"version": "1.0.24",
"authors": [
{
"name": "Ebizmarts Corp",
Expand Down
7 changes: 7 additions & 0 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,11 @@
<type name="Magento\Customer\Model\AccountManagement">
<plugin name="abandoned-checkout-save-quote" type="Ebizmarts\MailChimp\Model\Plugin\AccountManagement" sortOrder="10"/>
</type>
<virtualType name="Magento\Sales\Model\ResourceModel\Order\Grid" type="Magento\Sales\Model\ResourceModel\Grid">
<arguments>
<argument name="columns" xsi:type="array">
<item name="mailchimp_flag" xsi:type="string">sales_order.mailchimp_flag</item>
</argument>
</arguments>
</virtualType>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Ebizmarts_MailChimp" setup_version="1.0.23">
<module name="Ebizmarts_MailChimp" setup_version="1.0.24">
<sequence>
<module name="Magento_Newsletter"/>
</sequence>
Expand Down

0 comments on commit 23d089e

Please sign in to comment.