Skip to content

Commit fbf43ff

Browse files
Merge pull request #62 from jorgeeurekalabs/main
Newslleter
2 parents bf8b512 + 4000bf9 commit fbf43ff

File tree

34 files changed

+729
-96
lines changed

34 files changed

+729
-96
lines changed

.idea/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 0 additions & 5 deletions
This file was deleted.

.idea/magento2plugin.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/module-integration.iml

Lines changed: 0 additions & 16 deletions
This file was deleted.

.idea/php.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

AbandonedCart/Block/System/Config/SyncAbandonedCartData.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ public function getTotalAbandonedCart()
144144
['eq' => CronConfig::NOT_SYNCED],
145145
['eq' => CronConfig::FAIL_SYNCED]
146146
]
147-
);
147+
)
148+
->addFieldToFilter('items_count',['gt' => 0]);
148149

149150
return $collection->getSize();
150151
}
@@ -162,7 +163,8 @@ public function getNotSyncAbandonedCart()
162163
[
163164
['eq' => CronConfig::NOT_SYNCED]
164165
]
165-
);
166+
)
167+
->addFieldToFilter('items_count',['gt' => 0]);
166168

167169
return $collection->getSize();
168170
}
@@ -180,7 +182,8 @@ public function getFailedSync()
180182
[
181183
['eq' => CronConfig::FAIL_SYNCED]
182184
]
183-
);
185+
)
186+
->addFieldToFilter('items_count',['gt' => 0]);
184187

185188
return $collection->getSize();
186189
}

AbandonedCart/Model/AbandonedCartSendData.php

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ public function __construct(
176176
DateTime $dateTime,
177177
CartRepositoryInterface $quoteRepository,
178178
UrlInterface $urlBuilder
179-
) {
179+
)
180+
{
180181
$this->urlBuilder = $urlBuilder;
181182
$this->customerRepository = $customerRepository;
182183
$this->addressRepository = $addressRepository;
@@ -210,7 +211,7 @@ public function __construct(
210211
public function sendAbandonedCartData($quoteId = null): array
211212
{
212213
$result = [];
213-
$numberOfAbandonedCart = (int) $this->abandonedCartHelper->getNumberOfAbandonedCart();
214+
$numberOfAbandonedCart = (int)$this->abandonedCartHelper->getNumberOfAbandonedCart();
214215
$abandonedCarts = $this->quoteResourceCollectionFactory->create()
215216
->addFieldToSelect('*')
216217
->addFieldToFilter('ac_synced_date', [
@@ -230,7 +231,7 @@ public function sendAbandonedCartData($quoteId = null): array
230231
$abandonedCarts->addFieldToFilter('entity_id', ['eq' => $quoteId]);
231232
}
232233
$abandonedCarts->setPageSize($numberOfAbandonedCart);
233-
$abandonedCarts->getSelect()->join(array('address' => $abandonedCarts->getResource()->getTable('quote_address')),'main_table.entity_id = address.quote_id')
234+
$abandonedCarts->getSelect()->join(array('address' => $abandonedCarts->getResource()->getTable('quote_address')), 'main_table.entity_id = address.quote_id')
234235
->where("address.address_type='billing' and (main_table.customer_email is not null or address.email is not null)");
235236
foreach ($abandonedCarts as $abandonedCart) {
236237
$connectionId = $this->coreHelper->getConnectionId($abandonedCart->getStoreId());
@@ -296,7 +297,7 @@ public function sendAbandonedCartData($quoteId = null): array
296297
$customerModel = $this->customerFactory->create();
297298
$this->customerResource->load($customerModel, $customerId);
298299
if ($customerModel->getAcCustomerId()) {
299-
$this->customerId = $customerModel->getAcCustomerId();
300+
$this->customerId = $customerModel->getAcCustomerId();
300301
}
301302
}
302303
$abandonedCart->collectTotals();
@@ -311,7 +312,7 @@ public function sendAbandonedCartData($quoteId = null): array
311312
"orderDiscounts" => [
312313
"discountAmount" => $this->coreHelper->priceToCents($abandonedCart->getDiscountAmount())
313314
],
314-
"orderUrl" => $this->urlBuilder->getDirectUrl('checkout/cart'),
315+
"orderUrl" => $this->urlBuilder->getDirectUrl('checkout/cart'),
315316
"abandonedDate" => $abandonedCart->getCreatedAt(),
316317
"externalCreatedDate" => $abandonedCart->getCreatedAt(),
317318
"externalUpdatedDate" => $abandonedCart->getUpdatedAt(),
@@ -328,6 +329,7 @@ public function sendAbandonedCartData($quoteId = null): array
328329
];
329330

330331
try {
332+
331333
if (is_null($abandonedCart->getAcSyncedDate())) {
332334
$abandonedCartResult = $this->curl->sendRequestAbandonedCart(
333335
self::METHOD,
@@ -337,7 +339,7 @@ public function sendAbandonedCartData($quoteId = null): array
337339
} else {
338340
$abandonedCartResult = $this->curl->sendRequestAbandonedCart(
339341
self::UPDATE_METHOD,
340-
self::ABANDONED_CART_URL_ENDPOINT . "/" . (int) $abandonedCart->getAcOrderSyncId(),
342+
self::ABANDONED_CART_URL_ENDPOINT . "/" . (int)$abandonedCart->getAcOrderSyncId(),
341343
$abandonedCartData
342344
);
343345
}
@@ -407,7 +409,8 @@ private function getQuoteItems($quoteId): Collection
407409
$quoteItemCollection = $this->quoteItemCollectionFactory->create();
408410
return $quoteItemCollection
409411
->addFieldToSelect('*')
410-
->addFieldToFilter('quote_id', [$quoteId]);
412+
->addFieldToFilter('quote_id', [$quoteId])
413+
->addFieldToFilter('parent_item_id', ['null' => true]);
411414
}
412415

413416
/**
@@ -461,7 +464,8 @@ private function getFieldValues($customerId): array
461464
return $fieldValues;
462465
}
463466

464-
public function isGuest($quote): bool{
467+
public function isGuest($quote): bool
468+
{
465469
return is_null($quote->getCustomerId());
466470
}
467471

@@ -510,6 +514,7 @@ private function createEcomCustomer($customerId, $quote): void
510514
$ecomCustomer['connectionid'] = $connectionid;
511515
$ecomCustomer['externalid'] = $customerId;
512516
$ecomCustomer['email'] = $customerEmail;
517+
$ecomCustomer['acceptsMarketing'] = 1;
513518
$ecomCustomerData['ecomCustomer'] = $ecomCustomer;
514519
$AcCustomer = $this->curl->listAllCustomers(
515520
self::GET_METHOD,
@@ -538,22 +543,35 @@ private function createEcomCustomer($customerId, $quote): void
538543
}
539544

540545
if ($this->isGuest($quote)) {
541-
$ecomCustomerData = [
542-
"ecomCustomer" => [
543-
"connection" => $connectionid,
544-
'externals' => $quote->getBillingAddress()->getEmail(),
545-
'email' => $quote->getBillingAddress()->getEmail(),
546-
]
547-
];
548-
$ecomCustomerResult = $this->curl->createContacts(
549-
self::METHOD,
546+
547+
$ecomCustomerResult = $this->curl->listAllCustomers(
548+
self::GET_METHOD,
550549
self::ECOM_CUSTOMER_ENDPOINT,
551-
$ecomCustomerData
550+
$quote->getBillingAddress()->getEmail()
552551
);
553-
$ecomCustomerId = $ecomCustomerResult['data']['ecomCustomer']['id'] ?? null;
552+
if (isset($ecomCustomerResult['data']['ecomCustomers'][0])) {
553+
foreach ($ecomCustomerResult['data']['ecomCustomers'] as $Ac) {
554+
if ($Ac['connectionid'] === $connectionid) {
555+
$ecomCustomerId = $Ac['id'];
556+
}
557+
}
558+
} else {
559+
$ecomCustomerData = [
560+
"ecomCustomer" => [
561+
"connection" => $connectionid,
562+
'externals' => $quote->getBillingAddress()->getEmail(),
563+
'email' => $quote->getBillingAddress()->getEmail(),
564+
]
565+
];
566+
$ecomCustomerResult = $this->curl->createContacts(
567+
self::METHOD,
568+
self::ECOM_CUSTOMER_ENDPOINT,
569+
$ecomCustomerData
570+
);
571+
$ecomCustomerId = $ecomCustomerResult['data']['ecomCustomer']['id'] ?? null;
572+
}
554573
}
555-
556-
if ($ecomCustomerId !== 0) {
574+
if ($ecomCustomerId !== 0) {
557575
$syncStatus = CronConfig::SYNCED;
558576
} else {
559577
$syncStatus = CronConfig::FAIL_SYNCED;
@@ -564,7 +582,8 @@ private function createEcomCustomer($customerId, $quote): void
564582
} else {
565583
$this->saveCustomerResult($customerId, $syncStatus, $contactId, $ecomCustomerId);
566584
}
567-
} catch (\Exception $e) {
585+
} catch
586+
(\Exception $e) {
568587
$this->logger->critical("MODULE AbandonedCart: " . $e->getMessage());
569588
} catch (GuzzleException $e) {
570589
$this->logger->critical("MODULE AbandonedCart: " . $e->getMessage());

AbandonedCart/Ui/Component/Listing/AbandonedCartDataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected function _initSelect()
1919
'main_table.entity_id = quote_address.quote_id',
2020
['quote_address.quote_id','quote_address.email'],
2121
)
22-
->where("main_table.is_active = 1 AND quote_address.address_type = 'billing'");
22+
->where("main_table.is_active = 1 AND quote_address.address_type = 'billing' and main_table.items_count>0");
2323
return $this;
2424
}
2525
}

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.0",
12+
"version": "2.1.1",
1313
"require": {
1414
"php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2",
1515
"activecampaign/core": "2.1.*"

0 commit comments

Comments
 (0)