Skip to content

Commit

Permalink
Merge pull request #2040 from mailchimp/Issue2035-2.4
Browse files Browse the repository at this point in the history
Issue2035 2.4
  • Loading branch information
gonzaloebiz authored Nov 11, 2024
2 parents c37526e + ad2c280 commit 3e9115c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 12 deletions.
20 changes: 11 additions & 9 deletions Cron/Ecommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,19 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId)
$countProducts = 0;
$countOrders = 0;
$batchArray = [];
$this->_helper->resetCounters();
$this->_helper->resetCounters($storeId);
$results = $this->_apiSubscribers->sendSubscribers($storeId, $listId);
if ($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_ECOMMERCE_ACTIVE, $storeId)) {
$this->_helper->log('Generate Products payload');
$products = $this->_apiProduct->_sendProducts($storeId);
$countProducts = count($products);
$results = array_merge($results, $products);

$this->_helper->log('Generate Customers payload');
$customers = $this->_apiCustomer->sendCustomers($storeId);
$countCustomers = count($customers);
$results = array_merge($results, $customers);

if ($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_ALL_CUSTOMERS, $storeId)) {
$this->_helper->log('Generate Customers payload');
$customers = $this->_apiCustomer->sendCustomers($storeId);
$countCustomers = count($customers);
$results = array_merge($results, $customers);
}
$this->_helper->log('Generate Orders payload');
$orders = $this->_apiOrder->sendOrders($storeId);
$countOrders = count($orders);
Expand Down Expand Up @@ -261,14 +261,16 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId)
$syncBatches->setStatus(\Ebizmarts\MailChimp\Helper\Data::BATCH_PENDING);
$syncBatches->setMailchimpStoreId($mailchimpStoreId);
$syncBatches->setModifiedDate($this->_helper->getGmtDate());
if ($this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_ALL_CUSTOMERS, $storeId)) {
$syncBatches->setCustomersNewCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::CUS_NEW]);
$syncBatches->setCustomersModifiedCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::CUS_MOD]);
}
$syncBatches->setSubscribersNewCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::SUB_NEW]);
$syncBatches->setProductsNewCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::PRO_NEW]);
$syncBatches->setCustomersNewCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::CUS_NEW]);
$syncBatches->setCartsNewCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::QUO_NEW]);
$syncBatches->setOrdersNewCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::ORD_NEW]);
$syncBatches->setSubscribersModifiedCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::SUB_MOD]);
$syncBatches->setProductsModifiedCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::PRO_MOD]);
$syncBatches->setCustomersModifiedCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::CUS_MOD]);
$syncBatches->setCartsModifiedCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::QUO_MOD]);
$syncBatches->setOrdersModifiedCount($batchCounters[\Ebizmarts\MailChimp\Helper\Data::ORD_MOD]);
$syncBatches->getResource()->save($syncBatches);
Expand Down
11 changes: 8 additions & 3 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
const XML_PATH_CONFIRMATION_FLAG = 'newsletter/subscription/confirm';
const XML_PATH_STORE = 'mailchimp/ecommerce/store';
const XML_PATH_ECOMMERCE_ACTIVE = 'mailchimp/ecommerce/active';
const XML_PATH_ALL_CUSTOMERS = 'mailchimp/ecommerce/all_customers';
const XML_PATH_SYNC_DATE = 'mailchimp/general/mcminsyncdateflag';
const XML_ECOMMERCE_OPTIN = 'mailchimp/ecommerce/customer_optin';
const XML_ECOMMERCE_FIRSTDATE = 'mailchimp/ecommerce/firstdate';
Expand Down Expand Up @@ -1146,8 +1147,9 @@ public function modifyCounter($index, $increment = 1)
$this->counters[$index] = 1;
}
}
public function resetCounters()
public function resetCounters($storeId = null)
{
$this->counters = [];
$this->counters = [
self::SUB_NEW => 0,
self::SUB_MOD => 0,
Expand All @@ -1156,11 +1158,14 @@ public function resetCounters()
self::PRO_NEW => 0,
self::PRO_DELETED => 0,
self::PRO_MOD => 0,
self::CUS_NEW => 0,
self::CUS_MOD => 0,
self::QUO_NEW => 0,
self::QUO_MOD => 0
];
if ($this->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_ALL_CUSTOMERS, $storeId)) {
$this->counters [self::CUS_NEW] = 0;
$this->counters [self::CUS_MOD] = 0;
}

}
public function getCounters()
{
Expand Down
8 changes: 8 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="all_customers" translate="label comment" type="select" sortOrder="115" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Sync all customers</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment><![CDATA[Sync all customers or only customer with orders"]]></comment>
<depends>
<field id="*/*/active">1</field>
</depends>
</field>
<field id="customer_optin" translate="label" type="select" sortOrder="120" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Subscribe all customers to the newsletter</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
Expand Down
1 change: 1 addition & 0 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<mailchimp>
<ecommerce>
<campaign_action>sent,open,click</campaign_action>
<all_customers>Yes</all_customers>
</ecommerce>
</mailchimp>
</default>
Expand Down
1 change: 1 addition & 0 deletions i18n/es_ES.csv
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ MC Account name,Nombre de la cuenta de MC
Store name,Nombre de la tienda
List name,Nombre de la lista
Mailchimp Sync,Sincronización de Mailchimp
Sync all customers or only customer with orders, Sincronza todos los clientes o solo los que tienen ordenes
1 change: 1 addition & 0 deletions i18n/fr_FR.csv
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ MC Account name,Nom du compte MC
Store name,Nom de la boutique
List name,Nom de la liste
Mailchimp Sync,Synchronisation Mailchimp
Sync all customers or only customer with orders,Synchroniser tous les clients ou uniquement les clients avec les commandes
1 change: 1 addition & 0 deletions i18n/it_IT.csv
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,4 @@ MC Account name,Nome account MC
Store name,Nome negozio
List name,Nome elenco
Mailchimp Sync,Sincronizzazione Mailchimp
Sync all customers or only customer with orders,Sincronizza tutti i clienti o solo i clienti con gli ordini
2 changes: 2 additions & 0 deletions view/adminhtml/web/js/configapikey.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ define(
$("#row_mailchimp_abandonedcart_create_abandonedcart_automation").hide();
},
_showEcommerce: function () {
$("#row_mailchimp_ecommerce_all_customers").show();
$("#mailchimp_ecommerce_all_customers").show();
$("#row_mailchimp_ecommerce_customer_optin").show();
$("#mailchimp_ecommerce_customer_optin").show();
$("#row_mailchimp_ecommerce_firstdate").show();
Expand Down

0 comments on commit 3e9115c

Please sign in to comment.