Skip to content

Commit

Permalink
ask for activity only when the store is synced #1866 for 2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Feb 20, 2024
1 parent 127dfb6 commit ac37515
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
const XML_MAGENTO_MAIL = 'mailchimp/general/magentoemail';
const XML_SEND_PROMO = 'mailchimp/ecommerce/send_promo';
const XML_INCLUDING_TAXES = 'mailchimp/ecommerce/including_taxes';
const XML_CAMPAIGN_ACTION = 'mailchimp/ecommerce/campaign_action';
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';
Expand Down
14 changes: 9 additions & 5 deletions Model/Api/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ protected function _getModifiedOrders($magentoStoreId)
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,
$magentoStoreId
);
$isSynced = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_IS_SYNC, $magentoStoreId);
$modifiedOrders = $this->_getCollection();
// select orders for the current Magento store id
$modifiedOrders->addFieldToFilter('store_id', ['eq' => $magentoStoreId]);
Expand Down Expand Up @@ -205,7 +206,7 @@ protected function _getModifiedOrders($magentoStoreId)
}
}

$orderJson = $this->generatePOSTPayload($order, $mailchimpStoreId, $magentoStoreId, true);
$orderJson = $this->generatePOSTPayload($order, $mailchimpStoreId, $magentoStoreId, true, $isSynced);
if ($this->modifiedOrder) {
$order->save();
$this->modifiedOrder = false;
Expand Down Expand Up @@ -248,6 +249,7 @@ protected function _getNewOrders($magentoStoreId)
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,
$magentoStoreId
);
$isSynced = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_IS_SYNC, $magentoStoreId);
$newOrders = $this->_getCollection();
// select carts for the current Magento store id
$newOrders->addFieldToFilter('store_id', ['eq' => $magentoStoreId]);
Expand Down Expand Up @@ -290,7 +292,7 @@ protected function _getNewOrders($magentoStoreId)
$this->_counter++;
}
}
$orderJson = $this->generatePOSTPayload($order, $mailchimpStoreId, $magentoStoreId);
$orderJson = $this->generatePOSTPayload($order, $mailchimpStoreId, $magentoStoreId, false, $isSynced);
if ($this->modifiedOrder) {
$order->save();
$this->modifiedOrder = false;
Expand Down Expand Up @@ -338,13 +340,14 @@ protected function generatePOSTPayload(
\Magento\Sales\Model\Order $order,
$mailchimpStoreId,
$magentoStoreId,
$isModifiedOrder = false
$isModifiedOrder,
$isSynced
) {
$data = [];
$data['id'] = $order->getIncrementId();
if ($order->getMailchimpCampaignId()) {
$data['campaign_id'] = $order->getMailchimpCampaignId();
} else {
} elseif ($isSynced) {
if ($campaignId = $this->getCampaign($magentoStoreId, $order->getCustomerEmail())) {
$data['campaign_id'] = $campaignId;
$order->setMailchimpCampaignId($campaignId);
Expand Down Expand Up @@ -758,8 +761,9 @@ protected function getCampaign($store, $email)
{
$campaign_id = null;
$api = $this->_helper->getApi($store);
$actions = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_CAMPAIGN_ACTION, $store);
try {
$activity = $api->lists->members->memberActivity->get($this->_helper->getDefaultList($store), md5($email), null, null);
$activity = $api->lists->members->memberActivity->get($this->_helper->getDefaultList($store), md5($email), null, null, $actions);
if ($activity) {
foreach ($activity['activity'] as $act) {
if (key_exists('action', $act) && ($act['action'] == 'click' || $act['action'] == 'open')&& key_exists('campaign_id', $act) && $act['campaign_id']) {
Expand Down

0 comments on commit ac37515

Please sign in to comment.