Skip to content

Commit

Permalink
sync and clean statistics #2041 for magento 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Nov 27, 2024
1 parent c71467e commit 720d303
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
57 changes: 57 additions & 0 deletions Cron/SyncStatistics.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace Ebizmarts\MailChimp\Cron;

use Ebizmarts\MailChimp\Helper\Data as MailChimpHelper;
use Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification\CollectionFactory as MailchimpNotificationCollectionFactory;
class SyncStatistics
{
private $helper;
private $mailchimpNotificationCollectionFactory;
public function __construct(
MailChimpHelper $helper,
MailchimpNotificationCollectionFactory $mailchimpNotificationCollectionFactory
)
{
$this->helper = $helper;
$this->mailchimpNotificationCollectionFactory = $mailchimpNotificationCollectionFactory;
}
public function execute()
{
$this->helper->log("Sync statistics started");
if ($this->helper->isSupportEnabled())
{
$collection = $this->getCollection();
/**
* @var $collectionItem \Ebizmarts\MailChimp\Model\MailChimpNotification
*/
foreach ($collection as $collectionItem)
{
$this->syncData($collectionItem->getNotificationData());
$collectionItem->setProcessed(true);
$collectionItem->setSyncedAt($this->helper->getGmtDate());
$collectionItem->getResource()->save($collectionItem);
}
} else {
$this->helper->log("Support is off");
}

$this->helper->log("Sync statistics finished");
}
private function getCollection()
{
$collection = $this->mailchimpNotificationCollectionFactory->create();
$collection->addFieldToFilter('processed', 0);
$collection->setOrder('generated_at', 'ASC');

return $collection;
}
private function syncData($data)
{
$this->helper->log($data);
}
private function cleanData()
{

}
}
5 changes: 5 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
const XML_POPUP_FORM = 'mailchimp/general/popup_form';
const XML_POPUP_URL = 'mailchimp/general/popup_url';
const XML_CLEAN_ERROR_MONTHS = 'mailchimp/ecommerce/clean_errors_months';
const XML_ENABLE_SUPPORT = 'mailchimp/general/enable_support';

const ORDER_STATE_OK = 'complete';

Expand Down Expand Up @@ -284,6 +285,10 @@ public function isMailChimpEnabled($store = null)
{
return $this->getConfigValue(self::XML_PATH_ACTIVE, $store);
}
public function isSupportEnabled()
{
return $this->getConfigValue(self::XML_ENABLE_SUPPORT);
}

/**
* @param null $store
Expand Down
14 changes: 14 additions & 0 deletions Model/ResourceModel/MailchimpNotification/Collection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification;

class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
protected function _construct()
{
$this->_init(
\Ebizmarts\MailChimp\Model\MailchimpNotification::class,
\Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification::class
);
}
}
2 changes: 1 addition & 1 deletion etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
<field id="*/*/active">1</field>
</depends>
</field>
<field id="support" translate="label comment" type="select" sortOrder="75" showInDefault="1" showInWebsite="1" showInStore="1">
<field id="enable_support" translate="label comment" type="select" sortOrder="75" showInDefault="1" showInWebsite="0" showInStore="0">
<label>Enable Support</label>
<comment>
<![CDATA[By ennabling this, you accept <a href="https://github.com/magento/magento2/issues/4999" target="_blank">this</a>]]>
Expand Down
5 changes: 4 additions & 1 deletion etc/crontab.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
<schedule>0 * * * *</schedule>
</job>
<job name="ebizmarts_generate_statistics" instance="Ebizmarts\MailChimp\Cron\GenerateStatistics" method="execute">
<schedule>0 */6 * * *</schedule>
<schedule>*/5 * * * *</schedule>
</job>
<job name="ebizmarts_sync_statistics" instance="Ebizmarts\MailChimp\Cron\SyncStatistics" method="execute">
<schedule>*/5 * * * *</schedule>
</job>
</group>
</config>

0 comments on commit 720d303

Please sign in to comment.