Skip to content

Commit

Permalink
Merge pull request #84 from jorgeeurekalabs/main
Browse files Browse the repository at this point in the history
issue-10, issue-11, issue-44
  • Loading branch information
jorgeeurekalabs authored Dec 3, 2024
2 parents da31af3 + d88a2cb commit 9039a37
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 41 deletions.
20 changes: 15 additions & 5 deletions AbandonedCart/Model/AbandonedCartSendData.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function sendAbandonedCartData($quoteId = null): array
if ($quoteId) {
$abandonedCarts->addFieldToFilter('entity_id', ['eq' => $quoteId]);
}
$abandonedCarts->setPageSize($numberOfAbandonedCart);
$abandonedCarts->setPageSize($numberOfAbandonedCart)->setOrder('main_table.updated_at',"desc");
$abandonedCarts->getSelect()->join(array('address' => $abandonedCarts->getResource()->getTable('quote_address')), 'main_table.entity_id = address.quote_id')
->where("address.address_type='billing' and (main_table.customer_email is not null or address.email is not null)");
foreach ($abandonedCarts as $abandonedCart) {
Expand Down Expand Up @@ -288,7 +288,7 @@ public function sendAbandonedCartData($quoteId = null): array
"orderDiscounts" => [
"discountAmount" => $this->coreHelper->priceToCents($abandonedCart->getDiscountAmount())
],
"orderUrl" => $this->urlBuilder->getDirectUrl('checkout/cart'),
"orderUrl" => $this->urlBuilder->setScope($abandonedCart->getStoreId())->getDirectUrl('checkout/cart'),
"abandonedDate" => $this->dateTime->date(strtotime($abandonedUpdateDate),NULL,$timezone)->format('Y-m-d\TH:i:sP'),
"externalCreatedDate" => $this->dateTime->date(strtotime($abandonedCartRepository->getCreatedAt()),NULL,$timezone)->format('Y-m-d\TH:i:sP'),
"externalUpdatedDate" => $this->dateTime->date(strtotime($abandonedUpdateDate),NULL,$timezone)->format('Y-m-d\TH:i:sP'),
Expand Down Expand Up @@ -361,17 +361,26 @@ public function sendAbandonedCartData($quoteId = null): array
*/
private function getQuoteItemsData($entityId, $storeId): array
{

$quoteItemsData = [];
$this->appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true);
$quoteItems = $this->getQuoteItems($entityId);
foreach ($quoteItems as $quoteItem) {
$this->appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true);


$product = $this->_productRepositoryFactory->create()
->getById($quoteItem->getProductId());
->getById($quoteItem->getProductId(),false,$storeId);

$imageUrl = $this->imageHelperFactory->create()
->init($product, 'product_page_image_medium')->getUrl();
$this->appEmulation->stopEnvironmentEmulation();
$categories = $product->getCategoryCollection()->addAttributeToSelect('name');
$categoriesName = [];
foreach($categories as $category)
{
$categoriesName[] = $category->getName();
}
$categoriesName = implode(', ', $categoriesName);
$quoteItemsData[] = [
"externalid" => $quoteItem->getItemId(),
"name" => $quoteItem->getName(),
Expand All @@ -380,7 +389,8 @@ private function getQuoteItemsData($entityId, $storeId): array
"sku" => $quoteItem->getSku(),
"description" => $product->getDescription(),
"imageUrl" => $imageUrl,
"productUrl" => $product->getProductUrl()
"productUrl" => $product->getProductUrl(),
"category" => $categoriesName
];
}
return $quoteItemsData;
Expand Down
2 changes: 1 addition & 1 deletion AbandonedCart/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"config": {
"sort-packages": true
},
"version": "2.1.12",
"version": "2.1.14",
"require": {
"php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2",
"activecampaign/core": "2.1.*"
Expand Down
2 changes: 1 addition & 1 deletion AbandonedCart/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="ActiveCampaign_AbandonedCart" setup_version="2.1.12">
<module name="ActiveCampaign_AbandonedCart" setup_version="2.1.14">
<sequence>
<module name="Magento_Product"/>
<module name="Magento_Sales"/>
Expand Down
2 changes: 1 addition & 1 deletion Order/Cron/OrderSyncCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function execute(): void
'ac_order_sync_status',
['eq' => 0]
)
->setPageSize($OrderSyncNum);
->setPageSize($OrderSyncNum)->setOrder('main_table.entity_id',"desc");

foreach ($orderCollection as $order) {
try {
Expand Down
10 changes: 9 additions & 1 deletion Order/Model/OrderData/OrderDataSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,20 @@ public function orderDataSend($order): array

$imageUrl = $this->imageHelperFactory->create()
->init($item->getProduct(), 'product_thumbnail_image')->getUrl();
$categories = $item->getProduct()->getCategoryCollection()->addAttributeToSelect('name');
$categoriesName = [];
foreach($categories as $category)
{
$categoriesName[] = $category->getName();
}
$categoriesName = implode(', ', $categoriesName);

$items[] = [
"externalid" => $item->getProductId(),
"name" => $item->getName(),
"price" => $this->activeCampaignHelper->priceToCents($item->getPrice()),
"quantity" => $item->getQtyOrdered(),
"category" => implode(', ', $item->getProduct()->getCategoryIds()),
"category" => $categoriesName,
"sku" => $item->getSku(),
"description" => $item->getDescription(),
"imageUrl" => $imageUrl,
Expand Down
2 changes: 1 addition & 1 deletion Order/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"config": {
"sort-packages": true
},
"version": "2.1.7",
"version": "2.1.9",
"require": {
"php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2",
"activecampaign/core": "2.1.*"
Expand Down
2 changes: 1 addition & 1 deletion Order/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="ActiveCampaign_Order" setup_version="2.1.7">
<module name="ActiveCampaign_Order" setup_version="2.1.9">
<sequence>
<module name="ActiveCampaign_Core" />
<module name="ActiveCampaign_Customer"/>
Expand Down
38 changes: 14 additions & 24 deletions SyncLog/Cron/DeleteSyncLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,32 @@
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Store\Model\ScopeInterface;

use ActiveCampaign\SyncLog\Helper\Data;
class DeleteSyncLog
{

const SYNCLOG_TABLE = "sync_log";
const XML_PATH_ACTIVE_CAMPAIGN_SYNCLOG_ENABLE = "active_campaign/synclog/synclog_delete";

/**
* @var ScopeConfigInterface
*/
protected $scopeConfig;



/** @var ResourceConnection */
private $connection;

/** @var DateTime */
private $dateTime;

private $helper;

public function __construct(
ScopeConfigInterface $scopeConfig,
ResourceConnection $connection,
DateTime $dateTime
DateTime $dateTime,
Data $helper
)
{
$this->scopeConfig = $scopeConfig;
$this->connection = $connection;
$this->dateTime = $dateTime;
$this->helper = $helper;
}

/**
Expand All @@ -44,27 +43,18 @@ public function __construct(
*/
public function execute()
{
if($this->isDeletingEnabled()) {

if($this->helper->isDeletingEnabled()) {
$connection = $this->connection->getConnection();
$tableName = $connection->getTableName(self::SYNCLOG_TABLE);
$currentDate = $this->dateTime->gmtDate("Y-m-d", strtotime('-7 days'));
$currentDate = $this->dateTime->gmtDate("Y-m-d", strtotime('-'.$this->helper->removeAfterDays().' days'));
$whereConditions = [
$connection->quoteInto("creation_date < ?", $currentDate)
$connection->quoteInto("Date(creation_date) <= ?", $currentDate)
];

$connection->delete($tableName, $whereConditions);
}
}

/**
* @param null $scopeCode
* @return bool
*/
public function isDeletingEnabled($scopeCode = null): bool
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_ACTIVE_CAMPAIGN_SYNCLOG_ENABLE,
ScopeInterface::SCOPE_STORES,
$scopeCode
);
}

}
23 changes: 21 additions & 2 deletions SyncLog/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
class Data extends AbstractHelper
{
const ACTIVE_CAMPAIGN_SYNCLOG_MODE = "active_campaign/synclog/synclog_mode";


const ACTIVE_CAMPAIGN_REMOVE_AFTER_DAYS = "active_campaign/synclog/remove_after_days";
const XML_PATH_ACTIVE_CAMPAIGN_SYNCLOG_ENABLE = "active_campaign/synclog/synclog_delete";
/**
* @var \Magento\Framework\App\State *
*/
Expand All @@ -29,6 +29,13 @@ public function __construct(
$this->state = $state;
}

public function removeAfterDays($scopeCode = null){
return $this->scopeConfig->getValue(
self::ACTIVE_CAMPAIGN_REMOVE_AFTER_DAYS,
ScopeInterface::SCOPE_STORES,
$scopeCode
);
}
/**
* @param null $scopeCode
* @return bool
Expand All @@ -42,4 +49,16 @@ public function isLogError($scopeCode = null)
);
}

/**
* @param null $scopeCode
* @return bool
*/
public function isDeletingEnabled($scopeCode = null): bool
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_ACTIVE_CAMPAIGN_SYNCLOG_ENABLE,
ScopeInterface::SCOPE_STORES,
$scopeCode
);
}
}
2 changes: 1 addition & 1 deletion SyncLog/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"config": {
"sort-packages": true
},
"version": "2.1.2",
"version": "2.1.3",
"require": {
"php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2",
"activecampaign/core": "2.1.*"
Expand Down
8 changes: 7 additions & 1 deletion SyncLog/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@
</field>
<field id="synclog_delete" translate="label" type="select" sortOrder="10" showInDefault="1">
<label>SyncLog Delete</label>
<comment><![CDATA[Choosing yes will start deleting your past 7 days existing SyncLog stored in database.]]></comment>
<comment><![CDATA[Choosing yes will start deleting existing SyncLog stored in database.]]></comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="remove_after_days" type="text" sortOrder="19" showInDefault="1">
<label>Delete after (days)</label>
<depends>
<field id="synclog_delete">1</field>
</depends>
</field>
<field id="cron_minute" translate="label comment" type="text" sortOrder="20" showInDefault="1">
<label>Cron Minute</label>
<comment><![CDATA[0-59 Allowed value. Set * for every minute.]]></comment>
Expand Down
13 changes: 13 additions & 0 deletions SyncLog/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@
<synclog>
<synclog_delete>0</synclog_delete>
<synclog_mode>1</synclog_mode>
<remove_after_days>7</remove_after_days>
<cron_minute>*</cron_minute>
<cron_hour>*</cron_hour>
<cron_day>*</cron_day>
<cron_month>*</cron_month>
<cron_weekday>*</cron_weekday>

</synclog>
</active_campaign>
<crontab>
<default>
<jobs>
<activecampaign_synclog>
<schedule>
<cron_expr>* * * * *</cron_expr>
</schedule>
</activecampaign_synclog>
</jobs>
</default>
</crontab>
</default>
</config>
2 changes: 1 addition & 1 deletion SyncLog/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="ActiveCampaign_SyncLog" setup_version="2.1.2" />
<module name="ActiveCampaign_SyncLog" setup_version="2.1.3" />
</config>
2 changes: 1 addition & 1 deletion marketplace-composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "activecampaign/module-integration",
"description": "ActiveCampaign extension for Magento 2.3 and 2.4",
"type": "metapackage",
"version": "2.1.22",
"version": "2.1.23",
"license": [
"OSL-3.0"
],
Expand Down

0 comments on commit 9039a37

Please sign in to comment.