Skip to content

Commit

Permalink
Fixed issue when there is no abandoned cart update date.
Browse files Browse the repository at this point in the history
Fixed  Bundled Products with Dynamic SKUs enabled.
Fixed problem with acceptsMarketing.
  • Loading branch information
jorgeeurekalabs committed Apr 16, 2024
1 parent 900dbe9 commit e67ef40
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 20 deletions.
10 changes: 7 additions & 3 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) || ($abandonedCart->getCustomerId() && !$this->getCustomer($abandonedCart->getCustomerId())->getCustomerId())) {
if ($this->isGuest($quote) || ($abandonedCart->getCustomerId() && !$this->getCustomer($abandonedCart->getCustomerId())->getId())) {
$customerEmail = $quote->getBillingAddress()->getEmail();
if (!$customerEmail) {
$result['error'] = __('Customer Email does not exist.');
Expand All @@ -270,6 +270,10 @@ public function sendAbandonedCartData($quoteId = null): array
$abandonedCart->collectTotals();
$quoteItemsData = $this->getQuoteItemsData($abandonedCart->getEntityId(), $abandonedCart->getStoreId());
$abandonedCartRepository = $this->quoteRepository->get($abandonedCart->getId());
$abandonedUpdateDate = $abandonedCartRepository->getUpdatedAt();
if(is_null($abandonedUpdateDate)){
$abandonedUpdateDate = $abandonedCartRepository->getCreatedAt();
}
$timezone = $this->dateTime->getConfigTimezone(\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $abandonedCart->getStoreId());
$abandonedCartData = [
"ecomOrder" => [
Expand All @@ -281,9 +285,9 @@ public function sendAbandonedCartData($quoteId = null): array
"discountAmount" => $this->coreHelper->priceToCents($abandonedCart->getDiscountAmount())
],
"orderUrl" => $this->urlBuilder->getDirectUrl('checkout/cart'),
"abandonedDate" => $this->dateTime->date(strtotime($abandonedCartRepository->getUpdatedAt()),NULL,$timezone)->format('Y-m-d\TH:i:sP'),
"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($abandonedCartRepository->getUpdatedAt()),NULL,$timezone)->format('Y-m-d\TH:i:sP'),
"externalUpdatedDate" => $this->dateTime->date(strtotime($abandonedUpdateDate),NULL,$timezone)->format('Y-m-d\TH:i:sP'),
"shippingMethod" => $abandonedCart->getShippingAddress()->getShippingMethod(),
"totalPrice" => $this->coreHelper->priceToCents($abandonedCart->getGrandTotal()),
"shippingAmount" => $this->coreHelper->priceToCents($abandonedCart->getShippingAmount()),
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.8",
"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 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.8">
<module name="ActiveCampaign_AbandonedCart" setup_version="2.1.9">
<sequence>
<module name="Magento_Product"/>
<module name="Magento_Sales"/>
Expand Down
11 changes: 7 additions & 4 deletions Customer/Model/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function getEcomCustomerData($customer)
$ecomCustomer['connectionid'] = $this->coreHelper->getConnectionId($customer->getStoreId());
$ecomCustomer['externalid'] = $customer->getId();
$ecomCustomer['email'] = $customer->getEmail();
$ecomCustomerData['acceptsMarketing'] = (int)$this->subscriberFactory->create()->loadByCustomer($customer->getId(),$customer->getWebsiteId())->isSubscribed();
$ecomCustomer['acceptsMarketing'] = (int)$this->subscriberFactory->create()->loadBySubscriberEmail($customer->getEmail(), $customer->getWebsiteId())->isSubscribed();
$ecomCustomerData['ecomCustomer'] = $ecomCustomer;

return $ecomCustomerData;
Expand All @@ -178,13 +178,16 @@ public function getEcomCustomerData($customer)
/**
* @param null $billingId
* @return string|null
* @throws \Magento\Framework\Exception\LocalizedException
*/
private function getTelephone($billingId = null)
{
if ($billingId) {
$address = $this->addressRepository->getById($billingId);
return $address->getTelephone();
try{
$address = $this->addressRepository->getById($billingId);
return $address->getTelephone();
}catch (\Exception $exception){

}
}
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion Customer/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.8",
"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 Customer/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_Customer" setup_version="2.1.8">
<module name="ActiveCampaign_Customer" setup_version="2.1.9">
<sequence>
<module name="ActiveCampaign_Core"/>
</sequence>
Expand Down
9 changes: 4 additions & 5 deletions Order/Model/OrderData/OrderDataSend.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,20 +224,19 @@ public function orderDataSend($order): array
}
$timezone = $this->dateTime->getConfigTimezone(\Magento\Store\Model\ScopeInterface::SCOPE_STORES, $order->getStoreId());
foreach ($order->getAllVisibleItems() as $item) {
$product = $this->_productRepositoryFactory->create()
->get($item->getSku());

$imageUrl = $this->imageHelperFactory->create()
->init($product, 'product_thumbnail_image')->getUrl();
->init($item->getProduct(), 'product_thumbnail_image')->getUrl();
$items[] = [
"externalid" => $item->getProductId(),
"name" => $item->getName(),
"price" => $this->activeCampaignHelper->priceToCents($item->getPrice()),
"quantity" => $item->getQtyOrdered(),
"category" => implode(', ', $product->getCategoryIds()),
"category" => implode(', ', $item->getProduct()->getCategoryIds()),
"sku" => $item->getSku(),
"description" => $item->getDescription(),
"imageUrl" => $imageUrl,
"productUrl" => $product->getProductUrl()
"productUrl" => $item->getProduct()->getProductUrl()
];
}
$data = [
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.4",
"version": "2.1.5",
"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.4">
<module name="ActiveCampaign_Order" setup_version="2.1.5">
<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.17",
"version": "2.1.20",
"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.18",
"version": "2.1.20",
"license": [
"OSL-3.0"
],
Expand Down

0 comments on commit e67ef40

Please sign in to comment.