Skip to content

Commit

Permalink
Merge pull request #69 from jorgeeurekalabs/main
Browse files Browse the repository at this point in the history
Fix abandoned Card and Orders issues
  • Loading branch information
jorgeeurekalabs authored Mar 1, 2024
2 parents 208c848 + 205cf4f commit e4acaca
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 19 deletions.
8 changes: 6 additions & 2 deletions AbandonedCart/Model/AbandonedCartSendData.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function sendAbandonedCartData($quoteId = null): array

$quote = $this->quoteRepository->get($abandonedCart->getEntityId());
$AcCustomer = NULL;
if ($this->isGuest($quote)) {
if ($this->isGuest($quote) || ($abandonedCart->getCustomerId() && !$this->getCustomer($abandonedCart->getCustomerId())->getCustomerId())) {
$customerEmail = $quote->getBillingAddress()->getEmail();
if (!$customerEmail) {
$result['error'] = __('Customer Email does not exist.');
Expand Down Expand Up @@ -402,7 +402,11 @@ private function saveResult($quoteId, $acOrderId, $syncStatus): void
if ($quoteModel->getEntityId()) {
$quoteModel->setAcOrderSyncId($acOrderId);
$quoteModel->setAcSyncStatus($syncStatus);
$quoteModel->setAcSyncedDate($this->dateTime->date()->format('Y-m-d H:i:s'));
if(!$quoteModel->getUpdatedAt()){
$quoteModel->setAcSyncedDate($this->dateTime->date()->modify('+1 day')->format('Y-m-d H:i:s'));
}else{
$quoteModel->setAcSyncedDate($this->dateTime->date($quoteModel->getUpdatedAt())->modify('+1 day')->format('Y-m-d H:i:s'));
}
}
$quoteModel->save();
}
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.5",
"version": "2.1.6",
"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.5">
<module name="ActiveCampaign_AbandonedCart" setup_version="2.1.6">
<sequence>
<module name="Magento_Product"/>
<module name="Magento_Sales"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public function getNewsletterCountHelper(array $filter = []): int
{

$this->newsletterCollection->clear()->getSelect()->reset(\Magento\Framework\Db\Select::WHERE);
$this->newsletterCollection->addFieldToFilter('customer_id', null);
if (count($filter)) {
foreach ($filter as $fil) {
$this->newsletterCollection->addFieldToFilter($fil['field'], $fil['value']);
Expand Down
2 changes: 1 addition & 1 deletion Newsletter/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"config": {
"sort-packages": true
},
"version": "1.0.2",
"version": "1.0.3",
"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 Newsletter/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?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_Newsletter" setup_version="1.0.2">
<module name="ActiveCampaign_Newsletter" setup_version="1.0.3">
<sequence>
<module name="ActiveCampaign_Core"/>
<module name="ActiveCampaign_Customer"/>
Expand Down
27 changes: 18 additions & 9 deletions Order/Model/OrderData/OrderDataSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,29 @@ public function orderDataSend($order): array
try {
$connectionId = $this->activeCampaignHelper->getConnectionId($order->getStoreId());
$customerId = $order->getCustomerId();
$customerAcId = 0;
$quote = $this->quoteRepository->get($order->getQuoteId());
$quoteModel = null;
try{
$quoteModel = $this->quoteRepository->get($order->getQuoteId());
$quote = $quoteModel;
}catch (\Exception $e){
$quote = $order;
}

if ($customerId) {
$AcCustomer = $this->customer->updateCustomer($this->getCustomer($customerId));
}else{
$customerEmail = $quote->getBillingAddress()->getEmail();
$contact['email'] = $quote->getBillingAddress()->getEmail();
$contact['email'] = $customerEmail;
$contact['firstName'] = $quote->getBillingAddress()->getFirstname();
$contact['lastName'] = $quote->getBillingAddress()->getLastname();
$contact['phone'] = $quote->getBillingAddress()->getTelephone();
$contact['fieldValues'] = [];
$AcCustomer = $this->customer->createGuestCustomer($contact,$quote->getStoreId());
$AcCustomer = $this->customer->createGuestCustomer($contact,$order->getStoreId());
}
$customerAcId = $AcCustomer['ac_customer_id'];
$this->saveCustomerResultQuote($quote,$customerAcId);

if($quoteModel) {
$this->saveCustomerResultQuote($quote, $customerAcId);
}
foreach ($order->getAllVisibleItems() as $item) {
$product = $this->_productRepositoryFactory->create()
->get($item->getSku());
Expand All @@ -227,7 +234,7 @@ public function orderDataSend($order): array
"ecomOrder" => [
"externalid" => $order->getId(),
"source" => 1,
"email" => $quote->getBillingAddress()->getEmail(),
"email" => $order->getCustomerEmail(),
"orderProducts" => $items,
"orderDiscounts" => [
"discountAmount" => $this->activeCampaignHelper->priceToCents($order->getDiscountAmount())
Expand All @@ -247,8 +254,10 @@ public function orderDataSend($order): array
];

if (!$order->getAcOrderSyncId()) {

$AcOrderId = $quote->getAcOrderSyncId();
$AcOrderId=0;
if($quoteModel){
$AcOrderId = $quote->getAcOrderSyncId();
}
if($AcOrderId > 0){
$result = $this->curl->orderDataSend(
self::UPDATE_METHOD,
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.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
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.2">
<module name="ActiveCampaign_Order" setup_version="2.1.3">
<sequence>
<module name="ActiveCampaign_Core" />
<module name="ActiveCampaign_Customer"/>
Expand Down
2 changes: 1 addition & 1 deletion 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": "magento2-component",
"version": "2.0.15",
"version": "2.0.16",
"license": "OSL-3.0",
"require": {
"php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2"
Expand Down
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.0.15",
"version": "2.0.16",
"license": [
"OSL-3.0"
],
Expand Down

0 comments on commit e4acaca

Please sign in to comment.