Skip to content

Commit 82b5f72

Browse files
Merge pull request #81 from jorgeeurekalabs/main
DEVREL-52 DEVREL-40
2 parents 7d94bbc + 82c3607 commit 82b5f72

File tree

14 files changed

+38
-23
lines changed

14 files changed

+38
-23
lines changed

AbandonedCart/Helper/Data.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Data extends AbstractHelper
1010
{
1111
const ACTIVE_CAMPAIGN_ABANDONED_CART_SYNC = "active_campaign/abandoned_cart/sync";
1212
const ABANDONED_CART_NUMBER_OF_ABANDONED_CART = "active_campaign/abandoned_cart/number_of_abandoned_cart";
13-
13+
const ABANDONED_CART_MIN_INACTIVE_TIME = "active_campaign/abandoned_cart/min_inactive_time";
1414
/**
1515
* @param null $scopeCode
1616
* @return bool
@@ -49,4 +49,18 @@ public function getNumberOfAbandonedCart($scopeCode = null)
4949
$scopeCode
5050
);
5151
}
52+
53+
/**
54+
* @param null $scopeCode
55+
* @return mixed
56+
*/
57+
public function getMinInactiveTime($scopeCode = null)
58+
{
59+
return $this->scopeConfig->getValue(
60+
self::ABANDONED_CART_MIN_INACTIVE_TIME,
61+
ScopeInterface::SCOPE_STORES,
62+
$scopeCode
63+
);
64+
}
65+
5266
}

AbandonedCart/Model/AbandonedCartSendData.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,16 @@ public function sendAbandonedCartData($quoteId = null): array
222222
{
223223
$result = [];
224224
$numberOfAbandonedCart = (int)$this->abandonedCartHelper->getNumberOfAbandonedCart();
225+
$minInactiveTime = (int) $this->abandonedCartHelper->getMinInactiveTime();
225226
$abandonedCarts = $this->quoteResourceCollectionFactory->create()
226227
->addFieldToSelect('*')
227228
->addFieldToFilter('ac_synced_date', [
228229
['lt' => new \Zend_Db_Expr('main_table.updated_at')],
229-
['null' => true]
230+
['null' => true]
230231
])
232+
->addFieldToFilter('main_table.updated_at',
233+
['eq' => new \Zend_Db_Expr('IF( ac_synced_date is not null or main_table.updated_at < DATE_SUB(NOW(), INTERVAL '.$minInactiveTime.' minute), main_table.updated_at,-1)')]
234+
)
231235
->addFieldToFilter(
232236
'is_active',
233237
'1'

AbandonedCart/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"config": {
1010
"sort-packages": true
1111
},
12-
"version": "2.1.9",
12+
"version": "2.1.10",
1313
"require": {
1414
"php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2",
1515
"activecampaign/core": "2.1.*"

AbandonedCart/etc/adminhtml/system.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,19 @@
5252
<field id="sync">1</field>
5353
</depends>
5454
</field>
55-
<field id="ac_abandoned_cart_syncing" translate="label comment" type="button" sortOrder="40" showInDefault="1">
55+
<field id="min_inactive_time" translate="label comment" type="text" sortOrder="40" showInDefault="1">
56+
<label>Minimum inactivity time</label>
57+
<comment><![CDATA[Minimum inactivity time in minutes]]></comment>
58+
</field>
59+
<field id="ac_abandoned_cart_syncing" translate="label comment" type="button" sortOrder="50" showInDefault="1">
5660
<frontend_model>ActiveCampaign\AbandonedCart\Block\System\Config\SyncAbandonedCartData</frontend_model>
5761
<label>Sync Abandoned Cart Data</label>
5862
<depends>
5963
<field id="active_campaign/abandoned_cart/sync">1</field>
6064
</depends>
6165
</field>
66+
67+
6268
</group>
6369
</section>
6470
</system>

AbandonedCart/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<cron_day>*</cron_day>
1212
<cron_month>*</cron_month>
1313
<cron_weekday>*</cron_weekday>
14+
<min_inactive_time>60</min_inactive_time>
1415
</abandoned_cart>
1516
</active_campaign>
1617
</default>

AbandonedCart/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="ActiveCampaign_AbandonedCart" setup_version="2.1.9">
9+
<module name="ActiveCampaign_AbandonedCart" setup_version="2.1.10">
1010
<sequence>
1111
<module name="Magento_Product"/>
1212
<module name="Magento_Sales"/>

Customer/Model/Customer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ public function createGuestCustomer($data, $storeId){
292292
$ecomCustomerData=[];
293293
$data['connectionid'] = $this->coreHelper->getConnectionId($storeId);
294294
$data['externalid'] = $data['email'];
295-
$data['acceptsMarketing'] = (int)$this->subscriberFactory->create()->loadBySubscriberEmail($data['email'],$this->storeManager->getStore()->getWebsiteId())->isSubscribed();
295+
$data['acceptsMarketing'] = (int)$this->subscriberFactory->create()->loadBySubscriberEmail($data['email'],$this->storeManager->getStore($storeId)->getWebsiteId())->isSubscribed();
296296
$ecomCustomerData['ecomCustomer'] = $data;
297297
if (!$acCustomer) {
298298
$result = $this->curl->createContacts(self::METHOD, self::ECOM_CUSTOMER_ENDPOINT, $ecomCustomerData);

Customer/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"config": {
1010
"sort-packages": true
1111
},
12-
"version": "2.1.10",
12+
"version": "2.1.11",
1313
"require": {
1414
"php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2",
1515
"activecampaign/core": "2.1.*"

Customer/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
3-
<module name="ActiveCampaign_Customer" setup_version="2.1.10">
3+
<module name="ActiveCampaign_Customer" setup_version="2.1.11">
44
<sequence>
55
<module name="ActiveCampaign_Core"/>
66
</sequence>

Newsletter/Cron/NewsletterSyncCron.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,8 @@ public function execute(): void
135135
->setOrder('change_status_at', 'desc')
136136
->setPageSize($newsletterSyncNum)
137137
->setCurPage(1);
138-
139138
foreach ($newsletterCollection as $news) {
140139
$acContact=NULL;
141-
142140
try {
143141
$contactData = [
144142
'email' => $news->getSubscriberEmail()
@@ -147,16 +145,8 @@ public function execute(): void
147145
$result = $this->customer->updateCustomer($this->getCustomer($news->getCustomerId()));
148146
$acContact = $result['ac_contact_id'];
149147
}else{
150-
$orders = $this->orderCollectionFactory->create()->addAttributeToFilter('customer_email', $news->getEmail())->setOrder('entity_id','desc');
151-
152-
153-
if($orders->getSize()>0){
154-
$store = $orders->getFirstItem()->getStoreId();
155-
$this->customer->createGuestCustomer($contactData,$store);
156-
}else{
157148
$acContact = $this->customer->createGuestContact($contactData);
158-
}
159-
149+
$this->customer->createGuestCustomer($contactData,$news->getStoreId());
160150
}
161151

162152
if ($acContact) {

0 commit comments

Comments
 (0)