Skip to content

Commit 9039a37

Browse files
Merge pull request #84 from jorgeeurekalabs/main
issue-10, issue-11, issue-44
2 parents da31af3 + d88a2cb commit 9039a37

File tree

14 files changed

+87
-41
lines changed

14 files changed

+87
-41
lines changed

AbandonedCart/Model/AbandonedCartSendData.php

+15-5
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ public function sendAbandonedCartData($quoteId = null): array
244244
if ($quoteId) {
245245
$abandonedCarts->addFieldToFilter('entity_id', ['eq' => $quoteId]);
246246
}
247-
$abandonedCarts->setPageSize($numberOfAbandonedCart);
247+
$abandonedCarts->setPageSize($numberOfAbandonedCart)->setOrder('main_table.updated_at',"desc");
248248
$abandonedCarts->getSelect()->join(array('address' => $abandonedCarts->getResource()->getTable('quote_address')), 'main_table.entity_id = address.quote_id')
249249
->where("address.address_type='billing' and (main_table.customer_email is not null or address.email is not null)");
250250
foreach ($abandonedCarts as $abandonedCart) {
@@ -288,7 +288,7 @@ public function sendAbandonedCartData($quoteId = null): array
288288
"orderDiscounts" => [
289289
"discountAmount" => $this->coreHelper->priceToCents($abandonedCart->getDiscountAmount())
290290
],
291-
"orderUrl" => $this->urlBuilder->getDirectUrl('checkout/cart'),
291+
"orderUrl" => $this->urlBuilder->setScope($abandonedCart->getStoreId())->getDirectUrl('checkout/cart'),
292292
"abandonedDate" => $this->dateTime->date(strtotime($abandonedUpdateDate),NULL,$timezone)->format('Y-m-d\TH:i:sP'),
293293
"externalCreatedDate" => $this->dateTime->date(strtotime($abandonedCartRepository->getCreatedAt()),NULL,$timezone)->format('Y-m-d\TH:i:sP'),
294294
"externalUpdatedDate" => $this->dateTime->date(strtotime($abandonedUpdateDate),NULL,$timezone)->format('Y-m-d\TH:i:sP'),
@@ -361,17 +361,26 @@ public function sendAbandonedCartData($quoteId = null): array
361361
*/
362362
private function getQuoteItemsData($entityId, $storeId): array
363363
{
364+
364365
$quoteItemsData = [];
366+
$this->appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true);
365367
$quoteItems = $this->getQuoteItems($entityId);
366368
foreach ($quoteItems as $quoteItem) {
367-
$this->appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true);
369+
368370

369371
$product = $this->_productRepositoryFactory->create()
370-
->getById($quoteItem->getProductId());
372+
->getById($quoteItem->getProductId(),false,$storeId);
371373

372374
$imageUrl = $this->imageHelperFactory->create()
373375
->init($product, 'product_page_image_medium')->getUrl();
374376
$this->appEmulation->stopEnvironmentEmulation();
377+
$categories = $product->getCategoryCollection()->addAttributeToSelect('name');
378+
$categoriesName = [];
379+
foreach($categories as $category)
380+
{
381+
$categoriesName[] = $category->getName();
382+
}
383+
$categoriesName = implode(', ', $categoriesName);
375384
$quoteItemsData[] = [
376385
"externalid" => $quoteItem->getItemId(),
377386
"name" => $quoteItem->getName(),
@@ -380,7 +389,8 @@ private function getQuoteItemsData($entityId, $storeId): array
380389
"sku" => $quoteItem->getSku(),
381390
"description" => $product->getDescription(),
382391
"imageUrl" => $imageUrl,
383-
"productUrl" => $product->getProductUrl()
392+
"productUrl" => $product->getProductUrl(),
393+
"category" => $categoriesName
384394
];
385395
}
386396
return $quoteItemsData;

AbandonedCart/composer.json

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

AbandonedCart/etc/module.xml

+1-1
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.12">
9+
<module name="ActiveCampaign_AbandonedCart" setup_version="2.1.14">
1010
<sequence>
1111
<module name="Magento_Product"/>
1212
<module name="Magento_Sales"/>

Order/Cron/OrderSyncCron.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function execute(): void
9494
'ac_order_sync_status',
9595
['eq' => 0]
9696
)
97-
->setPageSize($OrderSyncNum);
97+
->setPageSize($OrderSyncNum)->setOrder('main_table.entity_id',"desc");
9898

9999
foreach ($orderCollection as $order) {
100100
try {

Order/Model/OrderData/OrderDataSend.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,20 @@ public function orderDataSend($order): array
227227

228228
$imageUrl = $this->imageHelperFactory->create()
229229
->init($item->getProduct(), 'product_thumbnail_image')->getUrl();
230+
$categories = $item->getProduct()->getCategoryCollection()->addAttributeToSelect('name');
231+
$categoriesName = [];
232+
foreach($categories as $category)
233+
{
234+
$categoriesName[] = $category->getName();
235+
}
236+
$categoriesName = implode(', ', $categoriesName);
237+
230238
$items[] = [
231239
"externalid" => $item->getProductId(),
232240
"name" => $item->getName(),
233241
"price" => $this->activeCampaignHelper->priceToCents($item->getPrice()),
234242
"quantity" => $item->getQtyOrdered(),
235-
"category" => implode(', ', $item->getProduct()->getCategoryIds()),
243+
"category" => $categoriesName,
236244
"sku" => $item->getSku(),
237245
"description" => $item->getDescription(),
238246
"imageUrl" => $imageUrl,

Order/composer.json

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

Order/etc/module.xml

+1-1
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_Order" setup_version="2.1.7">
3+
<module name="ActiveCampaign_Order" setup_version="2.1.9">
44
<sequence>
55
<module name="ActiveCampaign_Core" />
66
<module name="ActiveCampaign_Customer"/>

SyncLog/Cron/DeleteSyncLog.php

+14-24
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,32 @@
88
use Magento\Framework\Stdlib\DateTime\DateTime;
99
use Magento\Framework\App\Config\ScopeConfigInterface;
1010
use Magento\Store\Model\ScopeInterface;
11-
11+
use ActiveCampaign\SyncLog\Helper\Data;
1212
class DeleteSyncLog
1313
{
1414

1515
const SYNCLOG_TABLE = "sync_log";
16-
const XML_PATH_ACTIVE_CAMPAIGN_SYNCLOG_ENABLE = "active_campaign/synclog/synclog_delete";
1716

18-
/**
19-
* @var ScopeConfigInterface
20-
*/
21-
protected $scopeConfig;
17+
18+
2219

2320
/** @var ResourceConnection */
2421
private $connection;
2522

2623
/** @var DateTime */
2724
private $dateTime;
2825

26+
private $helper;
27+
2928
public function __construct(
30-
ScopeConfigInterface $scopeConfig,
3129
ResourceConnection $connection,
32-
DateTime $dateTime
30+
DateTime $dateTime,
31+
Data $helper
3332
)
3433
{
35-
$this->scopeConfig = $scopeConfig;
3634
$this->connection = $connection;
3735
$this->dateTime = $dateTime;
36+
$this->helper = $helper;
3837
}
3938

4039
/**
@@ -44,27 +43,18 @@ public function __construct(
4443
*/
4544
public function execute()
4645
{
47-
if($this->isDeletingEnabled()) {
46+
47+
if($this->helper->isDeletingEnabled()) {
4848
$connection = $this->connection->getConnection();
4949
$tableName = $connection->getTableName(self::SYNCLOG_TABLE);
50-
$currentDate = $this->dateTime->gmtDate("Y-m-d", strtotime('-7 days'));
50+
$currentDate = $this->dateTime->gmtDate("Y-m-d", strtotime('-'.$this->helper->removeAfterDays().' days'));
5151
$whereConditions = [
52-
$connection->quoteInto("creation_date < ?", $currentDate)
52+
$connection->quoteInto("Date(creation_date) <= ?", $currentDate)
5353
];
54+
5455
$connection->delete($tableName, $whereConditions);
5556
}
5657
}
5758

58-
/**
59-
* @param null $scopeCode
60-
* @return bool
61-
*/
62-
public function isDeletingEnabled($scopeCode = null): bool
63-
{
64-
return $this->scopeConfig->isSetFlag(
65-
self::XML_PATH_ACTIVE_CAMPAIGN_SYNCLOG_ENABLE,
66-
ScopeInterface::SCOPE_STORES,
67-
$scopeCode
68-
);
69-
}
59+
7060
}

SyncLog/Helper/Data.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
class Data extends AbstractHelper
1010
{
1111
const ACTIVE_CAMPAIGN_SYNCLOG_MODE = "active_campaign/synclog/synclog_mode";
12-
13-
12+
const ACTIVE_CAMPAIGN_REMOVE_AFTER_DAYS = "active_campaign/synclog/remove_after_days";
13+
const XML_PATH_ACTIVE_CAMPAIGN_SYNCLOG_ENABLE = "active_campaign/synclog/synclog_delete";
1414
/**
1515
* @var \Magento\Framework\App\State *
1616
*/
@@ -29,6 +29,13 @@ public function __construct(
2929
$this->state = $state;
3030
}
3131

32+
public function removeAfterDays($scopeCode = null){
33+
return $this->scopeConfig->getValue(
34+
self::ACTIVE_CAMPAIGN_REMOVE_AFTER_DAYS,
35+
ScopeInterface::SCOPE_STORES,
36+
$scopeCode
37+
);
38+
}
3239
/**
3340
* @param null $scopeCode
3441
* @return bool
@@ -42,4 +49,16 @@ public function isLogError($scopeCode = null)
4249
);
4350
}
4451

52+
/**
53+
* @param null $scopeCode
54+
* @return bool
55+
*/
56+
public function isDeletingEnabled($scopeCode = null): bool
57+
{
58+
return $this->scopeConfig->isSetFlag(
59+
self::XML_PATH_ACTIVE_CAMPAIGN_SYNCLOG_ENABLE,
60+
ScopeInterface::SCOPE_STORES,
61+
$scopeCode
62+
);
63+
}
4564
}

SyncLog/composer.json

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

SyncLog/etc/adminhtml/system.xml

+7-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@
1818
</field>
1919
<field id="synclog_delete" translate="label" type="select" sortOrder="10" showInDefault="1">
2020
<label>SyncLog Delete</label>
21-
<comment><![CDATA[Choosing yes will start deleting your past 7 days existing SyncLog stored in database.]]></comment>
21+
<comment><![CDATA[Choosing yes will start deleting existing SyncLog stored in database.]]></comment>
2222
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2323
</field>
24+
<field id="remove_after_days" type="text" sortOrder="19" showInDefault="1">
25+
<label>Delete after (days)</label>
26+
<depends>
27+
<field id="synclog_delete">1</field>
28+
</depends>
29+
</field>
2430
<field id="cron_minute" translate="label comment" type="text" sortOrder="20" showInDefault="1">
2531
<label>Cron Minute</label>
2632
<comment><![CDATA[0-59 Allowed value. Set * for every minute.]]></comment>

SyncLog/etc/config.xml

+13
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,25 @@
55
<synclog>
66
<synclog_delete>0</synclog_delete>
77
<synclog_mode>1</synclog_mode>
8+
<remove_after_days>7</remove_after_days>
89
<cron_minute>*</cron_minute>
910
<cron_hour>*</cron_hour>
1011
<cron_day>*</cron_day>
1112
<cron_month>*</cron_month>
1213
<cron_weekday>*</cron_weekday>
14+
1315
</synclog>
1416
</active_campaign>
17+
<crontab>
18+
<default>
19+
<jobs>
20+
<activecampaign_synclog>
21+
<schedule>
22+
<cron_expr>* * * * *</cron_expr>
23+
</schedule>
24+
</activecampaign_synclog>
25+
</jobs>
26+
</default>
27+
</crontab>
1528
</default>
1629
</config>

SyncLog/etc/module.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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_SyncLog" setup_version="2.1.2" />
3+
<module name="ActiveCampaign_SyncLog" setup_version="2.1.3" />
44
</config>

marketplace-composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "activecampaign/module-integration",
33
"description": "ActiveCampaign extension for Magento 2.3 and 2.4",
44
"type": "metapackage",
5-
"version": "2.1.22",
5+
"version": "2.1.23",
66
"license": [
77
"OSL-3.0"
88
],

0 commit comments

Comments
 (0)