diff --git a/AbandonedCart/Helper/Data.php b/AbandonedCart/Helper/Data.php index eec31c7..0e7b036 100644 --- a/AbandonedCart/Helper/Data.php +++ b/AbandonedCart/Helper/Data.php @@ -10,7 +10,7 @@ class Data extends AbstractHelper { const ACTIVE_CAMPAIGN_ABANDONED_CART_SYNC = "active_campaign/abandoned_cart/sync"; const ABANDONED_CART_NUMBER_OF_ABANDONED_CART = "active_campaign/abandoned_cart/number_of_abandoned_cart"; - + const ABANDONED_CART_MIN_INACTIVE_TIME = "active_campaign/abandoned_cart/min_inactive_time"; /** * @param null $scopeCode * @return bool @@ -49,4 +49,18 @@ public function getNumberOfAbandonedCart($scopeCode = null) $scopeCode ); } + + /** + * @param null $scopeCode + * @return mixed + */ + public function getMinInactiveTime($scopeCode = null) + { + return $this->scopeConfig->getValue( + self::ABANDONED_CART_MIN_INACTIVE_TIME, + ScopeInterface::SCOPE_STORES, + $scopeCode + ); + } + } diff --git a/AbandonedCart/Model/AbandonedCartSendData.php b/AbandonedCart/Model/AbandonedCartSendData.php index 4949bb1..f30e944 100644 --- a/AbandonedCart/Model/AbandonedCartSendData.php +++ b/AbandonedCart/Model/AbandonedCartSendData.php @@ -222,12 +222,16 @@ public function sendAbandonedCartData($quoteId = null): array { $result = []; $numberOfAbandonedCart = (int)$this->abandonedCartHelper->getNumberOfAbandonedCart(); + $minInactiveTime = (int) $this->abandonedCartHelper->getMinInactiveTime(); $abandonedCarts = $this->quoteResourceCollectionFactory->create() ->addFieldToSelect('*') ->addFieldToFilter('ac_synced_date', [ ['lt' => new \Zend_Db_Expr('main_table.updated_at')], - ['null' => true] + ['null' => true] ]) + ->addFieldToFilter('main_table.updated_at', + ['eq' => new \Zend_Db_Expr('IF( ac_synced_date is not null or main_table.updated_at < DATE_SUB(NOW(), INTERVAL '.$minInactiveTime.' minute), main_table.updated_at,-1)')] + ) ->addFieldToFilter( 'is_active', '1' diff --git a/AbandonedCart/composer.json b/AbandonedCart/composer.json index daefff2..5e9f674 100644 --- a/AbandonedCart/composer.json +++ b/AbandonedCart/composer.json @@ -9,7 +9,7 @@ "config": { "sort-packages": true }, - "version": "2.1.9", + "version": "2.1.10", "require": { "php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2", "activecampaign/core": "2.1.*" diff --git a/AbandonedCart/etc/adminhtml/system.xml b/AbandonedCart/etc/adminhtml/system.xml index 82a2b9b..77f526c 100644 --- a/AbandonedCart/etc/adminhtml/system.xml +++ b/AbandonedCart/etc/adminhtml/system.xml @@ -52,13 +52,19 @@ 1 - + + + + + ActiveCampaign\AbandonedCart\Block\System\Config\SyncAbandonedCartData 1 + + diff --git a/AbandonedCart/etc/config.xml b/AbandonedCart/etc/config.xml index 0e5d833..412b6c9 100644 --- a/AbandonedCart/etc/config.xml +++ b/AbandonedCart/etc/config.xml @@ -11,6 +11,7 @@ * * * + 60 diff --git a/AbandonedCart/etc/module.xml b/AbandonedCart/etc/module.xml index 48c0079..ca7a73f 100644 --- a/AbandonedCart/etc/module.xml +++ b/AbandonedCart/etc/module.xml @@ -6,7 +6,7 @@ */ --> - + diff --git a/Customer/Model/Customer.php b/Customer/Model/Customer.php index a12f83a..9550c16 100644 --- a/Customer/Model/Customer.php +++ b/Customer/Model/Customer.php @@ -292,7 +292,7 @@ public function createGuestCustomer($data, $storeId){ $ecomCustomerData=[]; $data['connectionid'] = $this->coreHelper->getConnectionId($storeId); $data['externalid'] = $data['email']; - $data['acceptsMarketing'] = (int)$this->subscriberFactory->create()->loadBySubscriberEmail($data['email'],$this->storeManager->getStore()->getWebsiteId())->isSubscribed(); + $data['acceptsMarketing'] = (int)$this->subscriberFactory->create()->loadBySubscriberEmail($data['email'],$this->storeManager->getStore($storeId)->getWebsiteId())->isSubscribed(); $ecomCustomerData['ecomCustomer'] = $data; if (!$acCustomer) { $result = $this->curl->createContacts(self::METHOD, self::ECOM_CUSTOMER_ENDPOINT, $ecomCustomerData); diff --git a/Customer/composer.json b/Customer/composer.json index 816edde..97a1abf 100644 --- a/Customer/composer.json +++ b/Customer/composer.json @@ -9,7 +9,7 @@ "config": { "sort-packages": true }, - "version": "2.1.10", + "version": "2.1.11", "require": { "php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2", "activecampaign/core": "2.1.*" diff --git a/Customer/etc/module.xml b/Customer/etc/module.xml index 1942019..2e96dd4 100644 --- a/Customer/etc/module.xml +++ b/Customer/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/Newsletter/Cron/NewsletterSyncCron.php b/Newsletter/Cron/NewsletterSyncCron.php index b64bf1d..c442126 100644 --- a/Newsletter/Cron/NewsletterSyncCron.php +++ b/Newsletter/Cron/NewsletterSyncCron.php @@ -135,10 +135,8 @@ public function execute(): void ->setOrder('change_status_at', 'desc') ->setPageSize($newsletterSyncNum) ->setCurPage(1); - foreach ($newsletterCollection as $news) { $acContact=NULL; - try { $contactData = [ 'email' => $news->getSubscriberEmail() @@ -147,16 +145,8 @@ public function execute(): void $result = $this->customer->updateCustomer($this->getCustomer($news->getCustomerId())); $acContact = $result['ac_contact_id']; }else{ - $orders = $this->orderCollectionFactory->create()->addAttributeToFilter('customer_email', $news->getEmail())->setOrder('entity_id','desc'); - - - if($orders->getSize()>0){ - $store = $orders->getFirstItem()->getStoreId(); - $this->customer->createGuestCustomer($contactData,$store); - }else{ $acContact = $this->customer->createGuestContact($contactData); - } - + $this->customer->createGuestCustomer($contactData,$news->getStoreId()); } if ($acContact) { diff --git a/Newsletter/composer.json b/Newsletter/composer.json index b1c227e..e0e7e4e 100644 --- a/Newsletter/composer.json +++ b/Newsletter/composer.json @@ -9,7 +9,7 @@ "config": { "sort-packages": true }, - "version": "1.0.4", + "version": "1.0.5", "require": { "php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2", "activecampaign/core": "2.1.*" diff --git a/Newsletter/etc/module.xml b/Newsletter/etc/module.xml index 36d0732..26b6621 100644 --- a/Newsletter/etc/module.xml +++ b/Newsletter/etc/module.xml @@ -1,7 +1,7 @@ - + diff --git a/composer.json b/composer.json index 965d287..768ea04 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "activecampaign/module-integration", "description": "ActiveCampaign extension for Magento 2.3 and 2.4", "type": "magento2-component", - "version": "2.1.21", + "version": "2.1.22", "license": "OSL-3.0", "require": { "php": "~7.3.0||~7.4.0||~8.0||~8.1||~8.2" diff --git a/marketplace-composer.json b/marketplace-composer.json index acd7cce..8bbcf36 100644 --- a/marketplace-composer.json +++ b/marketplace-composer.json @@ -2,7 +2,7 @@ "name": "activecampaign/module-integration", "description": "ActiveCampaign extension for Magento 2.3 and 2.4", "type": "metapackage", - "version": "2.1.21", + "version": "2.1.22", "license": [ "OSL-3.0" ],