From 49e1d370773c516fe59322ea3760cc8d681c8e8f Mon Sep 17 00:00:00 2001 From: Jorge Venzon Date: Fri, 30 Dec 2022 15:49:54 -0300 Subject: [PATCH 1/5] Synchronize customer data updates. Unnecessary folders were deleted. --- .../System/Config/SyncAbandonedCartData.php | 187 ------ .../Controller/Adminhtml/Index/Index.php | 43 -- .../Controller/Adminhtml/Index/MassSync.php | 101 --- .../Controller/Adminhtml/Index/Sync.php | 73 --- .../Controller/Adminhtml/Index/Syncaccart.php | 76 --- .../AbandonedCart/Cron/AbandonedCartSync.php | 45 -- AbandonedCart/AbandonedCart/Helper/Data.php | 52 -- .../Model/AbandonedCartSendData.php | 604 ------------------ .../AbandonedCart/Model/Config/CronConfig.php | 111 ---- .../Model/ResourceModel/Quote/Collection.php | 19 - ...uestPaymentInformationManagementPlugin.php | 61 -- .../PaymentInformationManagementPlugin.php | 70 -- .../Listing/AbandonedCartDataProvider.php | 25 - .../Component/Listing/Column/AcSyncStatus.php | 42 -- .../Ui/Component/Listing/Column/Actions.php | 62 -- AbandonedCart/AbandonedCart/composer.json | 26 - AbandonedCart/AbandonedCart/etc/acl.xml | 18 - .../AbandonedCart/etc/adminhtml/menu.xml | 12 - .../AbandonedCart/etc/adminhtml/routes.xml | 14 - .../AbandonedCart/etc/adminhtml/system.xml | 65 -- AbandonedCart/AbandonedCart/etc/config.xml | 17 - AbandonedCart/AbandonedCart/etc/crontab.xml | 7 - AbandonedCart/AbandonedCart/etc/db_schema.xml | 11 - AbandonedCart/AbandonedCart/etc/di.xml | 24 - .../etc/extension_attributes.xml | 9 - AbandonedCart/AbandonedCart/etc/module.xml | 17 - AbandonedCart/AbandonedCart/registration.php | 9 - .../layout/acecommerce_index_index.xml | 9 - .../config/sync_abandoned_cart_data.phtml | 95 --- .../ui_component/abandoned_cart_listing.xml | 182 ------ .../System/Config/ConnectActiveCampaign.php | 162 ----- .../Adminhtml/System/Config/FieldDisable.php | 53 -- .../Adminhtml/System/Config/Connect.php | 233 ------- .../Adminhtml/System/Config/Disconnect.php | 168 ----- Core/Core/Helper/Curl.php | 453 ------------- Core/Core/Helper/Data.php | 219 ------- Core/Core/Logger/Handler.php | 21 - Core/Core/Logger/Logger.php | 9 - Core/Core/composer.json | 24 - Core/Core/etc/acl.xml | 16 - Core/Core/etc/adminhtml/routes.xml | 8 - Core/Core/etc/adminhtml/system.xml | 40 -- Core/Core/etc/di.xml | 16 - Core/Core/etc/module.xml | 4 - Core/Core/registration.php | 8 - Core/Core/view/adminhtml/requirejs-config.js | 7 - .../templates/system/config/connection.phtml | 40 -- Core/Core/view/adminhtml/web/js/connection.js | 125 ---- Customer/Cron/CustomerSync.php | 60 +- .../System/Config/CustomerSyncStatus.php | 184 ------ .../Block/Adminhtml/System/Config/Widget.php | 27 - .../Adminhtml/Customer/MassSync.php | 121 ---- Customer/Customer/Cron/CustomerSync.php | 224 ------- Customer/Customer/Helper/Data.php | 62 -- Customer/Customer/Model/Config/CronConfig.php | 111 ---- Customer/Customer/Model/Customer.php | 179 ------ .../Customer/Observer/CustomerSaveAfter.php | 92 --- .../Data/AddCustomerAttributeAcContactId.php | 120 ---- .../Data/AddCustomerAttributeAcCustomerId.php | 120 ---- .../Data/AddCustomerAttributeAcSyncStatus.php | 120 ---- .../Component/Listing/Column/AcSyncStatus.php | 42 -- Customer/Customer/composer.json | 25 - Customer/Customer/etc/adminhtml/routes.xml | 8 - Customer/Customer/etc/adminhtml/system.xml | 66 -- Customer/Customer/etc/config.xml | 22 - Customer/Customer/etc/crontab.xml | 7 - Customer/Customer/etc/events.xml | 5 - Customer/Customer/etc/module.xml | 8 - Customer/Customer/registration.php | 8 - .../system/config/customer_sync_status.phtml | 49 -- .../ui_component/customer_listing.xml | 27 - Customer/Helper/Data.php | 28 +- Customer/etc/config.xml | 1 + .../System/Config/OrderSyncStatus.php | 139 ---- .../Block/Adminhtml/System/Config/Widget.php | 26 - .../Controller/Adminhtml/Order/Masssync.php | 101 --- Order/Order/Cron/OrderSyncCron.php | 115 ---- Order/Order/Helper/Data.php | 55 -- Order/Order/Model/Config/CronConfig.php | 111 ---- Order/Order/Model/OrderData/OrderDataSend.php | 456 ------------- Order/Order/Observer/OrderSync.php | 98 --- .../Component/Listing/Column/OrderStatus.php | 51 -- Order/Order/composer.json | 25 - Order/Order/etc/adminhtml/routes.xml | 8 - Order/Order/etc/adminhtml/system.xml | 65 -- Order/Order/etc/config.xml | 17 - Order/Order/etc/crontab.xml | 8 - Order/Order/etc/db_schema.xml | 12 - Order/Order/etc/events.xml | 6 - Order/Order/etc/extension_attributes.xml | 9 - Order/Order/etc/module.xml | 8 - Order/Order/registration.php | 8 - .../system/config/order_sync_status.phtml | 49 -- .../ui_component/sales_order_grid.xml | 30 - SyncLog/SyncLog/Block/Adminhtml/View/Log.php | 32 - .../Controller/Adminhtml/Index/Index.php | 37 -- .../Controller/Adminhtml/Index/View.php | 36 -- SyncLog/SyncLog/Cron/DeleteSyncLog.php | 70 -- SyncLog/SyncLog/Model/Config/CronConfig.php | 113 ---- .../SyncLog/Model/ResourceModel/SyncLog.php | 18 - .../ResourceModel/SyncLog/Collection.php | 20 - .../ResourceModel/SyncLog/Grid/Collection.php | 133 ---- SyncLog/SyncLog/Model/Status.php | 51 -- SyncLog/SyncLog/Model/SyncLog.php | 29 - .../Component/Listing/Grid/Column/Action.php | 61 -- SyncLog/SyncLog/composer.json | 25 - SyncLog/SyncLog/etc/acl.xml | 20 - SyncLog/SyncLog/etc/adminhtml/menu.xml | 8 - SyncLog/SyncLog/etc/adminhtml/routes.xml | 8 - SyncLog/SyncLog/etc/adminhtml/system.xml | 55 -- SyncLog/SyncLog/etc/config.xml | 15 - SyncLog/SyncLog/etc/crontab.xml | 8 - SyncLog/SyncLog/etc/db_schema.xml | 20 - SyncLog/SyncLog/etc/di.xml | 18 - SyncLog/SyncLog/etc/module.xml | 4 - SyncLog/SyncLog/registration.php | 9 - .../adminhtml/layout/synclog_index_index.xml | 8 - .../adminhtml/layout/synclog_index_view.xml | 8 - .../view/adminhtml/templates/synclog.phtml | 55 -- .../ui_component/synclog_record_grid_list.xml | 132 ---- composer.json | 2 +- 121 files changed, 79 insertions(+), 7721 deletions(-) delete mode 100644 AbandonedCart/AbandonedCart/Block/System/Config/SyncAbandonedCartData.php delete mode 100644 AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Index.php delete mode 100644 AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/MassSync.php delete mode 100644 AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Sync.php delete mode 100644 AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Syncaccart.php delete mode 100644 AbandonedCart/AbandonedCart/Cron/AbandonedCartSync.php delete mode 100644 AbandonedCart/AbandonedCart/Helper/Data.php delete mode 100644 AbandonedCart/AbandonedCart/Model/AbandonedCartSendData.php delete mode 100644 AbandonedCart/AbandonedCart/Model/Config/CronConfig.php delete mode 100644 AbandonedCart/AbandonedCart/Model/ResourceModel/Quote/Collection.php delete mode 100644 AbandonedCart/AbandonedCart/Plugin/Checkout/Model/GuestPaymentInformationManagementPlugin.php delete mode 100644 AbandonedCart/AbandonedCart/Plugin/Checkout/Model/PaymentInformationManagementPlugin.php delete mode 100644 AbandonedCart/AbandonedCart/Ui/Component/Listing/AbandonedCartDataProvider.php delete mode 100644 AbandonedCart/AbandonedCart/Ui/Component/Listing/Column/AcSyncStatus.php delete mode 100644 AbandonedCart/AbandonedCart/Ui/Component/Listing/Column/Actions.php delete mode 100644 AbandonedCart/AbandonedCart/composer.json delete mode 100644 AbandonedCart/AbandonedCart/etc/acl.xml delete mode 100644 AbandonedCart/AbandonedCart/etc/adminhtml/menu.xml delete mode 100644 AbandonedCart/AbandonedCart/etc/adminhtml/routes.xml delete mode 100644 AbandonedCart/AbandonedCart/etc/adminhtml/system.xml delete mode 100644 AbandonedCart/AbandonedCart/etc/config.xml delete mode 100644 AbandonedCart/AbandonedCart/etc/crontab.xml delete mode 100644 AbandonedCart/AbandonedCart/etc/db_schema.xml delete mode 100644 AbandonedCart/AbandonedCart/etc/di.xml delete mode 100644 AbandonedCart/AbandonedCart/etc/extension_attributes.xml delete mode 100644 AbandonedCart/AbandonedCart/etc/module.xml delete mode 100644 AbandonedCart/AbandonedCart/registration.php delete mode 100644 AbandonedCart/AbandonedCart/view/adminhtml/layout/acecommerce_index_index.xml delete mode 100644 AbandonedCart/AbandonedCart/view/adminhtml/templates/system/config/sync_abandoned_cart_data.phtml delete mode 100644 AbandonedCart/AbandonedCart/view/adminhtml/ui_component/abandoned_cart_listing.xml delete mode 100644 Core/Core/Block/Adminhtml/System/Config/ConnectActiveCampaign.php delete mode 100644 Core/Core/Block/Adminhtml/System/Config/FieldDisable.php delete mode 100644 Core/Core/Controller/Adminhtml/System/Config/Connect.php delete mode 100644 Core/Core/Controller/Adminhtml/System/Config/Disconnect.php delete mode 100644 Core/Core/Helper/Curl.php delete mode 100644 Core/Core/Helper/Data.php delete mode 100644 Core/Core/Logger/Handler.php delete mode 100644 Core/Core/Logger/Logger.php delete mode 100644 Core/Core/composer.json delete mode 100644 Core/Core/etc/acl.xml delete mode 100644 Core/Core/etc/adminhtml/routes.xml delete mode 100644 Core/Core/etc/adminhtml/system.xml delete mode 100644 Core/Core/etc/di.xml delete mode 100644 Core/Core/etc/module.xml delete mode 100644 Core/Core/registration.php delete mode 100644 Core/Core/view/adminhtml/requirejs-config.js delete mode 100644 Core/Core/view/adminhtml/templates/system/config/connection.phtml delete mode 100644 Core/Core/view/adminhtml/web/js/connection.js delete mode 100644 Customer/Customer/Block/Adminhtml/System/Config/CustomerSyncStatus.php delete mode 100644 Customer/Customer/Block/Adminhtml/System/Config/Widget.php delete mode 100644 Customer/Customer/Controller/Adminhtml/Customer/MassSync.php delete mode 100644 Customer/Customer/Cron/CustomerSync.php delete mode 100644 Customer/Customer/Helper/Data.php delete mode 100644 Customer/Customer/Model/Config/CronConfig.php delete mode 100644 Customer/Customer/Model/Customer.php delete mode 100644 Customer/Customer/Observer/CustomerSaveAfter.php delete mode 100644 Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcContactId.php delete mode 100644 Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcCustomerId.php delete mode 100644 Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcSyncStatus.php delete mode 100644 Customer/Customer/Ui/Component/Listing/Column/AcSyncStatus.php delete mode 100644 Customer/Customer/composer.json delete mode 100644 Customer/Customer/etc/adminhtml/routes.xml delete mode 100644 Customer/Customer/etc/adminhtml/system.xml delete mode 100644 Customer/Customer/etc/config.xml delete mode 100644 Customer/Customer/etc/crontab.xml delete mode 100644 Customer/Customer/etc/events.xml delete mode 100644 Customer/Customer/etc/module.xml delete mode 100644 Customer/Customer/registration.php delete mode 100644 Customer/Customer/view/adminhtml/templates/system/config/customer_sync_status.phtml delete mode 100644 Customer/Customer/view/adminhtml/ui_component/customer_listing.xml delete mode 100644 Order/Order/Block/Adminhtml/System/Config/OrderSyncStatus.php delete mode 100644 Order/Order/Block/Adminhtml/System/Config/Widget.php delete mode 100644 Order/Order/Controller/Adminhtml/Order/Masssync.php delete mode 100644 Order/Order/Cron/OrderSyncCron.php delete mode 100644 Order/Order/Helper/Data.php delete mode 100644 Order/Order/Model/Config/CronConfig.php delete mode 100644 Order/Order/Model/OrderData/OrderDataSend.php delete mode 100644 Order/Order/Observer/OrderSync.php delete mode 100644 Order/Order/Ui/Component/Listing/Column/OrderStatus.php delete mode 100644 Order/Order/composer.json delete mode 100644 Order/Order/etc/adminhtml/routes.xml delete mode 100644 Order/Order/etc/adminhtml/system.xml delete mode 100644 Order/Order/etc/config.xml delete mode 100644 Order/Order/etc/crontab.xml delete mode 100644 Order/Order/etc/db_schema.xml delete mode 100644 Order/Order/etc/events.xml delete mode 100644 Order/Order/etc/extension_attributes.xml delete mode 100644 Order/Order/etc/module.xml delete mode 100644 Order/Order/registration.php delete mode 100644 Order/Order/view/adminhtml/templates/system/config/order_sync_status.phtml delete mode 100644 Order/Order/view/adminhtml/ui_component/sales_order_grid.xml delete mode 100755 SyncLog/SyncLog/Block/Adminhtml/View/Log.php delete mode 100755 SyncLog/SyncLog/Controller/Adminhtml/Index/Index.php delete mode 100755 SyncLog/SyncLog/Controller/Adminhtml/Index/View.php delete mode 100644 SyncLog/SyncLog/Cron/DeleteSyncLog.php delete mode 100644 SyncLog/SyncLog/Model/Config/CronConfig.php delete mode 100755 SyncLog/SyncLog/Model/ResourceModel/SyncLog.php delete mode 100755 SyncLog/SyncLog/Model/ResourceModel/SyncLog/Collection.php delete mode 100755 SyncLog/SyncLog/Model/ResourceModel/SyncLog/Grid/Collection.php delete mode 100755 SyncLog/SyncLog/Model/Status.php delete mode 100755 SyncLog/SyncLog/Model/SyncLog.php delete mode 100755 SyncLog/SyncLog/Ui/Component/Listing/Grid/Column/Action.php delete mode 100644 SyncLog/SyncLog/composer.json delete mode 100644 SyncLog/SyncLog/etc/acl.xml delete mode 100755 SyncLog/SyncLog/etc/adminhtml/menu.xml delete mode 100755 SyncLog/SyncLog/etc/adminhtml/routes.xml delete mode 100644 SyncLog/SyncLog/etc/adminhtml/system.xml delete mode 100644 SyncLog/SyncLog/etc/config.xml delete mode 100644 SyncLog/SyncLog/etc/crontab.xml delete mode 100755 SyncLog/SyncLog/etc/db_schema.xml delete mode 100755 SyncLog/SyncLog/etc/di.xml delete mode 100755 SyncLog/SyncLog/etc/module.xml delete mode 100755 SyncLog/SyncLog/registration.php delete mode 100755 SyncLog/SyncLog/view/adminhtml/layout/synclog_index_index.xml delete mode 100755 SyncLog/SyncLog/view/adminhtml/layout/synclog_index_view.xml delete mode 100755 SyncLog/SyncLog/view/adminhtml/templates/synclog.phtml delete mode 100755 SyncLog/SyncLog/view/adminhtml/ui_component/synclog_record_grid_list.xml diff --git a/AbandonedCart/AbandonedCart/Block/System/Config/SyncAbandonedCartData.php b/AbandonedCart/AbandonedCart/Block/System/Config/SyncAbandonedCartData.php deleted file mode 100644 index b19edae..0000000 --- a/AbandonedCart/AbandonedCart/Block/System/Config/SyncAbandonedCartData.php +++ /dev/null @@ -1,187 +0,0 @@ -quoteResourceCollectionFactory = $quoteResourceCollectionFactory; - } - - /** - * Remove scope label - * - * @param AbstractElement $element - * @return string - */ - public function render(AbstractElement $element) - { - $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); - return parent::render($element); - } - - /** - * Return element html - * - * @param AbstractElement $element - * @return string - */ - protected function _getElementHtml(AbstractElement $element) - { - return $this->_toHtml(); - } - - /** - * Return ajax url for field sync button - * - * @return string - */ - public function getAjaxUrl() - { - return $this->getUrl('acecommerce/index/syncaccart'); - } - - /** - * Generate field sync button html - * - * @return string - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function getButtonHtml() - { - $button = $this->getLayout()->createBlock( - Button::class - )->setData([ - 'id' => 'ac_sync_abandoned_cart_button', - 'label' => __('Sync Abandoned Cart Data'), - ]); - - return $button->toHtml(); - } - - /** - * Get abandoned cart collection - * - * @return \Magento\Quote\Model\ResourceModel\Quote\Collection - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function getAbandonedCartCollection() - { - return $this->quoteResourceCollectionFactory->create() - ->addFieldToSelect('*') - ->addFieldToFilter( - 'main_table.is_active', - '1' - ); - } - - /** - * Get sync abandoned cart - * - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function getSyncAbandonedCart() - { - $collection = $this->getAbandonedCartCollection()->addFieldToFilter( - self::AC_SYNC_STATUS, - [ - ['eq' => CronConfig::SYNCED] - ] - ); - - return $collection->getSize(); - } - - /** - * Get total abandoned cart - * - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function getTotalAbandonedCart() - { - $collection = $this->getAbandonedCartCollection()->addFieldToFilter( - self::AC_SYNC_STATUS, - [ - ['eq' => CronConfig::SYNCED], - ['eq' => CronConfig::NOT_SYNCED], - ['eq' => CronConfig::FAIL_SYNCED] - ] - ); - - return $collection->getSize(); - } - - /** - * Get not sync abandoned cart - * - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function getNotSyncAbandonedCart() - { - $collection = $this->getAbandonedCartCollection()->addFieldToFilter( - self::AC_SYNC_STATUS, - [ - ['eq' => CronConfig::NOT_SYNCED] - ] - ); - - return $collection->getSize(); - } - - /** - * Get failed sync - * - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function getFailedSync() - { - $collection = $this->getAbandonedCartCollection()->addFieldToFilter( - self::AC_SYNC_STATUS, - [ - ['eq' => CronConfig::FAIL_SYNCED] - ] - ); - - return $collection->getSize(); - } -} diff --git a/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Index.php b/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Index.php deleted file mode 100644 index 97f3cd2..0000000 --- a/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Index.php +++ /dev/null @@ -1,43 +0,0 @@ -resultPageFactory = $resultPageFactory; - parent::__construct($context); - } - - /** - * Index action - * - * @return \Magento\Framework\Controller\ResultInterface - */ - public function execute() - { - $resultPage = $this->resultPageFactory->create(); - $resultPage->getConfig()->getTitle()->prepend(__("ActiveCampaign Abandoned Carts")); - return $resultPage; - } -} diff --git a/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/MassSync.php b/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/MassSync.php deleted file mode 100644 index 3044f7e..0000000 --- a/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/MassSync.php +++ /dev/null @@ -1,101 +0,0 @@ -filter = $filter; - $this->collectionFactory = $collectionFactory; - $this->abandonedCartSendData = $abandonedCartSendData; - parent::__construct($context); - } - - /** - * Execute action - * - * @return \Magento\Backend\Model\View\Result\Redirect - * @throws \Magento\Framework\Exception\LocalizedException|\Exception - */ - public function execute() - { - $collection = $this->filter->getCollection($this->collectionFactory->create()); - $countSync = 0; - $countFailSync = 0; - $countAlreadySync = 0; - - foreach ($collection as $quote) { - $ac_sync_status = $quote->getData('ac_sync_status'); - if ($ac_sync_status) { - $countAlreadySync++; - } else { - $quoteId = $quote->getEntityId(); - $result = $this->abandonedCartSendData->sendAbandonedCartData($quoteId); - if (array_key_exists('success', $result)) { - $countSync++; - } else if (array_key_exists('error', $result)) { - $countFailSync++; - } - } - } - - if ($countSync || $countFailSync) { - $this->messageManager->addNoticeMessage(__( - 'Orders synced: %1 Orders failed: %2', - $countSync, - $countFailSync - )); - } - if ($countAlreadySync) { - $this->messageManager->addNoticeMessage(__('%1 order(s) had already been synced.', $countAlreadySync)); - } - - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - - return $resultRedirect->setPath('*/*/'); - } -} diff --git a/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Sync.php b/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Sync.php deleted file mode 100644 index dee00d7..0000000 --- a/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Sync.php +++ /dev/null @@ -1,73 +0,0 @@ -quoteModel = $quoteModel; - $this->abandonedCartSendData = $abandonedCartSendData; - parent::__construct($context); - } - - /** - * Sync action - * - * @return void - */ - public function execute() - { - // check if we know what should be synced - $id = $this->getRequest()->getParam('entity_id'); - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultRedirectFactory->create(); - if ($id) { - $title = ""; - try { - // init model and sync - $model = $this->quoteModel; - $model->load($id); - $quoteId[] = $model->getEntityId(); - $result = $this->abandonedCartSendData->sendAbandonedCartData($quoteId); - if(isset($result['error'])){ - $this->messageManager->addErrorMessage($result['error']); - }else{ - $this->messageManager->addSuccessMessage(__('The data has been synced.')); - } - - return $resultRedirect->setPath('*/*/'); - } catch (\Exception $e) { - $this->messageManager->addErrorMessage($e->getMessage()); - return $resultRedirect->setPath('*/*/'); - } - } - $this->messageManager->addErrorMessage(__('We can\'t find a data to sync.')); - return $resultRedirect->setPath('*/*/'); - } -} diff --git a/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Syncaccart.php b/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Syncaccart.php deleted file mode 100644 index 7553b8c..0000000 --- a/AbandonedCart/AbandonedCart/Controller/Adminhtml/Index/Syncaccart.php +++ /dev/null @@ -1,76 +0,0 @@ -resultJsonFactory = $resultJsonFactory; - $this->abandonedCartHelper = $abandonedCartHelper; - $this->abandonedCartSendData = $abandonedCartSendData; - $this->connectActiveCampaign = $connectActiveCampaign; - parent::__construct($context); - } - - /** - * @return Json - */ - public function execute() - { - /** @var Json $result */ - $result = $this->resultJsonFactory->create(); - - if (!$this->abandonedCartHelper->isAbandonedCartSyncingEnabled()) { - $response['error'] = __("Activecampaign status is disabled."); - }elseif (!$this->connectActiveCampaign->isConnected()) { - $response['error'] = __("Activecampaign is disconnected."); - }else{ - $response = $this->abandonedCartSendData->sendAbandonedCartData(); - } - return $result->setData($response); - } -} diff --git a/AbandonedCart/AbandonedCart/Cron/AbandonedCartSync.php b/AbandonedCart/AbandonedCart/Cron/AbandonedCartSync.php deleted file mode 100644 index d40bafa..0000000 --- a/AbandonedCart/AbandonedCart/Cron/AbandonedCartSync.php +++ /dev/null @@ -1,45 +0,0 @@ -abandonedCartHelper = $abandonedCartHelper; - $this->abandonedCartSendData = $abandonedCartSendData; - } - - /** - * @throws NoSuchEntityException - * @throws LocalizedException - */ - public function execute(): void - { - if ($this->abandonedCartHelper->isAbandonedCartSyncingEnabled()) { - $this->abandonedCartSendData->sendAbandonedCartData(); - } - } -} diff --git a/AbandonedCart/AbandonedCart/Helper/Data.php b/AbandonedCart/AbandonedCart/Helper/Data.php deleted file mode 100644 index eec31c7..0000000 --- a/AbandonedCart/AbandonedCart/Helper/Data.php +++ /dev/null @@ -1,52 +0,0 @@ -scopeConfig->isSetFlag( - self::ACTIVE_CAMPAIGN_ABANDONED_CART_SYNC, - ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } - - /** - * @param null $scopeCode - * @return mixed - */ - public function getCronTime($scopeCode = null) - { - return $this->scopeConfig->getValue( - CronConfig::CRON_MODEL_PATH, - ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } - - /** - * @param null $scopeCode - * @return mixed - */ - public function getNumberOfAbandonedCart($scopeCode = null) - { - return $this->scopeConfig->getValue( - self::ABANDONED_CART_NUMBER_OF_ABANDONED_CART, - ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } -} diff --git a/AbandonedCart/AbandonedCart/Model/AbandonedCartSendData.php b/AbandonedCart/AbandonedCart/Model/AbandonedCartSendData.php deleted file mode 100644 index 7133f33..0000000 --- a/AbandonedCart/AbandonedCart/Model/AbandonedCartSendData.php +++ /dev/null @@ -1,604 +0,0 @@ -customerRepository = $customerRepository; - $this->addressRepository = $addressRepository; - $this->customerResourceCollectionFactory = $customerResourceCollectionFactory; - $this->customerFactory = $customerFactory; - $this->customerResource = $customerResource; - $this->eavAttribute = $eavAttribute; - $this->abandonedCartHelper = $abandonedCartHelper; - $this->quoteResourceCollectionFactory = $quoteResourceCollectionFactory; - $this->curl = $curl; - $this->logger = $logger; - $this->cartRepositoryInterface = $cartRepositoryInterface; - $this->coreHelper = $coreHelper; - $this->quoteItemCollectionFactory = $quoteItemCollectionFactory; - $this->_productRepositoryFactory = $productRepositoryFactory; - $this->imageHelperFactory = $imageHelperFactory; - $this->quoteFactory = $quoteFactory; - $this->appEmulation = $appEmulation; - $this->storeManager = $storeManager; - $this->customerModel = $customerModel; - $this->dateTime = $dateTime; - $this->quoteRepository = $quoteRepository; - } - - /** - * @param $quoteId - * @return array - * @throws NoSuchEntityException|LocalizedException - * @throws GuzzleException|GuzzleException - */ - public function sendAbandonedCartData($quoteId = null): array - { - $result = []; - $numberOfAbandonedCart = (int) $this->abandonedCartHelper->getNumberOfAbandonedCart(); - $abandonedCarts = $this->quoteResourceCollectionFactory->create() - ->addFieldToSelect('*') - ->addFieldToFilter('ac_synced_date', [ - ['gt' => new \Zend_Db_Expr('updated_at')], - ['null' => true] - ]) - ->addFieldToFilter( - 'is_active', - '1' - ); - - if ($quoteId) { - $abandonedCarts->addFieldToFilter('entity_id', ['eq' => $quoteId]); - } - $abandonedCarts->setPageSize($numberOfAbandonedCart); - - foreach ($abandonedCarts as $abandonedCart) { - $connectionId = $this->coreHelper->getConnectionId($abandonedCart->getStoreId()); - - $customerId = $abandonedCart->getCustomerId(); - - $quote = $this->quoteRepository->get($abandonedCart->getEntityId()); - - if ($this->isGuest($quote)) { - $customerEmail = $quote->getBillingAddress()->getEmail(); - - if (!$customerEmail) { - $result['error'] = __('Customer Email does not exist.'); - continue; - } - - if (!$this->isGuest($quote)) { - $websiteId = $this->storeManager->getStore($abandonedCart->getStoreId())->getWebsiteId(); - $customerModel = $this->customerModel; - $customerModel->setWebsiteId($websiteId); - $customerModel->loadByEmail($customerEmail); - if ($customerModel->getId()) { - $this->customerId = $customerModel->getId(); - } else { - $this->customerId = $customerEmail; - } - } else { - $this->customerId = $customerEmail; - } - - $this->createEcomCustomer($this->customerId, $quote); - - if (!$this->isGuest($quote)) { - $customerModel = $this->customerFactory->create(); - $this->customerResource->load($customerModel, $this->customerId); - - if ($customerModel->getAcCustomerId()) { - $this->customerId = $customerModel->getAcCustomerId(); - } else { - if ($quote->getAcTempCustomerId()) { - $this->customerId = $quote->getAcTempCustomerId(); - } else { - $AcCustomer = $this->curl->listAllCustomers( - self::GET_METHOD, - self::ECOM_CUSTOMER_ENDPOINT, - $customerEmail - ); - foreach ($AcCustomer['data']['ecomCustomers'] as $Ac) { - if ($Ac['connectionid'] === $connectionId) { - $this->customerId = $Ac['id']; - } - } - } - } - } - - if ($this->isGuest($quote)) { - $this->customerId = $quote->getAcTempCustomerId(); - } - } else { - $this->createEcomCustomer($abandonedCart->getCustomerId(), $quote); - $customerEmail = $abandonedCart->getCustomerEmail(); - $customerModel = $this->customerFactory->create(); - $this->customerResource->load($customerModel, $customerId); - if ($customerModel->getAcCustomerId()) { - $this->customerId = $customerModel->getAcCustomerId(); - } - } - - $quoteItemsData = $this->getQuoteItemsData($abandonedCart->getEntityId(), $abandonedCart->getStoreId()); - - $abandonedCartData = [ - "ecomOrder" => [ - "externalcheckoutid" => $abandonedCart->getEntityId(), - "source" => 1, - "email" => $customerEmail, - "orderProducts" => $quoteItemsData, - "orderDiscounts" => [ - "discountAmount" => $this->coreHelper->priceToCents($abandonedCart->getDiscountAmount()) - ], - "abandonedDate" => $abandonedCart->getCreatedAt(), - "externalCreatedDate" => $abandonedCart->getCreatedAt(), - "externalUpdatedDate" => $abandonedCart->getUpdatedAt(), - "shippingMethod" => $abandonedCart->getShippingMethod(), - "totalPrice" => $this->coreHelper->priceToCents($abandonedCart->getGrandTotal()), - "shippingAmount" => $this->coreHelper->priceToCents($abandonedCart->getShippingAmount()), - "taxAmount" => $this->coreHelper->priceToCents($abandonedCart->getTaxAmount()), - "discountAmount" => $this->coreHelper->priceToCents($abandonedCart->getDiscountAmount()), - "currency" => $abandonedCart->getGlobalCurrencyCode(), - "orderNumber" => $abandonedCart->getEntityId(), - "connectionid" => $connectionId, - "customerid" => $this->customerId, - ] - ]; - - try { - if (is_null($abandonedCart->getAcSyncedDate())) { - $abandonedCartResult = $this->curl->sendRequestAbandonedCart( - self::METHOD, - self::ABANDONED_CART_URL_ENDPOINT, - $abandonedCartData - ); - } else { - $abandonedCartResult = $this->curl->sendRequestAbandonedCart( - self::UPDATE_METHOD, - self::ABANDONED_CART_URL_ENDPOINT . "/" . (int) $abandonedCart->getAcOrderSyncId(), - $abandonedCartData - ); - } - - if ($abandonedCartResult['success']) { - $syncStatus = CronConfig::SYNCED; - } else { - $syncStatus = CronConfig::FAIL_SYNCED; - } - - if (isset($abandonedCartResult['data']['ecomOrder']['id'])) { - $acOrderId = $abandonedCartResult['data']['ecomOrder']['id']; - $this->saveResult($abandonedCart->getEntityId(), $acOrderId, $syncStatus); - } - - if (isset($abandonedCartResult['success']) && $abandonedCartResult['success']) { - $result['success'] = __("Abandoned cart data successfully synced!!"); - } elseif (isset($abandonedCartResult['message'])) { - $result['error'] = $abandonedCartResult['message']; - } - } catch (\Exception $e) { - $result['error'] = __($e->getMessage()); - $this->logger->critical("MODULE AbandonedCart: " . $e->getMessage()); - } catch (GuzzleException $e) { - $this->logger->critical("MODULE AbandonedCart GuzzleException: " . $e->getMessage()); - } - } - return $result; - } - - /** - * @throws NoSuchEntityException - */ - private function getQuoteItemsData($entityId, $storeId): array - { - $quoteItemsData = []; - $quoteItems = $this->getQuoteItems($entityId); - foreach ($quoteItems as $quoteItem) { - $this->appEmulation->startEnvironmentEmulation($storeId, Area::AREA_FRONTEND, true); - - $product = $this->_productRepositoryFactory->create() - ->getById($quoteItem->getProductId()); - - $imageUrl = $this->imageHelperFactory->create() - ->init($product, 'product_thumbnail_image')->getUrl(); - $this->appEmulation->stopEnvironmentEmulation(); - $quoteItemsData[] = [ - "externalid" => $quoteItem->getItemId(), - "name" => $quoteItem->getName(), - "price" => $this->coreHelper->priceToCents($quoteItem->getPrice()), - "quantity" => $quoteItem->getQty(), - "sku" => $quoteItem->getSku(), - "description" => $quoteItem->getDescription(), - "imageUrl" => $imageUrl, - "productUrl" => $product->getProductUrl() - ]; - } - return $quoteItemsData; - } - - /** - * @param $quoteId - * @return Collection - */ - private function getQuoteItems($quoteId): Collection - { - $quoteItemCollection = $this->quoteItemCollectionFactory->create(); - return $quoteItemCollection - ->addFieldToSelect('*') - ->addFieldToFilter('quote_id', [$quoteId]); - } - - /** - * @param $quoteId - * @param $acOrderId - * @param $syncStatus - * @throws AlreadyExistsException|NoSuchEntityException - */ - private function saveResult($quoteId, $acOrderId, $syncStatus): void - { - $quoteModel = $this->cartRepositoryInterface->get($quoteId); - if ($quoteModel->getEntityId()) { - $quoteModel->setAcOrderSyncId($acOrderId); - $quoteModel->setAcSyncStatus($syncStatus); - $quoteModel->setAcSyncedDate($this->dateTime->formatDate(time())); - } - $quoteModel->save(); - } - - /** - * @param null $billingId - * @return string|null - * @throws LocalizedException - */ - private function getTelephone($billingId = null): ?string - { - if ($billingId) { - return $this->addressRepository->getById($billingId)->getTelephone(); - } - return null; - } - - /** - * @param $customerId - * @return array - * @throws LocalizedException - * @throws NoSuchEntityException - */ - private function getFieldValues($customerId): array - { - $fieldValues = []; - $customAttributes = $this->customerRepository->getById($customerId)->getCustomAttributes(); - if (!empty($customAttributes)) { - foreach ($customAttributes as $attribute) { - $attributeId = $this->eavAttribute->getIdByCode(CustomerModel::ENTITY, $attribute->getAttributeCode()); - $attributeValues['field'] = $attributeId; - $attributeValues['value'] = $attribute->getValue(); - $fieldValues[] = $attributeValues; - } - } - return $fieldValues; - } - - public function isGuest($quote): bool{ - return is_null($quote->getCustomerId()); - } - - /** - * @param $customerId - * @return void - */ - private function createEcomCustomer($customerId, $quote): void - { - - try { - $ecomCustomerId = 0; - $contact = []; - - if (!$this->isGuest($quote)) { - $customer = $this->getCustomer($customerId); - $customerId = $customer->getId(); - $contact['email'] = $customer->getEmail(); - $customerEmail = $customer->getEmail(); - $contact['firstName'] = $customer->getFirstname(); - $contact['lastName'] = $customer->getLastname(); - $contact['phone'] = $this->getTelephone($customer->getDefaultBilling()); - $contact['fieldValues'] = $this->getFieldValues($customerId); - } else { - $customerId = $quote->getBillingAddress()->getEmail(); - $contact['email'] = $quote->getBillingAddress()->getEmail(); - $customerEmail = $quote->getBillingAddress()->getEmail(); - $contact['firstName'] = $quote->getBillingAddress()->getFirstname(); - $contact['lastName'] = $quote->getBillingAddress()->getLastname(); - $contact['phone'] = $quote->getBillingAddress()->getTelephone(); - $contact['fieldValues'] = []; - } - - - $contactData['contact'] = $contact; - - $contactResult = $this->curl->createContacts(self::METHOD, self::CONTACT_ENDPOINT, $contactData); - - $contactId = $contactResult['data']['contact']['id'] ?? null; - - $connectionid = $this->coreHelper->getConnectionId($quote->getStoreId()); - - if (!$this->isGuest($quote)) { - if (isset($contactResult['data']['contact']['id'])) { - if (!$customer->getAcCustomerId()) { - $ecomCustomer['connectionid'] = $connectionid; - $ecomCustomer['externalid'] = $customerId; - $ecomCustomer['email'] = $customerEmail; - $ecomCustomerData['ecomCustomer'] = $ecomCustomer; - $AcCustomer = $this->curl->listAllCustomers( - self::GET_METHOD, - self::ECOM_CUSTOMER_ENDPOINT, - $customerEmail - ); - if (isset($AcCustomer['data']['ecomCustomers'][0])) { - foreach ($AcCustomer['data']['ecomCustomers'] as $Ac) { - if ($Ac['connectionid'] === $connectionid) { - $ecomCustomerId = $Ac['id']; - } - } - } - if (!$ecomCustomerId) { - $ecomCustomerResult = $this->curl->createContacts( - self::METHOD, - self::ECOM_CUSTOMER_ENDPOINT, - $ecomCustomerData - ); - $ecomCustomerId = $ecomCustomerResult['data']['ecomCustomer']['id'] ?? null; - } - } else { - $ecomCustomerId = $customer->getAcCustomerId(); - } - } - } - - if ($this->isGuest($quote)) { - $ecomCustomerData = [ - "ecomCustomer" => [ - "connection" => $connectionid, - 'externals' => $quote->getBillingAddress()->getEmail(), - 'email' => $quote->getBillingAddress()->getEmail(), - ] - ]; - $ecomCustomerResult = $this->curl->createContacts( - self::METHOD, - self::ECOM_CUSTOMER_ENDPOINT, - $ecomCustomerData - ); - $ecomCustomerId = $ecomCustomerResult['data']['ecomCustomer']['id'] ?? null; - } - - if ($ecomCustomerId !== 0) { - $syncStatus = CronConfig::SYNCED; - } else { - $syncStatus = CronConfig::FAIL_SYNCED; - } - - if ($this->isGuest($quote)) { - $this->saveCustomerResultQuote($quote, $ecomCustomerId); - } else { - $this->saveCustomerResult($customerId, $syncStatus, $contactId, $ecomCustomerId); - } - } catch (\Exception $e) { - $this->logger->critical("MODULE AbandonedCart: " . $e->getMessage()); - } catch (GuzzleException $e) { - $this->logger->critical("MODULE AbandonedCart: " . $e->getMessage()); - } - } - - /** - * @param $customerId - * @param $syncStatus - * @param $contactId - * @param $ecomCustomerId - * @throws AlreadyExistsException - */ - private function saveCustomerResult($customerId, $syncStatus, $contactId, $ecomCustomerId): void - { - if (is_numeric($customerId)) { - $customerModel = $this->customerFactory->create(); - $this->customerResource->load($customerModel, $customerId); - $customerModel->setAcSyncStatus($syncStatus); - $customerModel->setAcContactId($contactId); - $customerModel->setAcCustomerId($ecomCustomerId); - $this->customerResource->save($customerModel); - } - } - - /** - * @param $quote - * @param $ecomCustomerId - * @throws AlreadyExistsException - */ - private function saveCustomerResultQuote($quote, $ecomCustomerId): void - { - if ($ecomCustomerId) { - $quote->setData("ac_temp_customer_id", $ecomCustomerId); - $quote->save(); - } - } - - /** - * @param $customerId - * @return CustomerModel - */ - private function getCustomer($customerId): CustomerModel - { - $customerModel = $this->customerFactory->create(); - if (is_numeric($customerId)) { - $this->customerResource->load($customerModel, $customerId); - return $customerModel; - } - return $customerModel; - } -} diff --git a/AbandonedCart/AbandonedCart/Model/Config/CronConfig.php b/AbandonedCart/AbandonedCart/Model/Config/CronConfig.php deleted file mode 100644 index d6facc7..0000000 --- a/AbandonedCart/AbandonedCart/Model/Config/CronConfig.php +++ /dev/null @@ -1,111 +0,0 @@ -_runModelPath = $runModelPath; - $this->_configValueFactory = $configValueFactory; - parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); - } - - /** - * @inheritdoc - * - * @return $this - * @throws \Exception - */ - public function afterSave() - { - $cronMinute = $this->getData('groups/abandoned_cart/fields/cron_minute/value'); - $cronHour = $this->getData('groups/abandoned_cart/fields/cron_hour/value'); - $cronDay = $this->getData('groups/abandoned_cart/fields/cron_day/value'); - $cronMonth = $this->getData('groups/abandoned_cart/fields/cron_month/value'); - $cronWeekday = $this->getData('groups/abandoned_cart/fields/cron_weekday/value'); - - $cronMinute = ($cronMinute == null) ? '*' : $cronMinute; - $cronHour = ($cronHour == null) ? '*' : $cronHour; - $cronDay = ($cronDay == null) ? '*' : $cronDay; - $cronMonth = ($cronMonth == null) ? '*' : $cronMonth; - $cronWeekday = ($cronWeekday == null) ? '*' : $cronWeekday; - - $cronExprArray = [ - $cronMinute, //Minute - $cronHour, //Hour - $cronDay, //Day of the Month - $cronMonth, //Month of the Year - $cronWeekday, //Day of the Week - ]; - - $cronExprString = join(' ', $cronExprArray); - - try { - $this->_configValueFactory->create()->load( - self::CRON_STRING_PATH, - 'path' - )->setValue( - $cronExprString - )->setPath( - self::CRON_STRING_PATH - )->save(); - $this->_configValueFactory->create()->load( - self::CRON_MODEL_PATH, - 'path' - )->setValue( - $this->_runModelPath - )->setPath( - self::CRON_MODEL_PATH - )->save(); - } catch (\Exception $e) { - throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t save the cron expression.')); - } - - return parent::afterSave(); - } -} diff --git a/AbandonedCart/AbandonedCart/Model/ResourceModel/Quote/Collection.php b/AbandonedCart/AbandonedCart/Model/ResourceModel/Quote/Collection.php deleted file mode 100644 index 288ca45..0000000 --- a/AbandonedCart/AbandonedCart/Model/ResourceModel/Quote/Collection.php +++ /dev/null @@ -1,19 +0,0 @@ - - */ -class Collection extends \Magento\Quote\Model\ResourceModel\Quote\Collection -{ - /** - * @var string - */ - protected $_idFieldName = 'entity_id'; -} diff --git a/AbandonedCart/AbandonedCart/Plugin/Checkout/Model/GuestPaymentInformationManagementPlugin.php b/AbandonedCart/AbandonedCart/Plugin/Checkout/Model/GuestPaymentInformationManagementPlugin.php deleted file mode 100644 index 502e32e..0000000 --- a/AbandonedCart/AbandonedCart/Plugin/Checkout/Model/GuestPaymentInformationManagementPlugin.php +++ /dev/null @@ -1,61 +0,0 @@ -abandonedCartHelper = $abandonedCartHelper; - $this->abandonedCartSendData = $abandonedCartSendData; - $this->quoteIdMaskFactory = $quoteIdMaskFactory; - } - - /** - * @param \Magento\Checkout\Model\ShippingInformationManagement $subject - * @param $result - * @param $cartId - * @param $email - * @param \Magento\Quote\Api\Data\PaymentInterface $paymentMethod - * @param \Magento\Quote\Api\Data\AddressInterface $billingAddress - */ - public function afterSavePaymentInformation( - \Magento\Checkout\Model\GuestPaymentInformationManagement $subject, - $result, - $cartId, - $email, - \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, - \Magento\Quote\Api\Data\AddressInterface $billingAddress = null - ) { - $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id'); - if ($this->abandonedCartHelper->isAbandonedCartSyncingEnabled()) { - $response = $this->abandonedCartSendData->sendAbandonedCartData($quoteIdMask->getQuoteId()); - } - } -} \ No newline at end of file diff --git a/AbandonedCart/AbandonedCart/Plugin/Checkout/Model/PaymentInformationManagementPlugin.php b/AbandonedCart/AbandonedCart/Plugin/Checkout/Model/PaymentInformationManagementPlugin.php deleted file mode 100644 index 2045590..0000000 --- a/AbandonedCart/AbandonedCart/Plugin/Checkout/Model/PaymentInformationManagementPlugin.php +++ /dev/null @@ -1,70 +0,0 @@ -abandonedCartHelper = $abandonedCartHelper; - $this->abandonedCartSendData = $abandonedCartSendData; - } - - /** - * @inheritdoc - */ - public function afterSavePaymentInformation( - \Magento\Checkout\Model\PaymentInformationManagement $subject, - $result, - $cartId, - \Magento\Quote\Api\Data\PaymentInterface $paymentMethod, - \Magento\Quote\Api\Data\AddressInterface $billingAddress = null - ) { - $quoteRepository = $this->getCartRepository(); - /** @var \Magento\Quote\Model\Quote $quote */ - $quote = $quoteRepository->getActive($cartId); - - if ($this->abandonedCartHelper->isAbandonedCartSyncingEnabled()) { - $response = $this->abandonedCartSendData->sendAbandonedCartData($quote->getId()); - } - } - - /** - * Get Cart repository - * - * @return \Magento\Quote\Api\CartRepositoryInterface - * @deprecated 100.2.0 - */ - private function getCartRepository() - { - if (!$this->cartRepository) { - $this->cartRepository = \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Quote\Api\CartRepositoryInterface::class); - } - return $this->cartRepository; - } -} diff --git a/AbandonedCart/AbandonedCart/Ui/Component/Listing/AbandonedCartDataProvider.php b/AbandonedCart/AbandonedCart/Ui/Component/Listing/AbandonedCartDataProvider.php deleted file mode 100644 index ef28021..0000000 --- a/AbandonedCart/AbandonedCart/Ui/Component/Listing/AbandonedCartDataProvider.php +++ /dev/null @@ -1,25 +0,0 @@ -getSelect() - ->join( - ['quote_address'], - 'main_table.entity_id = quote_address.quote_id', - ['quote_address.quote_id','quote_address.email'], - ) - ->where("main_table.is_active = 1 AND quote_address.address_type = 'billing'"); - return $this; - } -} diff --git a/AbandonedCart/AbandonedCart/Ui/Component/Listing/Column/AcSyncStatus.php b/AbandonedCart/AbandonedCart/Ui/Component/Listing/Column/AcSyncStatus.php deleted file mode 100644 index c47ed12..0000000 --- a/AbandonedCart/AbandonedCart/Ui/Component/Listing/Column/AcSyncStatus.php +++ /dev/null @@ -1,42 +0,0 @@ -getData('name')] = $this->getFieldLabel($item); - } - } - return $dataSource; - } - - /** - * Retrieve field label - * - * @param array $item - * @return string - */ - private function getFieldLabel(array $item) - { - $acSyncStatus = (int)$item['ac_sync_status']; - if ($acSyncStatus === CronConfig::SYNCED) { - return __('Synced'); - } elseif ($acSyncStatus === CronConfig::NOT_SYNCED) { - return __('Not Synced'); - } elseif ($acSyncStatus === CronConfig::FAIL_SYNCED) { - return __('Not Synced'); - } - return __('Something Wrong'); - } -} diff --git a/AbandonedCart/AbandonedCart/Ui/Component/Listing/Column/Actions.php b/AbandonedCart/AbandonedCart/Ui/Component/Listing/Column/Actions.php deleted file mode 100644 index e7c763a..0000000 --- a/AbandonedCart/AbandonedCart/Ui/Component/Listing/Column/Actions.php +++ /dev/null @@ -1,62 +0,0 @@ -urlBuilder = $urlBuilder; - parent::__construct($context, $uiComponentFactory, $components, $data); - } - - public function prepareDataSource(array $dataSource) - { - if (isset($dataSource['data']['items'])) { - foreach ($dataSource['data']['items'] as & $item) { - if (isset($item['entity_id'])) { - $item[$this->getData('name')] = [ - 'sync' => [ - 'href' => $this->urlBuilder->getUrl( - static::URL_PATH_SYNC, - [ - 'entity_id' => $item['entity_id'] - ] - ), - 'label' => __('Sync') - ] - ]; - } - } - } - - return $dataSource; - } -} diff --git a/AbandonedCart/AbandonedCart/composer.json b/AbandonedCart/AbandonedCart/composer.json deleted file mode 100644 index e851697..0000000 --- a/AbandonedCart/AbandonedCart/composer.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "name": "activecampaign/abandonedcart", - "description": "ActiveCampaign Abandoned Cart", - "type": "magento2-module", - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "config": { - "sort-packages": true - }, - "version": "2.1.0", - "require": { - "php": "~7.3.0||~7.4.0||~8.0||~8.1", - "activecampaign/core": "2.1.*" - }, - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "ActiveCampaign\\AbandonedCart\\": "" - } - } -} - diff --git a/AbandonedCart/AbandonedCart/etc/acl.xml b/AbandonedCart/AbandonedCart/etc/acl.xml deleted file mode 100644 index 437fa92..0000000 --- a/AbandonedCart/AbandonedCart/etc/acl.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - diff --git a/AbandonedCart/AbandonedCart/etc/adminhtml/menu.xml b/AbandonedCart/AbandonedCart/etc/adminhtml/menu.xml deleted file mode 100644 index 633a7bd..0000000 --- a/AbandonedCart/AbandonedCart/etc/adminhtml/menu.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - diff --git a/AbandonedCart/AbandonedCart/etc/adminhtml/routes.xml b/AbandonedCart/AbandonedCart/etc/adminhtml/routes.xml deleted file mode 100644 index f34f58c..0000000 --- a/AbandonedCart/AbandonedCart/etc/adminhtml/routes.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - diff --git a/AbandonedCart/AbandonedCart/etc/adminhtml/system.xml b/AbandonedCart/AbandonedCart/etc/adminhtml/system.xml deleted file mode 100644 index 82a2b9b..0000000 --- a/AbandonedCart/AbandonedCart/etc/adminhtml/system.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - -
- - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - 1 - - ActiveCampaign\AbandonedCart\Model\Config\CronConfig - - - - - - 1 - - - - - - - 1 - - - - - - - 1 - - - - - - - 1 - - - - - required-entry validate-number validate-greater-than-zero validate-integer - - - 1 - - - - ActiveCampaign\AbandonedCart\Block\System\Config\SyncAbandonedCartData - - - 1 - - - -
-
-
diff --git a/AbandonedCart/AbandonedCart/etc/config.xml b/AbandonedCart/AbandonedCart/etc/config.xml deleted file mode 100644 index 0e5d833..0000000 --- a/AbandonedCart/AbandonedCart/etc/config.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - 0 - 100 - 0 - * - * - * - * - - - - diff --git a/AbandonedCart/AbandonedCart/etc/crontab.xml b/AbandonedCart/AbandonedCart/etc/crontab.xml deleted file mode 100644 index f03f481..0000000 --- a/AbandonedCart/AbandonedCart/etc/crontab.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - crontab/default/jobs/ac_abandoned_cart_sync_cron_job/schedule/cron_expr - - - diff --git a/AbandonedCart/AbandonedCart/etc/db_schema.xml b/AbandonedCart/AbandonedCart/etc/db_schema.xml deleted file mode 100644 index b0b668c..0000000 --- a/AbandonedCart/AbandonedCart/etc/db_schema.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - -
-
diff --git a/AbandonedCart/AbandonedCart/etc/di.xml b/AbandonedCart/AbandonedCart/etc/di.xml deleted file mode 100644 index 14fdd4f..0000000 --- a/AbandonedCart/AbandonedCart/etc/di.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - Magento\Quote\Model\ResourceModel\Quote\Grid\Collection - - - - - - quote - Magento\Quote\Model\ResourceModel\Quote - - - \ No newline at end of file diff --git a/AbandonedCart/AbandonedCart/etc/extension_attributes.xml b/AbandonedCart/AbandonedCart/etc/extension_attributes.xml deleted file mode 100644 index cbda673..0000000 --- a/AbandonedCart/AbandonedCart/etc/extension_attributes.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - diff --git a/AbandonedCart/AbandonedCart/etc/module.xml b/AbandonedCart/AbandonedCart/etc/module.xml deleted file mode 100644 index 2359d77..0000000 --- a/AbandonedCart/AbandonedCart/etc/module.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - - - - - - diff --git a/AbandonedCart/AbandonedCart/registration.php b/AbandonedCart/AbandonedCart/registration.php deleted file mode 100644 index 6caa52d..0000000 --- a/AbandonedCart/AbandonedCart/registration.php +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - diff --git a/AbandonedCart/AbandonedCart/view/adminhtml/templates/system/config/sync_abandoned_cart_data.phtml b/AbandonedCart/AbandonedCart/view/adminhtml/templates/system/config/sync_abandoned_cart_data.phtml deleted file mode 100644 index 015baa8..0000000 --- a/AbandonedCart/AbandonedCart/view/adminhtml/templates/system/config/sync_abandoned_cart_data.phtml +++ /dev/null @@ -1,95 +0,0 @@ - - -getButtonHtml() ?> -

- - - - - - - -

 

- -
-
-
- escapeHtml(__("Total Abandoned Cart :")) ?> - escapeHtml(__($block->getTotalAbandonedCart())) ?> -
-
-
-
-
-
- escapeHtml(__("Synced Abandoned Cart :")) ?> - escapeHtml(__($block->getSyncAbandonedCart())) ?> -
-
-
-
-
-
- escapeHtml(__("Not Synced Abandoned Cart :")) ?> - escapeHtml(__($block->getNotSyncAbandonedCart())) ?> -
-
-
-
-
-
- escapeHtml(__("Fail Synced Abandoned Cart :")) ?> - escapeHtml(__($block->getFailedSync())) ?> -
-
-
diff --git a/AbandonedCart/AbandonedCart/view/adminhtml/ui_component/abandoned_cart_listing.xml b/AbandonedCart/AbandonedCart/view/adminhtml/ui_component/abandoned_cart_listing.xml deleted file mode 100644 index 4f1e3ac..0000000 --- a/AbandonedCart/AbandonedCart/view/adminhtml/ui_component/abandoned_cart_listing.xml +++ /dev/null @@ -1,182 +0,0 @@ - - -- - - abandoned_cart_listing.abandoned_cart_listing_data_source - - - - spinner_columns - - abandoned_cart_listing.abandoned_cart_listing_data_source - - - - - - entity_id - - - - ActiveCampaign_AbandonedCart::abandonedcart_operation - - - entity_id - entity_id - - - - - - true - - - - - - - - column - - - - - - - - - - - - - - - massSync - - - - - - - - - - entity_id - false - 55 - - - - - textRange - - asc - - - - - text - - text - - - - - - - text - - text - - - - - - - text - - text - - - - - - - text - - text - - - true - - - - - text - - text - - - true - - - - - text - - text - - - true - - - - - - text - - - true - - - - - text - - text - - - true - - - - - dateRange - date - - - - - - dateRange - date - - - - - - entity_id - false - - - - diff --git a/Core/Core/Block/Adminhtml/System/Config/ConnectActiveCampaign.php b/Core/Core/Block/Adminhtml/System/Config/ConnectActiveCampaign.php deleted file mode 100644 index 1cad16f..0000000 --- a/Core/Core/Block/Adminhtml/System/Config/ConnectActiveCampaign.php +++ /dev/null @@ -1,162 +0,0 @@ -setTemplate('ActiveCampaign_Core::system/config/connection.phtml'); - return $this; - } - - /** - * Unset some non-related element parameters - * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element - * - * @return string - */ - public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) - { - $element = clone $element; - $element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue(); - - return parent::render($element); - } - - /** - * Get the button and scripts contents - * - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element - * - * @return string - */ - protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element) - { - $currentButton = $this->escapeHtmlAttr(__('Connect')); - $successButton = $this->escapeHtmlAttr(__('Disconnect')); - $ajaxUrl = $this->_urlBuilder->getUrl('activecampaign/system_config/connect'); - $connection = true; - $isConnected = $this->isConnected(); - - if ($isConnected) { - $currentButton = $this->escapeHtmlAttr(__('Disconnect')); - $successButton = $this->escapeHtmlAttr(__('Connect')); - $ajaxUrl = $this->_urlBuilder->getUrl('activecampaign/system_config/disconnect'); - $connection = false; - } - - $this->addData( - [ - 'button_label' => __($currentButton), - 'html_id' => $element->getHtmlId(), - 'ajax_url' => $ajaxUrl, - 'connection' => $connection, - 'success_text' => $successButton, - 'field_mapping' => str_replace('"', '\\"', json_encode($this->_getFieldMapping())) - ] - ); - - return $this->_toHtml(); - } - - /** - * Returns configuration fields required to perform the ping request - * - * @return array - */ - protected function _getFieldMapping() - { - return [ - 'status' => 'active_campaign_general_status', - 'api_url' => 'active_campaign_general_api_url', - 'api_key' => 'active_campaign_general_api_key', - 'store' => 'store_switcher' - ]; - } - - /** - * Get connected stores - * - * @return array - */ - public function getConnectedStores(): array - { - $result = []; - - foreach ($this->_storeManager->getStores() as $store) { - $connectionId = $this->_scopeConfig->getValue( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $store->getId() - ); - - $result[$store->getId()]['name'] = $store->getName(); - $result[$store->getId()]['status'] = $connectionId; - } - - return $result; - } - - /** - * Is default config - * - * @return bool - */ - public function isDefaultConfig(): bool - { - return !$this->getRequest()->getParam('store'); - } - - /** - * Is connected - * - * @return bool - */ - public function isConnected(): bool - { - if ($store = $this->getRequest()->getParam('store')) { - $connectionId = $this->_scopeConfig->getValue( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $store - ); - - return (bool)$connectionId; - } - - $stores = $this->_storeManager->getStores(); - - foreach ($stores as $store) { - $connectionId = $this->_scopeConfig->getValue( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $store->getId() - ); - - if (!$connectionId) { - return false; - } - } - - return true; - } - - /** - * Get cache URL - * - * @return string - */ - public function getCacheUrl(): string - { - return $this->_urlBuilder->getUrl('adminhtml/cache'); - } -} diff --git a/Core/Core/Block/Adminhtml/System/Config/FieldDisable.php b/Core/Core/Block/Adminhtml/System/Config/FieldDisable.php deleted file mode 100644 index f232ce3..0000000 --- a/Core/Core/Block/Adminhtml/System/Config/FieldDisable.php +++ /dev/null @@ -1,53 +0,0 @@ -isConnected()) { - $element->setDisabled('disabled'); - } - - return $element->getElementHtml(); - } - - /** - * Is connected - * - * @return bool - */ - public function isConnected(): bool - { - if ($store = $this->getRequest()->getParam('store')) { - $connectionId = $this->_scopeConfig->getValue( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $store - ); - - return (bool)$connectionId; - } - - $stores = $this->_storeManager->getStores(); - - foreach ($stores as $store) { - $connectionId = $this->_scopeConfig->getValue( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $store->getId() - ); - - if (!$connectionId) { - return false; - } - } - - return true; - } -} diff --git a/Core/Core/Controller/Adminhtml/System/Config/Connect.php b/Core/Core/Controller/Adminhtml/System/Config/Connect.php deleted file mode 100644 index 1dfbafa..0000000 --- a/Core/Core/Controller/Adminhtml/System/Config/Connect.php +++ /dev/null @@ -1,233 +0,0 @@ -resultJsonFactory = $resultJsonFactory; - $this->configInterface = $configInterface; - $this->storeRepository = $storeRepository; - $this->storeManager = $storeManager; - $this->activeCampaignHelper = $activeCampaignHelper; - $this->curl = $curl; - } - - /** - * Check for connection to server - * - * @return \Magento\Framework\Controller\Result\Json - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function execute() - { - $request = $this->getRequest()->getParams(); - - // Set store to default if Single store mode - $request['store'] = $request['store'] ?? $this->storeManager->getDefaultStoreView()->getId(); - - $return = []; - - if ($request['status'] - && !empty($request['api_url']) - && !empty($request['api_key']) - ) { - $isEnabled = $this->activeCampaignHelper->isEnabled($request['status']); - if (!$isEnabled) { - $this->saveConfig( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_STATUS, - $request['status'], - $request['store'] - ); - } - - $apiUrl = $this->activeCampaignHelper->getApiUrl($request['store']); - if (empty($apiUrl)) { - $this->saveConfig( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_API_URL, - $request['api_url'], - $request['store'] - ); - } - - $apiKey = $this->activeCampaignHelper->getApiKey($request['store']); - if (empty($apiKey)) { - $this->saveConfig( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_API_KEY, - $request['api_key'], - $request['store'] - ); - } - - try { - if ((int)$request['store']) { - $data = $this->curlRequestData((int)$request['store']); - $result = $this->curl->createConnection( - self::METHOD, - self::URL_ENDPOINT, - $request, - $data - ); - - if ($result['success']) { - $connectionId = $result['data']['connection']['id']; - $this->saveConfig( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - $connectionId, - $request['store'] - ); - } else { - $return['success'] = false; - $return['errorMessage'] = $result['message']; - } - } elseif ($request['store'] == '0') { - $stores = $this->storeRepository->getList(); - - foreach ($stores as $store) { - if ($store->getId()) { - $data = $this->curlRequestData((int)$store->getId()); - $result = $this->curl->createConnection( - self::METHOD, - self::URL_ENDPOINT, - $request, - $data - ); - - if ($result['success']) { - $return['success'] = true; - $connectionId = $result['data']['connection']['id']; - $this->saveConfig( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - $connectionId, - $store->getId() - ); - } else { - $return['errorMessage'] = $result['message']; - } - } - } - } - - $allConnections = $this->curl->getAllConnections( - self::GET_METHOD, - self::URL_ENDPOINT - ); - - $checkConnections = $this->activeCampaignHelper->checkConnections($allConnections); - $return['success'] = $checkConnections; - } catch (\Exception $e) { - $return['success'] = false; - $return['errorMessage'] = __($e->getMessage()); - } - } - - $resultJson = $this->resultJsonFactory->create(); - - return $resultJson->setData($return); - } - - /** - * Save config - * - * @param string $path - * @param string $value - * @param int $scopeId - * - * @return void - */ - protected function saveConfig( - string $path, - string $value, - int $scopeId - ) { - $scope = ($scopeId) - ? \Magento\Store\Model\ScopeInterface::SCOPE_STORES - : \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT; - $this->configInterface->saveConfig($path, $value, $scope, $scopeId); - } - - /** - * CURL request data - * - * @param int|null $storeId - * - * @return array - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - protected function curlRequestData(?int $storeId): array - { - $store = $this->storeManager->getStore($storeId); - - return [ - 'connection' => [ - 'service' => 'magento2-' . $store->getName(), - 'externalid' => $store->getCode(), - 'name' => $store->getName(), - 'logoUrl' => $this->activeCampaignHelper->getStoreLogo($storeId), - 'linkUrl' => $store->getBaseUrl() - ] - ]; - } -} diff --git a/Core/Core/Controller/Adminhtml/System/Config/Disconnect.php b/Core/Core/Controller/Adminhtml/System/Config/Disconnect.php deleted file mode 100644 index f6e0e42..0000000 --- a/Core/Core/Controller/Adminhtml/System/Config/Disconnect.php +++ /dev/null @@ -1,168 +0,0 @@ -resultJsonFactory = $resultJsonFactory; - $this->cacheTypeList = $cacheTypeList; - $this->configInterface = $configInterface; - $this->storeRepository = $storeRepository; - $this->storeManager = $storeManager; - $this->activeCampaignHelper = $activeCampaignHelper; - $this->curl = $curl; - } - - /** - * Check for connection to server - * - * @return \Magento\Framework\Controller\Result\Json - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function execute() - { - $request = $this->getRequest()->getParams(); - - // Set store to default if Single store mode - $request['store'] = $request['store'] ?? $this->storeManager->getDefaultStoreView()->getId(); - - $return = []; - $return['success'] = false; - - if ($request['status'] - && !empty($request['api_url']) - && !empty($request['api_key']) - ) { - try { - if ((int)$request['store']) { - $connectionId = $this->activeCampaignHelper->getConnectionId($request['store']); - $urlEndpoint = self::URL_ENDPOINT . '/' . $connectionId; - $result = $this->curl->deleteConnection(self::METHOD, $urlEndpoint); - - if ($result['success']) { - $this->configInterface->deleteConfig( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $request['store'] - ); - } else { - $return['success'] = false; - $return['errorMessage'] = $result['message']; - } - } elseif ($request['store'] == '0') { - $stores = $this->storeRepository->getList(); - - foreach ($stores as $store) { - if ($store->getId()) { - $connectionId = $this->activeCampaignHelper->getConnectionId((int)$store->getId()); - $urlEndpoint = self::URL_ENDPOINT . '/' . $connectionId; - $result = $this->curl->deleteConnection(self::METHOD, $urlEndpoint); - - if ($result['success']) { - $this->configInterface->deleteConfig( - \ActiveCampaign\Core\Helper\Data::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $store->getId() - ); - } else { - $return['success'] = false; - $return['errorMessage'] = $result['message']; - } - } - } - } - - $allConnections = $this->curl->getAllConnections( - self::GET_METHOD, - self::URL_ENDPOINT - ); - $checkConnections = $this->activeCampaignHelper->checkConnections($allConnections); - $return['success'] = $checkConnections; - } catch (\Exception $e) { - $return['success'] = false; - $return['errorMessage'] = __($e->getMessage()); - } - } - - if ($return['success'] === true) { - $this->cacheTypeList->invalidate([ - \Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER, - \Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER - ]); - } - - $resultJson = $this->resultJsonFactory->create(); - - return $resultJson->setData($return); - } -} diff --git a/Core/Core/Helper/Curl.php b/Core/Core/Helper/Curl.php deleted file mode 100644 index c394d97..0000000 --- a/Core/Core/Helper/Curl.php +++ /dev/null @@ -1,453 +0,0 @@ -client = $client ?: new Client(); - $this->jsonHelper = $jsonHelper; - $this->logger = $logger; - $this->activeCampaignHelper = $activeCampaignHelper; - $this->syncLog = $syncLog; - - parent::__construct($context); - } - - /** - * Create connection - * - * @param string $method - * @param string $urlEndpoint - * @param array $request - * @param array $data - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function createConnection( - string $method, - string $urlEndpoint, - array $request, - array $data = [] - ): array { - $apiUrl = $this->activeCampaignHelper->getApiUrl(); - $apiUrl = empty($apiUrl) ? $request['api_url'] : $apiUrl; - - $apiKey = $this->activeCampaignHelper->getApiKey(); - $apiKey = empty($apiKey) ? $request['api_key'] : $apiKey; - - $url = $apiUrl . self::API_VERSION . $urlEndpoint; - $bodyData = (!empty($data)) ? $this->jsonHelper->serialize($data) : ''; - $headers = $this->getHeaders($apiKey); - - return $this->sendRequest($urlEndpoint, $method, $url, $headers, $bodyData); - } - - /** - * Send order data - * - * @param string $method - * @param string $urlEndpoint - * @param array $data - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function orderDataSend( - string $method, - string $urlEndpoint, - array $data = [] - ): array { - $apiUrl = $this->activeCampaignHelper->getApiUrl(); - $apiKey = $this->activeCampaignHelper->getApiKey(); - - $url = $apiUrl . self::API_VERSION . $urlEndpoint; - $bodyData = (!empty($data)) ? $this->jsonHelper->serialize($data) : ''; - $headers = $this->getHeaders($apiKey); - - return $this->sendRequest($urlEndpoint, $method, $url, $headers, $bodyData); - } - - /** - * Update order data - * - * @param string $method - * @param string $urlEndpoint - * @param array $data - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function orderDataUpdate( - string $method, - string $urlEndpoint, - array $data = [] - ): array { - $apiUrl = $this->activeCampaignHelper->getApiUrl(); - $apiKey = $this->activeCampaignHelper->getApiKey(); - - $url = $apiUrl . self::API_VERSION . $urlEndpoint; - $bodyData = (!empty($data)) ? $this->jsonHelper->serialize($data) : ''; - $headers = $this->getHeaders($apiKey); - - return $this->sendRequest($urlEndpoint, $method, $url, $headers, $bodyData); - } - - /** - * Delete order data - * - * @param string $method - * @param string $urlEndpoint - * @param int|string $orderId - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function orderDataDelete( - string $method, - string $urlEndpoint, - int|string $orderId - ): array { - $apiUrl = $this->activeCampaignHelper->getApiUrl(); - $apiKey = $this->activeCampaignHelper->getApiKey(); - - $url = $apiUrl . self::API_VERSION . $urlEndpoint . $orderId; - $headers = $this->getHeaders($apiKey); - - return $this->sendRequest($urlEndpoint, $method, $url, $headers); - } - - /** - * Delete connection - * - * @param string $method - * @param string $urlEndpoint - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function deleteConnection( - string $method, - string $urlEndpoint - ): array { - $apiUrl = $this->activeCampaignHelper->getApiUrl(); - $apiKey = $this->activeCampaignHelper->getApiKey(); - - $url = $apiUrl . self::API_VERSION . $urlEndpoint; - $headers = $this->getHeaders($apiKey); - - return $this->sendRequest($urlEndpoint, $method, $url, $headers); - } - - /** - * Create contacts - * - * @param string $method - * @param string $urlEndpoint - * @param array $data - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function createContacts( - string $method, - string $urlEndpoint, - array $data = [] - ): array { - $apiUrl = $this->activeCampaignHelper->getApiUrl(); - $apiKey = $this->activeCampaignHelper->getApiKey(); - - $url = $apiUrl . self::API_VERSION . $urlEndpoint; - $bodyData = (!empty($data)) ? $this->jsonHelper->serialize($data) : ''; - $headers = $this->getHeaders($apiKey); - - return $this->sendRequest($urlEndpoint, $method, $url, $headers, $bodyData); - } - - /** - * Get all connections - * - * @param string $method - * @param string $urlEndpoint - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function getAllConnections( - string $method, - string $urlEndpoint - ): array { - $apiUrl = $this->activeCampaignHelper->getApiUrl(); - $apiKey = $this->activeCampaignHelper->getApiKey(); - - $url = $apiUrl . self::API_VERSION . $urlEndpoint; - $headers = $this->getHeaders($apiKey); - - return $this->sendRequest($urlEndpoint, $method, $url, $headers); - } - - /** - * Send request for abandoned cart - * - * @param string $method - * @param string $urlEndpoint - * @param array $data - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function sendRequestAbandonedCart( - string $method, - string $urlEndpoint, - array $data = [] - ): array { - $apiUrl = $this->activeCampaignHelper->getApiUrl(); - $apiKey = $this->activeCampaignHelper->getApiKey(); - - $url = $apiUrl . self::API_VERSION . $urlEndpoint; - $bodyData = (!empty($data)) ? $this->jsonHelper->serialize($data) : ''; - $headers = $this->getHeaders($apiKey); - - return $this->sendRequest('ecomAbandonedCarts', $method, $url, $headers, $bodyData); - } - - /** - * List all customers - * - * @param string $method - * @param string $urlEndpoint - * @param string $customerEmail - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - public function listAllCustomers( - string $method, - string $urlEndpoint, - string $customerEmail - ): array { - $apiUrl = $this->activeCampaignHelper->getApiUrl(); - $apiKey = $this->activeCampaignHelper->getApiKey(); - - $url = $apiUrl . self::API_VERSION . $urlEndpoint . '?filters[email]=' . urlencode($customerEmail); - $headers = $this->getHeaders($apiKey); - - return $this->sendRequest('ecomCustomers', $method, $url, $headers); - } - - /** - * Get headers - * - * @param string|null $apiKey - * - * @return array - */ - private function getHeaders(?string $apiKey): array - { - return [ - 'Content-Type' => self::CONTENT_TYPE, - 'Api-Token' => $apiKey - ]; - } - - /** - * Send request - * - * @param string $urlEndpoint - * @param string $method - * @param string $url - * @param array $headers - * @param string $bodyData - * - * @return array - * @throws \GuzzleHttp\Exception\GuzzleException - */ - private function sendRequest( - string $urlEndpoint, - string $method, - string $url, - array $headers, - string $bodyData = '' - ): array { - $result = []; - $synclog = $this->syncLog; - - try { - $request = [ - 'METHOD' => $method, - 'URL' => $url, - 'HTTP VERSION' => self::HTTP_VERSION, - 'HEADERS' => $headers, - 'BODY DATA' => $bodyData - ]; - - /** - * @todo Create data interfaces to maintain integrity of data - */ - $synclog->setType($urlEndpoint); - $synclog->setEndpoint($urlEndpoint); - $synclog->setMethod($method); - $synclog->setRequest($this->jsonHelper->serialize($request)); - - $this->logger->info('REQUEST', $request); - - $options = []; - $options[\GuzzleHttp\RequestOptions::HEADERS] = $headers; - - if ($bodyData !== null) { - $options[\GuzzleHttp\RequestOptions::BODY] = $bodyData; - } - - $resultCurl = $this->client->request($method, $url, $options); - - $body = $resultCurl->getBody()->getContents(); - $response = $this->jsonHelper->unserialize($body); - - $this->logger->info('RESPONSE', $response); - - $synclog->setResponse($body); - $synclog->setStatus(1); - - if (!empty($resultCurl)) { - $result['status'] = $resultCurl->getStatusCode(); - if (isset($result['status']) && array_key_exists($result['status'], $this->successCodes())) { - $result['success'] = true; - $result['data'] = $response; - } elseif (isset($result['status']) && array_key_exists($result['status'], $this->failureCodes())) { - $result['success'] = false; - $result['message'] = $this->getMessage($response); - $result['data'] = $response; - } else { - $result['success'] = false; - $result['message'] = $this->getMessage($response); - } - } else { - $result['success'] = false; - $result['message'] = __('Cannot connect to active campaign server. Please try again later.'); - } - } catch (\Exception $e) { - $synclog->setStatus(0); - $synclog->setErrors($e->getMessage()); - - $this->logger->critical('MODULE Core: ' . $e->getMessage()); - - $result['success'] = false; - $result['message'] = $e->getMessage(); - } - - /** - * @todo Replace with repository service contract - */ - $synclog->save(); - $synclog->unsetData(); - - return $result; - } - - /** - * Success codes - * - * @return array - */ - private function successCodes(): array - { - return [ - 200 => 'OK', - 201 => 'Created' - ]; - } - - /** - * Failure codes - * - * @return array - */ - private function failureCodes(): array - { - return [ - 400 => 'Bad Request', - 404 => 'Not Found', - 422 => 'Unprocessable Entity' - ]; - } - - /** - * Get message - * - * @param mixed $response - * - * @return \Magento\Framework\Phrase|string - */ - private function getMessage(mixed $response): \Magento\Framework\Phrase|string - { - if (is_array($response)) { - if (isset($response['message'])) { - return $response['message']; - } elseif (isset($response['error']['title'])) { - return $response['error']['title']; - } elseif (isset($response['errors']['0']['title'])) { - return $response['errors']['0']['title']; - } - } - - return __('An unknown error occurred. Please try again later'); - } -} diff --git a/Core/Core/Helper/Data.php b/Core/Core/Helper/Data.php deleted file mode 100644 index 2a499a8..0000000 --- a/Core/Core/Helper/Data.php +++ /dev/null @@ -1,219 +0,0 @@ -storeRepository = $storeRepository; - $this->configInterface = $configInterface; - $this->logo = $logo; - } - - /** - * Is enabled - * - * @param int|string|null $scopeCode - * - * @return bool - */ - public function isEnabled(int|string $scopeCode = null): bool - { - return $this->scopeConfig->isSetFlag( - self::ACTIVE_CAMPAIGN_GENERAL_STATUS, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } - - /** - * Get API URL - * - * @param int|string|null $scopeCode - * - * @return string|null - */ - public function getApiUrl(int|string $scopeCode = null): ?string - { - return $this->scopeConfig->getValue( - self::ACTIVE_CAMPAIGN_GENERAL_API_URL, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } - - /** - * Get API key - * - * @param int|string|null $scopeCode - * - * @return string|null - */ - public function getApiKey(int|string $scopeCode = null): ?string - { - return $this->scopeConfig->getValue( - self::ACTIVE_CAMPAIGN_GENERAL_API_KEY, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } - - /** - * Get connection ID - * - * @param int|string|null $scopeCode - * - * @return string|null - */ - public function getConnectionId(int|string $scopeCode = null): ?string - { - return $this->scopeConfig->getValue( - self::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } - - /** - * Get store logo - * - * @param int|string|null $scopeCode - * - * @return string - */ - public function getStoreLogo(int|string $scopeCode = null): string - { - $folderName = \Magento\Config\Model\Config\Backend\Image\Logo::UPLOAD_DIR; - $storeLogoPath = $this->scopeConfig->getValue( - 'design/header/logo_src', - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $scopeCode - ); - $path = $folderName . '/' . $storeLogoPath; - $logoUrl = $this->_urlBuilder->getBaseUrl(['_type' => \Magento\Framework\UrlInterface::URL_TYPE_MEDIA]) . $path; - - if ($storeLogoPath !== null) { - $url = $logoUrl; - } else { - $url = $this->logo->getLogoSrc(); - } - - return $url; - } - - /** - * Converts to cents the price amount - * - * @param float|null $price - * - * @return int - */ - public function priceToCents(?float $price = 0.0): int - { - $price = (is_null($price)) ? $price = 0.0 : $price; - return (int) (round($price, 2) * 100); - } - - /** - * Check connections - * - * @param array $allConnections - * - * @return bool - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - public function checkConnections(array $allConnections): bool - { - if ($allConnections['success']) { - $activeConnectionIds = []; - - foreach ($allConnections['data']['connections'] as $connection) { - $store = $this->storeRepository->get($connection['externalid']); - $connectionId = $this->getConnectionId($store->getId()); - $activeConnectionIds[] = $connection['id']; - - if ($connectionId != $connection['id']) { - $this->saveConfig( - self::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - $connection['id'], - $store->getId() - ); - } - } - - $stores = $this->storeRepository->getList(); - - foreach ($stores as $store) { - if ($store->getId()) { - $connectionId = $this->getConnectionId($store->getId()); - if (($connectionId) && (!in_array($connectionId, $activeConnectionIds))) { - $this->configInterface->deleteConfig( - self::ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID, - \Magento\Store\Model\ScopeInterface::SCOPE_STORES, - $store->getId() - ); - } - } - } - - return true; - } - - return false; - } - - /** - * Save config - * - * @param string $path - * @param string $value - * @param int $scopeId - * - * @return void - */ - public function saveConfig( - string $path, - string $value, - int $scopeId - ) { - $scope = ($scopeId) - ? \Magento\Store\Model\ScopeInterface::SCOPE_STORES - : \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT; - $this->configInterface->saveConfig($path, $value, $scope, $scopeId); - } -} diff --git a/Core/Core/Logger/Handler.php b/Core/Core/Logger/Handler.php deleted file mode 100644 index 981e905..0000000 --- a/Core/Core/Logger/Handler.php +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/Core/Core/etc/adminhtml/routes.xml b/Core/Core/etc/adminhtml/routes.xml deleted file mode 100644 index d695645..0000000 --- a/Core/Core/etc/adminhtml/routes.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/Core/Core/etc/adminhtml/system.xml b/Core/Core/etc/adminhtml/system.xml deleted file mode 100644 index 5feb3e7..0000000 --- a/Core/Core/etc/adminhtml/system.xml +++ /dev/null @@ -1,40 +0,0 @@ - - - - - - -
- separator-top - - active_campaign - ActiveCampaign_Core::config_active_campaign - - - - - Magento\Config\Model\Config\Source\Enabledisable - - - - required-entry validate-url validate-no-html-tags - Example: https://youraccountname.api-us1.com - ActiveCampaign\Core\Block\Adminhtml\System\Config\FieldDisable - - - - required-entry - ActiveCampaign\Core\Block\Adminhtml\System\Config\FieldDisable - - - - -
-
-
diff --git a/Core/Core/etc/di.xml b/Core/Core/etc/di.xml deleted file mode 100644 index 90fe6ed..0000000 --- a/Core/Core/etc/di.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - Magento\Framework\Filesystem\Driver\File - - - - - ActiveCampaign - - ActiveCampaign\Core\Logger\Handler - - - - diff --git a/Core/Core/etc/module.xml b/Core/Core/etc/module.xml deleted file mode 100644 index 5686a9f..0000000 --- a/Core/Core/etc/module.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/Core/Core/registration.php b/Core/Core/registration.php deleted file mode 100644 index 63f921f..0000000 --- a/Core/Core/registration.php +++ /dev/null @@ -1,8 +0,0 @@ -getConnectedStores(); -?> -

- escapeHtmlAttr(__('Before clicking on this button Please click on Save Config button. ')) ?> - -

- -

- escapeHtmlAttr(__('After clicking on this button Please go to ')) ?> - escapeHtmlAttr(__('Cache Management ')) ?> - escapeHtmlAttr(__('and refresh cache types.')) ?> - -

-

 

-isDefaultConfig()): ?> - $store): ?> -
-
-
- escapeHtml(__($store['name'] . " :")) ?> - - escapeHtml(__("Connected")) ?> - - escapeHtml(__("Disconnected")) ?> - -
-
-
- - diff --git a/Core/Core/view/adminhtml/web/js/connection.js b/Core/Core/view/adminhtml/web/js/connection.js deleted file mode 100644 index 50f8a1e..0000000 --- a/Core/Core/view/adminhtml/web/js/connection.js +++ /dev/null @@ -1,125 +0,0 @@ -/** - * @api - */ -define([ - 'jquery', - 'Magento_Ui/js/modal/alert', - 'Magento_Ui/js/modal/confirm', - 'jquery/ui' -], function ($, alert, confirmation) { - 'use strict'; - - $.widget('mage.Connection', { - options: { - url: '', - elementId: '', - successText: '', - failedText: '', - fieldMapping: '', - txt:'' - }, - - /** - * Bind handlers to events - */ - _create: function () { - this._on({ - 'click': $.proxy(this._connect, this) - }); - }, - - /** - * Prepare AJAX request - * @private - */ - _connect: function () { - var result = this.options.failedText, - element = $('#' + this.options.elementId), - self = this, - params = {}, - msg = '', - fieldToCheck = this.options.fieldToCheck || 'success'; - - element.removeClass('success').addClass('fail'); - $.each($.parseJSON(this.options.fieldMapping), function (key, el) { - params[key] = $('#' + el).val(); - }); - - if(params.store === "0"){ - var content = $.mage.__('Do you want to connect all stores ?'); - if(!self.options.connection){ - content = $.mage.__('Do you want to disconnect all stores ?'); - } - confirmation({ - title: $.mage.__('Are you sure ?'), - content: content, - actions: { - confirm: function() { - self._connectAjax(self,params); - } - }, - buttons: [{ - text: $.mage.__('No'), - class: 'action-secondary action-dismiss', - click: function (event) { - this.closeModal(event); - } - }, { - text: $.mage.__('Yes'), - class: 'action-primary action-accept', - click: function (event) { - this.closeModal(event, true); - } - }] - }); - }else{ - self._connectAjax(self,params); - } - }, - - /** - * AJAX request to connection - * @private - */ - _connectAjax: function (self,params){ - var result = self.options.failedText, - element = $('#' + self.options.elementId), - msg = '', - fieldToCheck = self.options.fieldToCheck || 'success'; - - $.ajax({ - url: self.options.url, - showLoader: true, - data: params, - headers: self.options.headers || {} - - }).done(function (response) { - if (response.success){ - if (self.options.connection) { - alert({ - content : $.mage.__('Connected Successfully.'), - }); - }else{ - alert({ - content : $.mage.__('Disconnected Successfully.'), - }); - } - } else { - msg = response.errorMessage; - if (msg) { - alert({ - content: msg - }); - } - } - if (response[fieldToCheck]) { - element.removeClass('fail').addClass('success'); - result = self.options.successText; - } - }).always(function () { - $('#' + self.options.elementId + '_result').text(result); - }); - } - }); - return $.mage.Connection; -}); diff --git a/Customer/Cron/CustomerSync.php b/Customer/Cron/CustomerSync.php index b621b5c..46ecc47 100644 --- a/Customer/Cron/CustomerSync.php +++ b/Customer/Cron/CustomerSync.php @@ -14,6 +14,7 @@ use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerResourceCollectionFactory; use Magento\Eav\Model\ResourceModel\Entity\Attribute; use Psr\Log\LoggerInterface; +use Magento\Framework\App\Cache\TypeListInterface; class CustomerSync { @@ -25,6 +26,8 @@ class CustomerSync const METHOD = "POST"; + const METHOD_PUT = "PUT"; + /** * @var CustomerRepositoryInterface */ @@ -75,6 +78,11 @@ class CustomerSync */ protected $logger; + /** + * @var CacheTypeList + */ + protected $cacheTypeList; + /** * CustomerSync constructor. * @param CustomerRepositoryInterface $customerRepository @@ -98,7 +106,8 @@ public function __construct( CustomerHelper $customerHelper, CoreHelper $coreHelper, Curl $curl, - LoggerInterface $logger + LoggerInterface $logger, + TypeListInterface $cacheTypeList ) { $this->customerRepository = $customerRepository; $this->addressRepository = $addressRepository; @@ -110,6 +119,7 @@ public function __construct( $this->coreHelper = $coreHelper; $this->curl = $curl; $this->logger = $logger; + $this->cacheTypeList = $cacheTypeList; } public function execute() @@ -117,6 +127,7 @@ public function execute() if ($this->customerHelper->isCustomerSyncingEnabled()) { $contact = []; $ecomCustomer = []; + $this->updateCustomers(); $numberOfCustomers = (int)$this->customerHelper->getNumberOfCustomers(); $customers = $this->customerResourceCollectionFactory->create() @@ -128,16 +139,10 @@ public function execute() foreach ($customers as $customer) { $contactId = 0; + $customerId = $customer->getId(); $ecomCustomerId = 0; $syncStatus = CronConfig::NOT_SYNCED; - $customerId = $customer->getId(); - - $contact['email'] = $customer->getEmail(); - $contact['firstName'] = $customer->getFirstname(); - $contact['lastName'] = $customer->getLastname(); - $contact['phone'] = $this->getTelephone($customer->getDefaultBilling()); - $contact['fieldValues'] = $this->getFieldValues($customerId); - $contactData['contact'] = $contact; + $contactData = $this->contactBody($customer); try { $contactResult = $this->curl->createContacts(self::METHOD, self::CONTACT_ENDPOINT, $contactData); @@ -221,4 +226,41 @@ private function getFieldValues($customerId) } return $fieldValues; } + + public function updateCustomers(){ + + $numberOfCustomers = (int)$this->customerHelper->getNumberOfCustomers(); + $customers = $this->customerResourceCollectionFactory->create() + ->addAttributeToSelect('ac_contact_id') + ->addAttributeToFilter( 'ac_contact_id',['neq' => null ]) + ->addAttributeToFilter( self::AC_SYNC_STATUS,['eq' => CronConfig::SYNCED ]) + ->addAttributeToFilter('updated_at',['gt' => $this->customerHelper->getLastCustomerUpdateSync()]) + ->setOrder('updated_at','asc') + ->setPageSize($numberOfCustomers); + foreach ($customers as $customer){ + $contactData = $this->contactBody($customer); + $lastUpdate = $this->customerHelper->getLastCustomerUpdateSync(); + try { + $this->curl->createContacts(self::METHOD_PUT, self::CONTACT_ENDPOINT.'/'.$customer->getAcContactId(), $contactData); + $lastUpdate = $customer->getUpdatedAt(); + } catch (\Exception $e) { + $this->logger->critical("MODULE: Customer contact/sync" . $e); + } + } + $this->customerHelper->setLastCustomerUpdateSync($lastUpdate); + $this->cacheTypeList->cleanType('config'); + } + + + private function contactBody($customer){ + $customerId = $customer->getId(); + $contact['email'] = $customer->getEmail(); + $contact['firstName'] = $customer->getFirstname(); + $contact['lastName'] = $customer->getLastname(); + $contact['phone'] = $this->getTelephone($customer->getDefaultBilling()); + $contact['fieldValues'] = $this->getFieldValues($customerId); + $contactData['contact'] = $contact; + + return $contactData; + } } diff --git a/Customer/Customer/Block/Adminhtml/System/Config/CustomerSyncStatus.php b/Customer/Customer/Block/Adminhtml/System/Config/CustomerSyncStatus.php deleted file mode 100644 index 326abab..0000000 --- a/Customer/Customer/Block/Adminhtml/System/Config/CustomerSyncStatus.php +++ /dev/null @@ -1,184 +0,0 @@ -customerRepository = $customerRepository; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; - $this->filterBuilder = $filterBuilder; - - parent::__construct($context, $data); - $this->setSyncStatusData(); - } - - /** - * Set sync status data - * - * @return CustomerSyncStatus - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function setSyncStatusData() - { - $this->totalCustomer = $this->getTotalCustomersCount(); - $this->syncedCustomer = $this->getSyncedCustomerCount(); - $this->notSyncedCustomer = $this->getNotSyncedCustomerCount(); - $this->failSyncedCustomer = $this->getFailSyncedCustomerCount(); - - return $this; - } - - /** - * Get customer counter helper - * - * @param \Magento\Framework\Api\Filter[] $filter - * - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function getCustomerCountHelper(array $filter = []): int - { - $searchCriteria = $this->searchCriteriaBuilder; - - if (count($filter)) { - $searchCriteria->addFilters($filter); - } - - $searchCriteria->setCurrentPage(1) - ->setPageSize(1); - - return $this->customerRepository - ->getList($searchCriteria->create()) - ->getTotalCount(); - } - - /** - * Get total customers count - * - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - public function getTotalCustomersCount(): int - { - return $this->getCustomerCountHelper(); - } - - /** - * Get synced customer count - * - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - private function getSyncedCustomerCount(): int - { - return $this->getCustomerCountHelper([ - $this->filterBuilder - ->setField(self::AC_SYNC_STATUS) - ->setValue(\ActiveCampaign\Customer\Model\Config\CronConfig::SYNCED) - ->setConditionType('eq') - ->create() - ]); - } - - /** - * Get not synced customer count - * - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - private function getNotSyncedCustomerCount(): int - { - return $this->getCustomerCountHelper( - [ - $this->filterBuilder - ->setField(self::AC_SYNC_STATUS) - ->setValue(\ActiveCampaign\Customer\Model\Config\CronConfig::NOT_SYNCED) - ->setConditionType('eq') - ->create(), - $this->filterBuilder - ->setField(self::AC_SYNC_STATUS) - ->setValue(true) - ->setConditionType('null') - ->create() - ] - ); - } - - /** - * Get failed synced customer count - * - * @return int - * @throws \Magento\Framework\Exception\LocalizedException - */ - private function getFailSyncedCustomerCount(): int - { - return $this->getCustomerCountHelper([ - $this->filterBuilder - ->setField(self::AC_SYNC_STATUS) - ->setValue(\ActiveCampaign\Customer\Model\Config\CronConfig::FAIL_SYNCED) - ->setConditionType('eq') - ->create() - ]); - } -} diff --git a/Customer/Customer/Block/Adminhtml/System/Config/Widget.php b/Customer/Customer/Block/Adminhtml/System/Config/Widget.php deleted file mode 100644 index 1d8b2e6..0000000 --- a/Customer/Customer/Block/Adminhtml/System/Config/Widget.php +++ /dev/null @@ -1,27 +0,0 @@ -addChild('customer_sync_status', CustomerSyncStatus::class); - - return parent::_prepareLayout(); - } - - /** - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element - * - * @return string - */ - public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) - { - return $this->getChildHtml('customer_sync_status'); - } -} diff --git a/Customer/Customer/Controller/Adminhtml/Customer/MassSync.php b/Customer/Customer/Controller/Adminhtml/Customer/MassSync.php deleted file mode 100644 index dd93d86..0000000 --- a/Customer/Customer/Controller/Adminhtml/Customer/MassSync.php +++ /dev/null @@ -1,121 +0,0 @@ -customer = $customer; - $this->curl = $curl; - $this->logger = $logger; - $this->customerRepository = $customerRepository; - } - - /** - * @param AbstractCollection $collection - * @return \Magento\Backend\Model\View\Result\Redirect - */ - public function massAction(AbstractCollection $collection) - { - $customersSynced = 0; - $contactId = 0; - $ecomCustomerId = 0; - $syncStatus = CronConfig::NOT_SYNCED; - - foreach ($collection->getAllIds() as $customerId) { - if (!empty($customerId)) { - try { - $contactData = $this->customer->getContactData($customerId); - $isEcomCustomer = $contactData['contact']['isEcomCustomer']; - - unset($contactData['contact']['isEcomCustomer']); - - $contactResult = $this->curl->createContacts( - self::METHOD, - self::CONTACT_ENDPOINT, - $contactData - ); - $contactId = isset($contactResult['data']['contact']['id']) ? $contactResult['data']['contact']['id'] : null; - $syncStatus = ($contactResult['success']) ? CronConfig::SYNCED : CronConfig::FAIL_SYNCED; - - if ($contactResult['success'] && !$isEcomCustomer) { - $ecomCustomerData = $this->customer->getEcomCustomerData($customerId); - $ecomCustomerResult = $this->curl->createContacts( - self::METHOD, - self::ECOM_CUSTOMER_ENDPOINT, - $ecomCustomerData - ); - $ecomCustomerId = isset($ecomCustomerResult['data']['ecomCustomer']['id']) ? $ecomCustomerResult['data']['ecomCustomer']['id'] : null; - } - - $this->customer->saveResult($customerId, $syncStatus, $contactId, $ecomCustomerId); - } catch (\Exception $exception) { - $this->logger->critical("MODULE: Customer " . $exception); - } - } - $customersSynced++; - } - - if ($customersSynced) { - $this->messageManager->addSuccessMessage(__('A total of %1 record(s) were synced in the ActiveCampaign.', $customersSynced)); - } - /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */ - $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT); - $resultRedirect->setPath('customer/index'); - - return $resultRedirect; - } -} diff --git a/Customer/Customer/Cron/CustomerSync.php b/Customer/Customer/Cron/CustomerSync.php deleted file mode 100644 index b621b5c..0000000 --- a/Customer/Customer/Cron/CustomerSync.php +++ /dev/null @@ -1,224 +0,0 @@ -customerRepository = $customerRepository; - $this->addressRepository = $addressRepository; - $this->customerResourceCollectionFactory = $customerResourceCollectionFactory; - $this->customerFactory = $customerFactory; - $this->customerResource = $customerResource; - $this->eavAttribute = $eavAttribute; - $this->customerHelper = $customerHelper; - $this->coreHelper = $coreHelper; - $this->curl = $curl; - $this->logger = $logger; - } - - public function execute() - { - if ($this->customerHelper->isCustomerSyncingEnabled()) { - $contact = []; - $ecomCustomer = []; - $numberOfCustomers = (int)$this->customerHelper->getNumberOfCustomers(); - - $customers = $this->customerResourceCollectionFactory->create() - ->addAttributeToFilter([ - ['attribute' => self::AC_SYNC_STATUS,'null' => true ], - ['attribute' => self::AC_SYNC_STATUS,'neq' => CronConfig::SYNCED ] - ]) - ->setPageSize($numberOfCustomers); - - foreach ($customers as $customer) { - $contactId = 0; - $ecomCustomerId = 0; - $syncStatus = CronConfig::NOT_SYNCED; - $customerId = $customer->getId(); - - $contact['email'] = $customer->getEmail(); - $contact['firstName'] = $customer->getFirstname(); - $contact['lastName'] = $customer->getLastname(); - $contact['phone'] = $this->getTelephone($customer->getDefaultBilling()); - $contact['fieldValues'] = $this->getFieldValues($customerId); - $contactData['contact'] = $contact; - - try { - $contactResult = $this->curl->createContacts(self::METHOD, self::CONTACT_ENDPOINT, $contactData); - $contactId = isset($contactResult['data']['contact']['id']) ? $contactResult['data']['contact']['id'] : null; - - if ($contactResult['success']) { - $ecomCustomer['connectionid'] = $this->coreHelper->getConnectionId($customer->getStoreId()); - $ecomCustomer['externalid'] = $customerId; - $ecomCustomer['email'] = $customer->getEmail(); - $ecomCustomerData['ecomCustomer'] = $ecomCustomer; - $ecomCustomerResult = $this->curl->createContacts( - self::METHOD, - self::ECOM_CUSTOMER_ENDPOINT, - $ecomCustomerData - ); - $ecomCustomerId = isset($ecomCustomerResult['data']['ecomCustomer']['id']) ? $ecomCustomerResult['data']['ecomCustomer']['id'] : null; - $syncStatus = CronConfig::SYNCED; - } else { - $syncStatus = CronConfig::FAIL_SYNCED; - } - - $this->saveResult($customerId, $syncStatus, $contactId, $ecomCustomerId); - } catch (\Exception $e) { - $this->logger->critical("MODULE: Customer " . $e); - } - } - } - } - - /** - * @param $customerId - * @param $syncStatus - * @param $contactId - * @param $ecomCustomerId - * @throws \Magento\Framework\Exception\AlreadyExistsException - */ - private function saveResult($customerId, $syncStatus, $contactId, $ecomCustomerId) - { - $customerModel = $this->customerFactory->create(); - if ($customerId) { - $this->customerResource->load($customerModel, $customerId); - } - $customerModel->setAcSyncStatus($syncStatus); - $customerModel->setAcContactId($contactId); - $customerModel->setAcCustomerId($ecomCustomerId); - - $this->customerResource->save($customerModel); - } - - /** - * @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(); - } - return null; - } - - /** - * @param $customerId - * @return array - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - private function getFieldValues($customerId) - { - $fieldValues = []; - $customAttributes = $this->customerRepository->getById($customerId)->getCustomAttributes(); - if (!empty($customAttributes)) { - foreach ($customAttributes as $attribute) { - $attributeId = $this->eavAttribute->getIdByCode(Customer::ENTITY, $attribute->getAttributeCode()); - $attributeValues['field'] = $attributeId; - $attributeValues['value'] = $attribute->getValue(); - $fieldValues[] = $attributeValues; - } - } - return $fieldValues; - } -} diff --git a/Customer/Customer/Helper/Data.php b/Customer/Customer/Helper/Data.php deleted file mode 100644 index f2745e5..0000000 --- a/Customer/Customer/Helper/Data.php +++ /dev/null @@ -1,62 +0,0 @@ -scopeConfig->isSetFlag( - self::ACTIVE_CAMPAIGN_CUSTOMER_SYNC, - ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } - - /** - * @param null $scopeCode - * @return mixed - */ - public function getCronTime($scopeCode = null) - { - return $this->scopeConfig->getValue( - CronConfig::CRON_MODEL_PATH, - ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } - - /** - * @param null $scopeCode - * @return mixed - */ - public function getNumberOfCustomers($scopeCode = null) - { - return $this->scopeConfig->getValue( - self::ACTIVE_CAMPAIGN_CUSTOMER_NUMBER_OF_CUSTOMERS, - ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } -} diff --git a/Customer/Customer/Model/Config/CronConfig.php b/Customer/Customer/Model/Config/CronConfig.php deleted file mode 100644 index 3678255..0000000 --- a/Customer/Customer/Model/Config/CronConfig.php +++ /dev/null @@ -1,111 +0,0 @@ -_runModelPath = $runModelPath; - $this->_configValueFactory = $configValueFactory; - parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); - } - - /** - * @inheritdoc - * - * @return $this - * @throws \Exception - */ - public function afterSave() - { - $cronMinute = $this->getData('groups/customer/fields/cron_minute/value'); - $cronHour = $this->getData('groups/customer/fields/cron_hour/value'); - $cronDay = $this->getData('groups/customer/fields/cron_day/value'); - $cronMonth = $this->getData('groups/customer/fields/cron_month/value'); - $cronWeekday = $this->getData('groups/customer/fields/cron_weekday/value'); - - $cronMinute = ($cronMinute == null) ? '*' : $cronMinute; - $cronHour = ($cronHour == null) ? '*' : $cronHour; - $cronDay = ($cronDay == null) ? '*' : $cronDay; - $cronMonth = ($cronMonth == null) ? '*' : $cronMonth; - $cronWeekday = ($cronWeekday == null) ? '*' : $cronWeekday; - - $cronExprArray = [ - $cronMinute, //Minute - $cronHour, //Hour - $cronDay, //Day of the Month - $cronMonth, //Month of the Year - $cronWeekday, //Day of the Week - ]; - - $cronExprString = join(' ', $cronExprArray); - - try { - $this->_configValueFactory->create()->load( - self::CRON_STRING_PATH, - 'path' - )->setValue( - $cronExprString - )->setPath( - self::CRON_STRING_PATH - )->save(); - $this->_configValueFactory->create()->load( - self::CRON_MODEL_PATH, - 'path' - )->setValue( - $this->_runModelPath - )->setPath( - self::CRON_MODEL_PATH - )->save(); - } catch (\Exception $e) { - throw new \Exception(__('We can\'t save the cron expression.')); - } - - return parent::afterSave(); - } -} diff --git a/Customer/Customer/Model/Customer.php b/Customer/Customer/Model/Customer.php deleted file mode 100644 index 3eb1e9b..0000000 --- a/Customer/Customer/Model/Customer.php +++ /dev/null @@ -1,179 +0,0 @@ -customerRepository = $customerRepository; - $this->addressRepository = $addressRepository; - $this->eavAttribute = $eavAttribute; - $this->coreHelper = $coreHelper; - $this->customerFactory = $customerFactory; - $this->customerResource = $customerResource; - } - - /** - * @param $customerId - * @return array - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - public function getContactData($customerId) - { - $contact = []; - $customer = $this->customerRepository->getById($customerId); - - $contact['email'] = $customer->getEmail(); - $contact['firstName'] = $customer->getFirstname(); - $contact['lastName'] = $customer->getLastname(); - $contact['phone'] = $this->getTelephone($customer->getDefaultBilling()); - $contact['fieldValues'] = $this->getFieldValues($customer->getCustomAttributes()); - $contact['isEcomCustomer'] = $this->isEcomCustomer; - $contactData['contact'] = $contact; - - return $contactData; - } - - /** - * @param $customerId - * @return array - * @throws \Magento\Framework\Exception\LocalizedException - * @throws \Magento\Framework\Exception\NoSuchEntityException - */ - public function getEcomCustomerData($customerId) - { - $ecomCustomer = []; - $customer = $this->customerRepository->getById($customerId); - - $ecomCustomer['connectionid'] = $this->coreHelper->getConnectionId($customer->getStoreId()); - $ecomCustomer['externalid'] = $customer->getId(); - $ecomCustomer['email'] = $customer->getEmail(); - $ecomCustomerData['ecomCustomer'] = $ecomCustomer; - - return $ecomCustomerData; - } - - /** - * @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(); - } - return null; - } - - /** - * @param $customAttributes - * @return array - */ - private function getFieldValues($customAttributes) - { - $fieldValues = []; - if (!empty($customAttributes)) { - foreach ($customAttributes as $attribute) { - $attributeId = $this->eavAttribute->getIdByCode( - \Magento\Customer\Model\Customer::ENTITY, - $attribute->getAttributeCode() - ); - if ($attribute->getAttributeCode() === self::AC_CUSTOMER_ID) { - $this->isEcomCustomer = ($attribute->getValue()) ? true : false; - } - $attributeValues['field'] = $attributeId; - $attributeValues['value'] = $attribute->getValue(); - $fieldValues[] = $attributeValues; - } - } - return $fieldValues; - } - - /** - * @param $customerId - * @param $syncStatus - * @param $contactId - * @param $ecomCustomerId - * @throws \Magento\Framework\Exception\AlreadyExistsException - */ - public function saveResult($customerId, $syncStatus, $contactId, $ecomCustomerId) - { - $customerModel = $this->customerFactory->create(); - if ($customerId) { - $this->customerResource->load($customerModel, $customerId); - } - - $customerModel->setAcSyncStatus($syncStatus); - if ($contactId) { - $customerModel->setAcContactId($contactId); - } - if ($ecomCustomerId) { - $customerModel->setAcCustomerId($ecomCustomerId); - } - - $this->customerResource->save($customerModel); - } -} diff --git a/Customer/Customer/Observer/CustomerSaveAfter.php b/Customer/Customer/Observer/CustomerSaveAfter.php deleted file mode 100644 index f90cc1b..0000000 --- a/Customer/Customer/Observer/CustomerSaveAfter.php +++ /dev/null @@ -1,92 +0,0 @@ -customer = $customer; - $this->curl = $curl; - $this->logger = $logger; - } - - /** - * Upgrade order customer email when customer has changed email - * - * @param Observer $observer - * @return void - */ - public function execute(Observer $observer): void - { - /** @var Customer $originalCustomer */ - $originalCustomer = $observer->getEvent()->getOrigCustomerDataObject(); - if (!$originalCustomer) { - return; - } - - /** @var Customer $customer */ - $customer = $observer->getEvent()->getCustomerDataObject(); - - $contactId = 0; - $ecomCustomerId = 0; - $syncStatus = CronConfig::NOT_SYNCED; - $customerId = $customer->getId(); - - try { - $contactData = $this->customer->getContactData($customerId); - $isEcomCustomer = $contactData['contact']['isEcomCustomer']; - - unset($contactData['contact']['isEcomCustomer']); - - $contactResult = $this->curl->createContacts(self::METHOD, self::CONTACT_ENDPOINT, $contactData); - $contactId = isset($contactResult['data']['contact']['id']) ? $contactResult['data']['contact']['id'] : null; - $syncStatus = ($contactResult['success']) ? CronConfig::SYNCED : CronConfig::FAIL_SYNCED; - - if ($contactResult['success'] && !$isEcomCustomer) { - $ecomCustomerData = $this->customer->getEcomCustomerData($customerId); - $ecomCustomerResult = $this->curl->createContacts( - self::METHOD, - self::ECOM_CUSTOMER_ENDPOINT, - $ecomCustomerData - ); - $ecomCustomerId = isset($ecomCustomerResult['data']['ecomCustomer']['id']) ? $ecomCustomerResult['data']['ecomCustomer']['id'] : null; - } - $this->customer->saveResult($customerId, $syncStatus, $contactId, $ecomCustomerId); - } catch (\Exception $e) { - $this->logger->critical("MODULE: Customer " . $e); - } - } -} diff --git a/Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcContactId.php b/Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcContactId.php deleted file mode 100644 index 9565cea..0000000 --- a/Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcContactId.php +++ /dev/null @@ -1,120 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->customerSetupFactory = $customerSetupFactory; - $this->attributeSetFactory = $attributeSetFactory; - } - - /** - * {@inheritdoc} - */ - public function apply() - { - $this->moduleDataSetup->getConnection()->startSetup(); - /** @var CustomerSetup $customerSetup */ - $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); - $customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY); - $attributeSetId = $customerEntity->getDefaultAttributeSetId(); - - /** @var $attributeSet Set */ - $attributeSet = $this->attributeSetFactory->create(); - $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); - if (!$customerSetup->getAttributeId(Customer::ENTITY, 'ac_contact_id')) { - $customerSetup->addAttribute( - Customer::ENTITY, - 'ac_contact_id', - [ - 'type' => 'int', - 'input' => 'hidden', - 'label' => 'ActiveCampaign Contact Id', - 'default' => 0, - 'required' => false, - 'visible' => false, - 'system' => false, - 'user_defined' => false, - 'is_visible_in_grid' => true, - 'is_used_in_grid' => true, - 'is_filterable_in_grid' => true, - 'is_searchable_in_grid' => true, - 'position' => 999 - ] - ); - - $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'ac_contact_id'); - $attribute->addData([ - 'attribute_set_id' => $attributeSetId, - 'attribute_group_id' => $attributeGroupId - ]); - $attribute->save(); - } - - $this->moduleDataSetup->getConnection()->endSetup(); - } - - public function revert() - { - $this->moduleDataSetup->getConnection()->startSetup(); - /** @var CustomerSetup $customerSetup */ - $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); - $customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'ac_contact_id'); - - $this->moduleDataSetup->getConnection()->endSetup(); - } - - /** - * {@inheritdoc} - */ - public function getAliases() - { - return []; - } - - /** - * {@inheritdoc} - */ - public static function getDependencies() - { - return [ - - ]; - } -} diff --git a/Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcCustomerId.php b/Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcCustomerId.php deleted file mode 100644 index 3209027..0000000 --- a/Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcCustomerId.php +++ /dev/null @@ -1,120 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->customerSetupFactory = $customerSetupFactory; - $this->attributeSetFactory = $attributeSetFactory; - } - - /** - * {@inheritdoc} - */ - public function apply() - { - $this->moduleDataSetup->getConnection()->startSetup(); - /** @var CustomerSetup $customerSetup */ - $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); - $customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY); - $attributeSetId = $customerEntity->getDefaultAttributeSetId(); - - /** @var $attributeSet Set */ - $attributeSet = $this->attributeSetFactory->create(); - $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); - if (!$customerSetup->getAttributeId(Customer::ENTITY, 'ac_customer_id')) { - $customerSetup->addAttribute( - Customer::ENTITY, - 'ac_customer_id', - [ - 'type' => 'int', - 'input' => 'hidden', - 'label' => 'ActiveCampaign Customer Id', - 'default' => 0, - 'required' => false, - 'visible' => false, - 'system' => false, - 'user_defined' => false, - 'is_visible_in_grid' => true, - 'is_used_in_grid' => true, - 'is_filterable_in_grid' => true, - 'is_searchable_in_grid' => true, - 'position' => 999 - ] - ); - - $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'ac_customer_id'); - $attribute->addData([ - 'attribute_set_id' => $attributeSetId, - 'attribute_group_id' => $attributeGroupId - ]); - $attribute->save(); - } - - $this->moduleDataSetup->getConnection()->endSetup(); - } - - public function revert() - { - $this->moduleDataSetup->getConnection()->startSetup(); - /** @var CustomerSetup $customerSetup */ - $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); - $customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'ac_customer_id'); - - $this->moduleDataSetup->getConnection()->endSetup(); - } - - /** - * {@inheritdoc} - */ - public function getAliases() - { - return []; - } - - /** - * {@inheritdoc} - */ - public static function getDependencies() - { - return [ - - ]; - } -} diff --git a/Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcSyncStatus.php b/Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcSyncStatus.php deleted file mode 100644 index 5aceed9..0000000 --- a/Customer/Customer/Setup/Patch/Data/AddCustomerAttributeAcSyncStatus.php +++ /dev/null @@ -1,120 +0,0 @@ -moduleDataSetup = $moduleDataSetup; - $this->customerSetupFactory = $customerSetupFactory; - $this->attributeSetFactory = $attributeSetFactory; - } - - /** - * {@inheritdoc} - */ - public function apply() - { - $this->moduleDataSetup->getConnection()->startSetup(); - /** @var CustomerSetup $customerSetup */ - $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); - $customerEntity = $customerSetup->getEavConfig()->getEntityType(Customer::ENTITY); - $attributeSetId = $customerEntity->getDefaultAttributeSetId(); - - /** @var $attributeSet Set */ - $attributeSet = $this->attributeSetFactory->create(); - $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId); - if (!$customerSetup->getAttributeId(Customer::ENTITY, 'ac_sync_status')) { - $customerSetup->addAttribute( - Customer::ENTITY, - 'ac_sync_status', - [ - 'type' => 'int', - 'input' => 'hidden', - 'label' => 'ActiveCampaign Status', - 'default' => 0, - 'required' => false, - 'visible' => false, - 'system' => false, - 'user_defined' => false, - 'is_visible_in_grid' => true, - 'is_used_in_grid' => true, - 'is_filterable_in_grid' => true, - 'is_searchable_in_grid' => true, - 'position' => 998 - ] - ); - - $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'ac_sync_status'); - $attribute->addData([ - 'attribute_set_id' => $attributeSetId, - 'attribute_group_id' => $attributeGroupId - ]); - $attribute->save(); - } - - $this->moduleDataSetup->getConnection()->endSetup(); - } - - public function revert() - { - $this->moduleDataSetup->getConnection()->startSetup(); - /** @var CustomerSetup $customerSetup */ - $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]); - $customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'ac_sync_status'); - - $this->moduleDataSetup->getConnection()->endSetup(); - } - - /** - * {@inheritdoc} - */ - public function getAliases() - { - return []; - } - - /** - * {@inheritdoc} - */ - public static function getDependencies() - { - return [ - - ]; - } -} diff --git a/Customer/Customer/Ui/Component/Listing/Column/AcSyncStatus.php b/Customer/Customer/Ui/Component/Listing/Column/AcSyncStatus.php deleted file mode 100644 index 5b3c634..0000000 --- a/Customer/Customer/Ui/Component/Listing/Column/AcSyncStatus.php +++ /dev/null @@ -1,42 +0,0 @@ -getData('name')] = $this->getFieldLabel($item); - } - } - return $dataSource; - } - - /** - * Retrieve field label - * - * @param array $item - * @return string - */ - private function getFieldLabel(array $item) - { - $acSyncStatus = (int)$item['ac_sync_status']; - if ($acSyncStatus === CronConfig::SYNCED) { - return __('Synced'); - } elseif ($acSyncStatus === CronConfig::NOT_SYNCED) { - return __('Not Synced'); - } elseif ($acSyncStatus === CronConfig::FAIL_SYNCED) { - return __('Not Synced'); - } - return __('Something Wrong'); - } -} diff --git a/Customer/Customer/composer.json b/Customer/Customer/composer.json deleted file mode 100644 index 5644d47..0000000 --- a/Customer/Customer/composer.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "activecampaign/customer", - "description": "ActiveCampaign Customer", - "type": "magento2-module", - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "config": { - "sort-packages": true - }, - "version": "2.1.0", - "require": { - "php": "~7.3.0||~7.4.0||~8.0||~8.1", - "activecampaign/core": "2.1.*" - }, - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "ActiveCampaign\\Customer\\": "" - } - } -} diff --git a/Customer/Customer/etc/adminhtml/routes.xml b/Customer/Customer/etc/adminhtml/routes.xml deleted file mode 100644 index 695dbb1..0000000 --- a/Customer/Customer/etc/adminhtml/routes.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/Customer/Customer/etc/adminhtml/system.xml b/Customer/Customer/etc/adminhtml/system.xml deleted file mode 100644 index 6936ce0..0000000 --- a/Customer/Customer/etc/adminhtml/system.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - -
- - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - 1 - - ActiveCampaign\Customer\Model\Config\CronConfig - - - - - - 1 - - - - - - - 1 - - - - - - - 1 - - - - - - - 1 - - - - - required-entry validate-number validate-greater-than-zero validate-integer - - - 1 - - - - - ActiveCampaign\Customer\Block\Adminhtml\System\Config\Widget - - 1 - - - -
-
-
diff --git a/Customer/Customer/etc/config.xml b/Customer/Customer/etc/config.xml deleted file mode 100644 index 01344ac..0000000 --- a/Customer/Customer/etc/config.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - 0 - 100 - 10 - * - * - * - * - - - - diff --git a/Customer/Customer/etc/crontab.xml b/Customer/Customer/etc/crontab.xml deleted file mode 100644 index bc9f531..0000000 --- a/Customer/Customer/etc/crontab.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - crontab/default/jobs/ac_customer_sync_cron_job/schedule/cron_expr - - - diff --git a/Customer/Customer/etc/events.xml b/Customer/Customer/etc/events.xml deleted file mode 100644 index 43c661e..0000000 --- a/Customer/Customer/etc/events.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/Customer/Customer/etc/module.xml b/Customer/Customer/etc/module.xml deleted file mode 100644 index 37ce8b1..0000000 --- a/Customer/Customer/etc/module.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/Customer/Customer/registration.php b/Customer/Customer/registration.php deleted file mode 100644 index e527be0..0000000 --- a/Customer/Customer/registration.php +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - - -
-
-
-
- escapeHtml(__("Total Customer :")) ?> - escapeHtml(__($block->totalCustomer)) ?> -
-
-
-
-
-
- escapeHtml(__("Synced Customer :")) ?> - escapeHtml(__($block->syncedCustomer)) ?> -
-
-
-
-
-
- escapeHtml(__("Not Synced Customer :")) ?> - escapeHtml(__($block->notSyncedCustomer)) ?> -
-
-
-
-
-
- escapeHtml(__("Fail Synced Customer :")) ?> - escapeHtml(__($block->failSyncedCustomer)) ?> -
-
-
-
diff --git a/Customer/Customer/view/adminhtml/ui_component/customer_listing.xml b/Customer/Customer/view/adminhtml/ui_component/customer_listing.xml deleted file mode 100644 index 73526e7..0000000 --- a/Customer/Customer/view/adminhtml/ui_component/customer_listing.xml +++ /dev/null @@ -1,27 +0,0 @@ - -- - - - - - Are you sure you want to sync the selected customers in the ActiveCampaign? - Sync - - - sync - - - - - - - - - select - - true - - - - diff --git a/Customer/Helper/Data.php b/Customer/Helper/Data.php index f2745e5..ff74bc4 100644 --- a/Customer/Helper/Data.php +++ b/Customer/Helper/Data.php @@ -5,19 +5,28 @@ use Magento\Framework\App\Helper\Context; use Magento\Store\Model\ScopeInterface; use ActiveCampaign\Customer\Model\Config\CronConfig; - +use \Magento\Framework\App\Config\ConfigResource\ConfigInterface; class Data extends AbstractHelper { const ACTIVE_CAMPAIGN_CUSTOMER_SYNC = "active_campaign/customer/sync"; const ACTIVE_CAMPAIGN_CUSTOMER_NUMBER_OF_CUSTOMERS = "active_campaign/customer/number_of_customers"; + const ACTIVE_CAMPAIGN_CUSTOMER_UPDATE_LAST_SYNC = "active_campaign/customer/last_customers_updated"; + /** + * @var \Magento\Framework\App\Config\ConfigResource\ConfigInterface + */ + private $configInterface; /** * Data constructor. * @param Context $context */ + + public function __construct( - Context $context + Context $context, + ConfigInterface $configInterface ) { + $this->configInterface = $configInterface; parent::__construct($context); } @@ -59,4 +68,19 @@ public function getNumberOfCustomers($scopeCode = null) $scopeCode ); } + + public function getLastCustomerUpdateSync($scopeCode = null) + { + return $this->scopeConfig->getValue( + self::ACTIVE_CAMPAIGN_CUSTOMER_UPDATE_LAST_SYNC, + ScopeInterface::SCOPE_STORES, + $scopeCode + ); + } + + public function setLastCustomerUpdateSync($date, $scopeCode = null) + { + $scope = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT; + $this->configInterface->saveConfig(self::ACTIVE_CAMPAIGN_CUSTOMER_UPDATE_LAST_SYNC, $date, $scope); + } } diff --git a/Customer/etc/config.xml b/Customer/etc/config.xml index 01344ac..0ccfa46 100644 --- a/Customer/etc/config.xml +++ b/Customer/etc/config.xml @@ -16,6 +16,7 @@ * * * + 0 diff --git a/Order/Order/Block/Adminhtml/System/Config/OrderSyncStatus.php b/Order/Order/Block/Adminhtml/System/Config/OrderSyncStatus.php deleted file mode 100644 index 2fceeba..0000000 --- a/Order/Order/Block/Adminhtml/System/Config/OrderSyncStatus.php +++ /dev/null @@ -1,139 +0,0 @@ -orderRepository = $orderRepository; - $this->searchCriteriaBuilder = $searchCriteriaBuilder; - $this->filterBuilder = $filterBuilder; - - parent::__construct($context, $data); - } - - /** - * Get order count helper - * - * @param \Magento\Framework\Api\Filter[] $filter - * @return int - */ - public function getOrderCountHelper(array $filter = []): int - { - $searchCriteria = $this->searchCriteriaBuilder; - - if (count($filter)) { - $searchCriteria->addFilters($filter); - } - $searchCriteria = $searchCriteria->create(); - $searchCriteria->setCurrentPage(1) - ->setPageSize(1); - - return $this->orderRepository - ->getList($searchCriteria) - ->getTotalCount(); - } - - /** - * Get total order - * - * @return int - */ - public function getTotalOrder(): int - { - return $this->getOrderCountHelper(); - } - - /** - * Get sync order - * - * @return int - */ - public function getSyncOrder(): int - { - return $this->getOrderCountHelper([ - $this->filterBuilder - ->setField(self::AC_SYNC_STATUS) - ->setValue(\ActiveCampaign\Order\Model\Config\CronConfig::SYNCED) - ->setConditionType('eq') - ->create() - ]); - } - - /** - * Get not sync order - * - * @return int - */ - public function getNotSyncOrder(): int - { - return $this->getOrderCountHelper( - [ - $this->filterBuilder - ->setField(self::AC_SYNC_STATUS) - ->setValue(\ActiveCampaign\Order\Model\Config\CronConfig::NOT_SYNCED) - ->setConditionType('eq') - ->create(), - $this->filterBuilder - ->setField(self::AC_SYNC_STATUS) - ->setValue(true) - ->setConditionType('null') - ->create() - ] - ); - } - - /** - * Get failed sync - * - * @return int - */ - public function getFailedSync(): int - { - return $this->getOrderCountHelper([ - $this->filterBuilder - ->setField(self::AC_SYNC_STATUS) - ->setValue(\ActiveCampaign\Order\Model\Config\CronConfig::FAIL_SYNCED) - ->setConditionType('eq') - ->create() - ]); - } -} diff --git a/Order/Order/Block/Adminhtml/System/Config/Widget.php b/Order/Order/Block/Adminhtml/System/Config/Widget.php deleted file mode 100644 index c8ad733..0000000 --- a/Order/Order/Block/Adminhtml/System/Config/Widget.php +++ /dev/null @@ -1,26 +0,0 @@ -addChild('order_sync_status', OrderSyncStatus::class); - - return parent::_prepareLayout(); - } - - /** - * @param \Magento\Framework\Data\Form\Element\AbstractElement $element - * @return string - */ - public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element) - { - return $this->getChildHtml('order_sync_status'); - } -} diff --git a/Order/Order/Controller/Adminhtml/Order/Masssync.php b/Order/Order/Controller/Adminhtml/Order/Masssync.php deleted file mode 100644 index fc3c8f2..0000000 --- a/Order/Order/Controller/Adminhtml/Order/Masssync.php +++ /dev/null @@ -1,101 +0,0 @@ -orderdataSend = $orderdataSend; - $this->collectionFactory = $collectionFactory; - $this->orderManagement = $orderManagement; - $this->curl = $curl; - $this->quoteRepository = $quoteRepository; - } - - protected function massAction(AbstractCollection $collection) - { - $countUpdateOrder = 0; - $countAlreadySync = 0; - foreach ($collection->getItems() as $order) { - if (!$order->getEntityId()) { - continue; - } - $ac_order_sync_status = $order->getData('ac_order_sync_status'); - if (!$ac_order_sync_status) { - $result = $this->orderdataSend->orderDataSend($order); - if (array_key_exists('success', $result) && $result['success'] != false) { - $countUpdateOrder++; - } - $quote = $this->quoteRepository->get($order->getQuoteId()); - if ($quote->getAcOrderSyncId() != 0) { - $this->curl->orderDataDelete(self::DELETE_METHOD, self::URL_ENDPOINT, $quote->getAcOrderSyncId()); - } - } else { - $countAlreadySync++; - } - } - $countNonUpdateOrder = $collection->count() - $countUpdateOrder - $countAlreadySync; - if ($countUpdateOrder || $countNonUpdateOrder) { - $this->messageManager->addNoticeMessage(__( - 'Orders synced: %1 Orders failed: %2', - $countUpdateOrder, - $countNonUpdateOrder - )); - } - if ($countAlreadySync) { - $this->messageManager->addNoticeMessage(__('%1 order(s) had already been synced.', $countAlreadySync)); - } - $resultRedirect = $this->resultRedirectFactory->create(); - $resultRedirect->setPath($this->getComponentRefererUrl()); - return $resultRedirect; - } -} diff --git a/Order/Order/Cron/OrderSyncCron.php b/Order/Order/Cron/OrderSyncCron.php deleted file mode 100644 index 7d87607..0000000 --- a/Order/Order/Cron/OrderSyncCron.php +++ /dev/null @@ -1,115 +0,0 @@ -orderdataSend = $orderdataSend; - $this->_orderCollectionFactory = $orderCollectionFactory; - $this->activeCampaignHelper = $activeCampaignHelper; - $this->state = $state; - $this->curl = $curl; - $this->quoteRepository = $quoteRepository; - $this->logger = $logger; - } - - /** - * @throws NoSuchEntityException|GuzzleException - */ - public function execute(): void - { - try { - $isEnabled = $this->activeCampaignHelper->isOrderSyncEnabled(); - if ($isEnabled) { - $OrderSyncNum = $this->activeCampaignHelper->getOrderSyncNum(); - $orderCollection = $this->_orderCollectionFactory->create() - ->addAttributeToSelect('*') - ->addFieldToFilter( - 'ac_order_sync_status', - ['eq' => 0] - ) - ->setPageSize($OrderSyncNum); - - foreach ($orderCollection as $order) { - try { - $this->orderdataSend->orderDataSend($order); - $quote = $this->quoteRepository->get($order->getQuoteId()); - if ($quote->getAcOrderSyncId() !== 0) { - $this->curl->orderDataDelete(self::DELETE_METHOD, self::URL_ENDPOINT, $quote->getAcOrderSyncId()); - } - } catch (NoSuchEntityException|GuzzleException $e) { - $this->logger->error('MODULE Order: ' . $e->getMessage()); - } - } - } - } catch (\Exception $e) { - $this->logger->error('MODULE Order: ' . $e->getMessage()); - } - } -} diff --git a/Order/Order/Helper/Data.php b/Order/Order/Helper/Data.php deleted file mode 100644 index cfed1e4..0000000 --- a/Order/Order/Helper/Data.php +++ /dev/null @@ -1,55 +0,0 @@ -state = $state; - } - - /** - * @param null $scopeCode - * @return bool - */ - public function isOrderSyncEnabled($scopeCode = null) - { - return $this->scopeConfig->isSetFlag( - self::ACTIVE_CAMPAIGN_ORDER_STATUS, - ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } - - /** - * @param null $scopeCode - * @return mixed - */ - public function getOrderSyncNum($scopeCode = null) - { - return $this->scopeConfig->getValue( - self::ACTIVE_CAMPAIGN_ORDER_SYNC_NUM, - ScopeInterface::SCOPE_STORES, - $scopeCode - ); - } -} diff --git a/Order/Order/Model/Config/CronConfig.php b/Order/Order/Model/Config/CronConfig.php deleted file mode 100644 index dfc3190..0000000 --- a/Order/Order/Model/Config/CronConfig.php +++ /dev/null @@ -1,111 +0,0 @@ -_runModelPath = $runModelPath; - $this->_configValueFactory = $configValueFactory; - parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data); - } - - /** - * {@inheritdoc} - * - * @return $this - * @throws \Exception - */ - public function afterSave() - { - $cronMinute = $this->getData('groups/order_sync/fields/cron_minute/value'); - $cronHour = $this->getData('groups/order_sync/fields/cron_hour/value'); - $cronDay = $this->getData('groups/order_sync/fields/cron_day/value'); - $cronMonth = $this->getData('groups/order_sync/fields/cron_month/value'); - $cronWeekday = $this->getData('groups/order_sync/fields/cron_weekday/value'); - - $cronMinute = ($cronMinute == null) ? '*' : $cronMinute; - $cronHour = ($cronHour == null) ? '*' : $cronHour; - $cronDay = ($cronDay == null) ? '*' : $cronDay; - $cronMonth = ($cronMonth == null) ? '*' : $cronMonth; - $cronWeekday = ($cronWeekday == null) ? '*' : $cronWeekday; - - $cronExprArray = [ - $cronMinute, //Minute - $cronHour, //Hour - $cronDay, //Day of the Month - $cronMonth, //Month of the Year - $cronWeekday, //Day of the Week - ]; - - $cronExprString = join(' ', $cronExprArray); - - try { - $this->_configValueFactory->create()->load( - self::CRON_STRING_PATH, - 'path' - )->setValue( - $cronExprString - )->setPath( - self::CRON_STRING_PATH - )->save(); - $this->_configValueFactory->create()->load( - self::CRON_MODEL_PATH, - 'path' - )->setValue( - $this->_runModelPath - )->setPath( - self::CRON_MODEL_PATH - )->save(); - } catch (\Exception $e) { - throw new \Exception(__('We can\'t save the cron expression.')); - } - - return parent::afterSave(); - } -} diff --git a/Order/Order/Model/OrderData/OrderDataSend.php b/Order/Order/Model/OrderData/OrderDataSend.php deleted file mode 100644 index 1e936d4..0000000 --- a/Order/Order/Model/OrderData/OrderDataSend.php +++ /dev/null @@ -1,456 +0,0 @@ -_productRepositoryFactory = $productRepositoryFactory; - $this->imageHelperFactory = $imageHelperFactory; - $this->activeCampaignOrderHelper = $activeCampaignOrderHelper; - $this->activeCampaignHelper = $activeCampaignHelper; - $this->configInterface = $configInterface; - $this->curl = $curl; - $this->_customerRepositoryInterface = $customerRepositoryInterface; - $this->storeRepository = $storeRepository; - $this->customerFactory = $customerFactory; - $this->storeManager = $storeManager; - $this->customerModel = $customerModel; - $this->addressRepository = $addressRepository; - $this->eavAttribute = $eavAttribute; - $this->coreHelper = $coreHelper; - $this->customerResource = $customerResource; - } - - /** - * @param $order - * @return array - * @throws GuzzleException - */ - public function orderDataSend($order): array - { - $return = []; - $isEnabled = $this->activeCampaignOrderHelper->isOrderSyncEnabled(); - if ($isEnabled) { - try { - $connectionId = $this->activeCampaignHelper->getConnectionId($order->getStoreId()); - $customerId = $order->getCustomerId(); - $customerAcId = 0; - if ($customerId) { - $this->createEcomCustomer($order->getCustomerId(), $order); - $customerEmail = $order->getCustomerEmail(); - $customerModel = $this->customerFactory->create(); - $this->customerResource->load($customerModel, $customerId); - if ($customerModel->getAcCustomerId()) { - $customerAcId = $customerModel->getAcCustomerId(); - } - } else { - $customerEmail = $order->getBillingAddress()->getEmail(); - $websiteId = $this->storeManager->getWebsite()->getWebsiteId(); - $customerModel = $this->customerModel; - $customerModel->setWebsiteId($websiteId); - $customerModel->loadByEmail($customerEmail); - if ($customerModel->getId()) { - $customerId = $customerModel->getId(); - } else { - $customerId = 0; - } - $this->createEcomCustomer($customerId, $order); - $customerModel = $this->customerFactory->create(); - $this->customerResource->load($customerModel, $customerId); - if ($customerModel->getAcCustomerId()) { - $customerAcId = $customerModel->getAcCustomerId(); - } else { - if ($order->getAcTempCustomerId()) { - $customerAcId = $order->getAcTempCustomerId(); - } else { - $AcCustomer = $this->curl->listAllCustomers( - self::GET_METHOD, - self::ECOM_CUSTOMER_ENDPOINT, - $customerEmail - ); - foreach ($AcCustomer['data']['ecomCustomers'] as $Ac) { - if ($Ac['connectionid'] == $connectionId) { - $customerAcId = $Ac['id']; - } - } - } - } - } - - foreach ($order->getAllVisibleItems() as $item) { - $product = $this->_productRepositoryFactory->create() - ->get($item->getSku()); - $imageUrl = $this->imageHelperFactory->create() - ->init($product, 'product_thumbnail_image')->getUrl(); - $items[] = [ - "externalid" => $item->getProductId(), - "name" => $item->getName(), - "price" => $this->activeCampaignHelper->priceToCents($item->getPrice()), - "quantity" => $item->getQtyOrdered(), - "category" => implode(', ', $product->getCategoryIds()), - "sku" => $item->getSku(), - "description" => $item->getDescription(), - "imageUrl" => $imageUrl, - "productUrl" => $product->getProductUrl() - ]; - } - $data = [ - "ecomOrder" => [ - "externalid" => $order->getId(), - "source" => 1, - "email" => $customerEmail, - "orderProducts" => $items, - "orderDiscounts" => [ - "discountAmount" => $this->activeCampaignHelper->priceToCents($order->getDiscountAmount()) - ], - "externalCreatedDate" => $order->getCreatedAt(), - "externalUpdatedDate" => $order->getUpdatedAt(), - "shippingMethod" => $order->getShippingMethod(), - "totalPrice" => $this->activeCampaignHelper->priceToCents($order->getGrandTotal()), - "shippingAmount" => $this->activeCampaignHelper->priceToCents($order->getShippingAmount()), - "taxAmount" => $this->activeCampaignHelper->priceToCents($order->getTaxAmount()), - "discountAmount" => $this->activeCampaignHelper->priceToCents($order->getDiscountAmount()), - "currency" => $order->getOrderCurrencyCode(), - "orderNumber" => $order->getIncrementId(), - "connectionid" => $connectionId, - "customerid" => $customerAcId - ] - ]; - - if (!$order->getAcOrderSyncId()) { - $result = $this->curl->orderDataSend( - self::METHOD, - self::URL_ENDPOINT, - $data - ); - if ($result['status'] == '422' || $result['status'] == '400') { - $ecomAlreadyExistOrderData = []; - $ecomAlreadyExistOrderResult = $this->curl->createContacts( - self::GET_METHOD, - self::URL_ENDPOINT, - $ecomAlreadyExistOrderData - ); - $ecomOrders = $ecomAlreadyExistOrderResult['data']['ecomOrders']; - foreach ($ecomOrders as $ecomKey => $customers) { - $ecomOrderArray[$ecomOrders[$ecomKey]['email']] = $ecomOrders[$ecomKey]['id']; - } - $acOrderId = $ecomOrderArray[$customerEmail]; - } else { - $acOrderId = isset($result['data']['ecomOrders']['id']) ? $result['data']['ecomOrders']['id'] : null; - } - } else { - $acOrderId = $order->getAcOrderSyncId(); - } - - if ($acOrderId != 0) { - $syncStatus = CronConfig::SYNCED; - } else { - $syncStatus = CronConfig::FAIL_SYNCED; - } - - $order->setData("ac_order_sync_status", $syncStatus) - ->setData("ac_order_sync_id", $acOrderId) - ->save(); - - if (isset($result['success'])) { - $return['success'] = __("Order data successfully synced!!"); - } - } catch (\Exception $e) { - $return['success'] = false; - $return['errorMessage'] = __($e->getMessage()); - } - } - return $return; - } - - /** - * @param null $billingId - * @return string|null - * @throws LocalizedException - */ - private function getTelephone($billingId = null): ?string - { - if ($billingId) { - $address = $this->addressRepository->getById($billingId); - return $address->getTelephone(); - } - return null; - } - - /** - * @param $customerId - * @return array - * @throws LocalizedException - * @throws NoSuchEntityException - */ - private function getFieldValues($customerId) - { - $fieldValues = []; - $customAttributes = $this->_customerRepositoryInterface->getById($customerId); - $customAttributes->getCustomAttributes(); - if (!empty($customAttributes)) { - foreach ($customAttributes as $attribute) { - $attributeId = $this->eavAttribute->getIdByCode(CustomerModel::ENTITY, $attribute->getAttributeCode()); - $attributeValues['field'] = $attributeId; - $attributeValues['value'] = $attribute->getValue(); - $fieldValues[] = $attributeValues; - } - } - return $fieldValues; - } - - /** - * @param $customerId - * @return object - */ - private function getCustomer($customerId): object - { - $customerModel = $this->customerFactory->create(); - $this->customerResource->load($customerModel, $customerId); - return $customerModel; - } - - /** - * @param $customerId - * @return array - */ - private function createEcomCustomer($customerId, $quote) - { - $ecomOrderArray = []; - $ecomCustomerId = 0; - $syncStatus = CronConfig::NOT_SYNCED; - $customer = $this->getCustomer($customerId); - if ($customerId) { - $customerId = $customer->getId(); - $contact['email'] = $customer->getEmail(); - $customerEmail = $customer->getEmail(); - $contact['firstName'] = $customer->getFirstname(); - $contact['lastName'] = $customer->getLastname(); - $contact['phone'] = $this->getTelephone($customer->getDefaultBilling()); - $contact['fieldValues'] = $this->getFieldValues($customerId); - } else { - $customerId = 0; - $contact['email'] = $quote->getBillingAddress()->getEmail(); - $customerEmail = $quote->getBillingAddress()->getEmail(); - $contact['firstName'] = $quote->getBillingAddress()->getFirstname(); - $contact['lastName'] = $quote->getBillingAddress()->getLastname(); - $contact['phone'] = $quote->getBillingAddress()->getTelephone(); - $contact['fieldValues'] = []; - } - $contactData['contact'] = $contact; - try { - $contactResult = $this->curl->createContacts(self::METHOD, self::CONTACT_ENDPOINT, $contactData); - $contactId = isset($contactResult['data']['contact']['id']) ? $contactResult['data']['contact']['id'] : null; - $connectionid = $this->coreHelper->getConnectionId($customer->getStoreId()); - - if (isset($contactResult['data']['contact']['id'])) { - if (!$customer->getAcCustomerId()) { - $ecomCustomer['connectionid'] = $connectionid; - $ecomCustomer['externalid'] = $customerId; - $ecomCustomer['email'] = $customerEmail; - $ecomCustomerData['ecomCustomer'] = $ecomCustomer; - $AcCustomer = $this->curl->listAllCustomers( - self::GET_METHOD, - self::ECOM_CUSTOMERLIST_ENDPOINT, - $customerEmail - ); - if (isset($AcCustomer['data']['ecomCustomers'][0])) { - foreach ($AcCustomer['data']['ecomCustomers'] as $Ac) { - if ($Ac['connectionid'] == $connectionid) { - $ecomCustomerId = $Ac['id']; - } - } - } - if (!$ecomCustomerId) { - $ecomCustomerResult = $this->curl->createContacts( - self::METHOD, - self::ECOM_CUSTOMERLIST_ENDPOINT, - $ecomCustomerData - ); - $ecomCustomerId = isset($ecomCustomerResult['data']['ecomCustomer']['id']) ? $ecomCustomerResult['data']['ecomCustomer']['id'] : null; - } - } else { - $ecomCustomerId = $customer->getAcCustomerId(); - } - } - - if ($ecomCustomerId != 0) { - $syncStatus = CronConfig::SYNCED; - } else { - $syncStatus = CronConfig::FAIL_SYNCED; - } - - if ($customerId) { - $this->saveCustomerResult($customerId, $syncStatus, $contactId, $ecomCustomerId); - } else { - $this->saveCustomerResultQuote($quote, $ecomCustomerId); - } - } catch (\Exception $e) { - $this->logger->critical("MODULE Order " . $e); - } - } - - /** - * @param $customerId - * @param $syncStatus - * @param $contactId - * @param $ecomCustomerId - * @throws \Magento\Framework\Exception\AlreadyExistsException - */ - private function saveCustomerResult($customerId, $syncStatus, $contactId, $ecomCustomerId) - { - $customerModel = $this->customerFactory->create(); - if ($customerId) { - $this->customerResource->load($customerModel, $customerId); - } - - $customerModel->setAcSyncStatus($syncStatus); - - $customerModel->setAcContactId($contactId); - $customerModel->setAcCustomerId($ecomCustomerId); - - $this->customerResource->save($customerModel); - } - - /** - * @param $quote - * @param $ecomCustomerId - * @throws \Magento\Framework\Exception\AlreadyExistsException - */ - private function saveCustomerResultQuote($quote, $ecomCustomerId) - { - if ($ecomCustomerId) { - $quote->setData("ac_temp_customer_id", $ecomCustomerId); - $quote->save(); - } - } -} diff --git a/Order/Order/Observer/OrderSync.php b/Order/Order/Observer/OrderSync.php deleted file mode 100644 index e665cdb..0000000 --- a/Order/Order/Observer/OrderSync.php +++ /dev/null @@ -1,98 +0,0 @@ -orderdataSend = $orderdataSend; - $this->curl = $curl; - $this->activeCampaignHelper = $activeCampaignHelper; - $this->orderModel = $orderModel; - $this->quoteRepository = $quoteRepository; - $this->logger = $logger; - } - - /** - * @param Observer $observer - * @return void - */ - public function execute(Observer $observer) - { - $isEnabled = $this->activeCampaignHelper->isOrderSyncEnabled(); - $orderIds = $observer->getEvent()->getOrderIds(); - - if ($isEnabled) { - foreach ($orderIds as $orderId) { - $orderData = $this->orderModel->load($orderId); - $acOrderStatus = $orderData->getAcOrderSyncStatus(); - if ($acOrderStatus == 0) { - $this->orderdataSend->orderDataSend($orderData); - } - - $quote = $this->quoteRepository->get($orderData->getQuoteId()); - $this->curl->orderDataDelete(self::DELETE_METHOD, self::URL_ENDPOINT, $quote->getAcOrderSyncId()); - if ($orderData->getStatus() == 'canceled') { - $orderSyncId = $orderData->getAcOrderSyncId(); - $this->curl->orderDataDelete(self::DELETE_METHOD, self::URL_ENDPOINT, $orderSyncId); - } - } - } - } -} diff --git a/Order/Order/Ui/Component/Listing/Column/OrderStatus.php b/Order/Order/Ui/Component/Listing/Column/OrderStatus.php deleted file mode 100644 index 0a32a2a..0000000 --- a/Order/Order/Ui/Component/Listing/Column/OrderStatus.php +++ /dev/null @@ -1,51 +0,0 @@ -_orderRepository = $orderRepository; - $this->_searchCriteria = $criteria; - parent::__construct($context, $uiComponentFactory, $components, $data); - } - - /** - * @param array $dataSource - * @return array - */ - public function prepareDataSource(array $dataSource) - { - if (isset($dataSource['data']['items'])) { - foreach ($dataSource['data']['items'] as & $item) { - $order = $this->_orderRepository->get($item["entity_id"]); - $status = $order->getData("ac_order_sync_status"); - - if ($status) { - $message = 'Synced'; - } else { - $message = 'Not Synced'; - } - - $item[$this->getData('name')] = $message; - } - } - - return $dataSource; - } -} diff --git a/Order/Order/composer.json b/Order/Order/composer.json deleted file mode 100644 index 8845a28..0000000 --- a/Order/Order/composer.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "name": "activecampaign/order", - "description": "ActiveCampaign Order", - "type": "magento2-module", - "license": [ - "OSL-3.0", - "AFL-3.0" - ], - "config": { - "sort-packages": true - }, - "version": "2.1.0", - "require": { - "php": "~7.3.0||~7.4.0||~8.0||~8.1", - "activecampaign/core": "2.1.*" - }, - "autoload": { - "files": [ - "registration.php" - ], - "psr-4": { - "ActiveCampaign\\Order\\": "" - } - } -} diff --git a/Order/Order/etc/adminhtml/routes.xml b/Order/Order/etc/adminhtml/routes.xml deleted file mode 100644 index 8478357..0000000 --- a/Order/Order/etc/adminhtml/routes.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/Order/Order/etc/adminhtml/system.xml b/Order/Order/etc/adminhtml/system.xml deleted file mode 100644 index 6cf8720..0000000 --- a/Order/Order/etc/adminhtml/system.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - -
- separator-top - - active_campaign - ActiveCampaign_Core::config_active_campaign - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - 1 - - ActiveCampaign\Order\Model\Config\CronConfig - - - - - - 1 - - - - - - - 1 - - - - - - - 1 - - - - - - - 1 - - - - - Number of orders sync at a time - - - - ActiveCampaign\Order\Block\Adminhtml\System\Config\Widget - - 1 - - - -
-
-
diff --git a/Order/Order/etc/config.xml b/Order/Order/etc/config.xml deleted file mode 100644 index 5b59491..0000000 --- a/Order/Order/etc/config.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - 0 - 100 - 5 - * - * - * - * - - - - diff --git a/Order/Order/etc/crontab.xml b/Order/Order/etc/crontab.xml deleted file mode 100644 index 8cf3e97..0000000 --- a/Order/Order/etc/crontab.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - crontab/default/jobs/ac_order_sync_cron_job/schedule/cron_expr - - - diff --git a/Order/Order/etc/db_schema.xml b/Order/Order/etc/db_schema.xml deleted file mode 100644 index 8170de8..0000000 --- a/Order/Order/etc/db_schema.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - -
- - - -
-
diff --git a/Order/Order/etc/events.xml b/Order/Order/etc/events.xml deleted file mode 100644 index c68ed4c..0000000 --- a/Order/Order/etc/events.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/Order/Order/etc/extension_attributes.xml b/Order/Order/etc/extension_attributes.xml deleted file mode 100644 index 7b4a4e7..0000000 --- a/Order/Order/etc/extension_attributes.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - diff --git a/Order/Order/etc/module.xml b/Order/Order/etc/module.xml deleted file mode 100644 index bc8814e..0000000 --- a/Order/Order/etc/module.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/Order/Order/registration.php b/Order/Order/registration.php deleted file mode 100644 index 750c0e9..0000000 --- a/Order/Order/registration.php +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - - -
-
-
-
- escapeHtml(__("Total Orders :")) ?> - escapeHtml(__($block->getTotalOrder())) ?> -
-
-
-
-
-
- escapeHtml(__("Synced Orders :")) ?> - escapeHtml(__($block->getSyncOrder())) ?> -
-
-
-
-
-
- escapeHtml(__("Not Synced Orders :")) ?> - escapeHtml(__($block->getNotSyncOrder())) ?> -
-
-
-
-
-
- escapeHtml(__("Fail Synced Orders :")) ?> - escapeHtml(__($block->getFailedSync())) ?> -
-
-
-
diff --git a/Order/Order/view/adminhtml/ui_component/sales_order_grid.xml b/Order/Order/view/adminhtml/ui_component/sales_order_grid.xml deleted file mode 100644 index 6da657a..0000000 --- a/Order/Order/view/adminhtml/ui_component/sales_order_grid.xml +++ /dev/null @@ -1,30 +0,0 @@ - -- - - - - - order_sync - Sync to ActiveCampaign - - - Sync Order(s) - Are you sure you wan\'t to sync selected items? - - - - - - - - - - - true - ActiveCampaign Sync Status - - - - - diff --git a/SyncLog/SyncLog/Block/Adminhtml/View/Log.php b/SyncLog/SyncLog/Block/Adminhtml/View/Log.php deleted file mode 100755 index a41969e..0000000 --- a/SyncLog/SyncLog/Block/Adminhtml/View/Log.php +++ /dev/null @@ -1,32 +0,0 @@ -syncLogModelFactory = $syncLogModelFactory; - $this->_request = $request; - } - - public function getLogCollection() - { - $param = $this->getRequest()->getParams(); - $collection = $this->syncLogModelFactory->getCollection() - ->addFieldToFilter('id', $param['id'])->getData(); - //echo "
";print_r($collection);exit;
-        return $collection;
-    }
-}
diff --git a/SyncLog/SyncLog/Controller/Adminhtml/Index/Index.php b/SyncLog/SyncLog/Controller/Adminhtml/Index/Index.php
deleted file mode 100755
index bae64d4..0000000
--- a/SyncLog/SyncLog/Controller/Adminhtml/Index/Index.php
+++ /dev/null
@@ -1,37 +0,0 @@
-resultPageFactory = $resultPageFactory;
-    }
-
-    /**
-     * Grid List page.
-     *
-     * @return \Magento\Backend\Model\View\Result\Page
-     */
-    public function execute()
-    {
-        /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
-        $resultPage = $this->resultPageFactory->create();
-        $resultPage->setActiveMenu('ActiveCampaign_SyncLog::logs');
-        $resultPage->getConfig()->getTitle()->prepend(__('ActiveCampaign Sync Logs'));
-        return $resultPage;
-    }
-}
diff --git a/SyncLog/SyncLog/Controller/Adminhtml/Index/View.php b/SyncLog/SyncLog/Controller/Adminhtml/Index/View.php
deleted file mode 100755
index 63b1d33..0000000
--- a/SyncLog/SyncLog/Controller/Adminhtml/Index/View.php
+++ /dev/null
@@ -1,36 +0,0 @@
-resultPageFactory = $resultPageFactory;
-    }
-
-    /**
-     * Grid List page.
-     *
-     * @return \Magento\Backend\Model\View\Result\Page
-     */
-    public function execute()
-    {
-        /** @var \Magento\Backend\Model\View\Result\Page $resultPage */
-        $resultPage = $this->resultPageFactory->create();
-        $resultPage->getConfig()->getTitle()->prepend(__('ActiveCampaign Log Information'));
-        return $resultPage;
-    }
-}
diff --git a/SyncLog/SyncLog/Cron/DeleteSyncLog.php b/SyncLog/SyncLog/Cron/DeleteSyncLog.php
deleted file mode 100644
index 0866af5..0000000
--- a/SyncLog/SyncLog/Cron/DeleteSyncLog.php
+++ /dev/null
@@ -1,70 +0,0 @@
-scopeConfig = $scopeConfig;
-        $this->connection = $connection;
-        $this->dateTime = $dateTime;
-    }
-
-    /**
-     * Execute the cron
-     *
-     * @return void
-     */
-    public function execute()
-    {
-        if($this->isDeletingEnabled()) {
-            $connection = $this->connection->getConnection();
-            $tableName = $connection->getTableName(self::SYNCLOG_TABLE);
-            $currentDate = $this->dateTime->gmtDate("Y-m-d", strtotime('-7 days'));
-            $whereConditions = [
-                  $connection->quoteInto("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
-        );
-    }
-}
diff --git a/SyncLog/SyncLog/Model/Config/CronConfig.php b/SyncLog/SyncLog/Model/Config/CronConfig.php
deleted file mode 100644
index 3dde4b6..0000000
--- a/SyncLog/SyncLog/Model/Config/CronConfig.php
+++ /dev/null
@@ -1,113 +0,0 @@
-_runModelPath = $runModelPath;
-        $this->_configValueFactory = $configValueFactory;
-        parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
-    }
-
-    /**
-     * @inheritdoc
-     *
-     * @return $this
-     * @throws \Exception
-     */
-    public function afterSave()
-    {
-        $cronMinute = $this->getData('groups/synclog/fields/cron_minute/value');
-        $cronHour = $this->getData('groups/synclog/fields/cron_hour/value');
-        $cronDay = $this->getData('groups/synclog/fields/cron_day/value');
-        $cronMonth = $this->getData('groups/synclog/fields/cron_month/value');
-        $cronWeekday = $this->getData('groups/synclog/fields/cron_weekday/value');
-
-        $cronMinute = ($cronMinute == null) ? '*' : $cronMinute;
-        $cronHour = ($cronHour == null) ? '*' : $cronHour;
-        $cronDay = ($cronDay == null) ? '*' : $cronDay;
-        $cronMonth = ($cronMonth == null) ? '*' : $cronMonth;
-        $cronWeekday = ($cronWeekday == null) ? '*' : $cronWeekday;
-
-        $cronExprArray = [
-            $cronMinute,            //Minute
-            $cronHour,              //Hour
-            $cronDay,               //Day of the Month
-            $cronMonth,             //Month of the Year
-            $cronWeekday,           //Day of the Week
-        ];
-
-        $cronExprString = join(' ', $cronExprArray);
-
-        try {
-            $this->_configValueFactory->create()->load(
-                self::CRON_STRING_PATH,
-                'path'
-            )->setValue(
-                $cronExprString
-            )->setPath(
-                self::CRON_STRING_PATH
-            )->save();
-
-            $this->_configValueFactory->create()->load(
-                self::CRON_MODEL_PATH,
-                'path'
-            )->setValue(
-                $this->_runModelPath
-            )->setPath(
-                self::CRON_MODEL_PATH
-            )->save();
-
-        } catch (\Exception $e) {
-            throw new \Magento\Framework\Exception\LocalizedException(__('We can\'t save the Cron expression.'));
-        }
-
-        return parent::afterSave();
-    }
-}
diff --git a/SyncLog/SyncLog/Model/ResourceModel/SyncLog.php b/SyncLog/SyncLog/Model/ResourceModel/SyncLog.php
deleted file mode 100755
index 0037633..0000000
--- a/SyncLog/SyncLog/Model/ResourceModel/SyncLog.php
+++ /dev/null
@@ -1,18 +0,0 @@
-_init('sync_log', 'id');
-    }
-}
diff --git a/SyncLog/SyncLog/Model/ResourceModel/SyncLog/Collection.php b/SyncLog/SyncLog/Model/ResourceModel/SyncLog/Collection.php
deleted file mode 100755
index cc8e70d..0000000
--- a/SyncLog/SyncLog/Model/ResourceModel/SyncLog/Collection.php
+++ /dev/null
@@ -1,20 +0,0 @@
-_init('ActiveCampaign\SyncLog\Model\SyncLog', 'ActiveCampaign\SyncLog\Model\ResourceModel\SyncLog');
-    }
-}
diff --git a/SyncLog/SyncLog/Model/ResourceModel/SyncLog/Grid/Collection.php b/SyncLog/SyncLog/Model/ResourceModel/SyncLog/Grid/Collection.php
deleted file mode 100755
index bc925c3..0000000
--- a/SyncLog/SyncLog/Model/ResourceModel/SyncLog/Grid/Collection.php
+++ /dev/null
@@ -1,133 +0,0 @@
-_eventPrefix = $eventPrefix;
-        $this->_eventObject = $eventObject;
-        $this->_init($model, $resourceModel);
-        $this->setMainTable($mainTable);
-    }
-
-    /**
-     * @return AggregationInterface
-     */
-    public function getAggregations()
-    {
-        return $this->aggregations;
-    }
-
-    /**
-     * @param AggregationInterface $aggregations
-     * @return $this
-     */
-    public function setAggregations($aggregations)
-    {
-        $this->aggregations = $aggregations;
-        return $this;
-    }
-
-    /**
-     * Get search criteria.
-     *
-     * @return \Magento\Framework\Api\SearchCriteriaInterface|null
-     */
-    public function getSearchCriteria()
-    {
-        return null;
-    }
-
-    /**
-     * Set search criteria.
-     *
-     * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
-     * @return $this
-     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
-     */
-    public function setSearchCriteria(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
-    {
-        return $this;
-    }
-
-    /**
-     * Get total count.
-     *
-     * @return int
-     */
-    public function getTotalCount()
-    {
-        return $this->getSize();
-    }
-
-    /**
-     * Set total count.
-     *
-     * @param int $totalCount
-     * @return $this
-     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
-     */
-    public function setTotalCount($totalCount)
-    {
-        return $this;
-    }
-
-    /**
-     * Set items list.
-     *
-     * @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
-     * @return $this
-     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
-     */
-    public function setItems(array $items = null)
-    {
-        return $this;
-    }
-}
diff --git a/SyncLog/SyncLog/Model/Status.php b/SyncLog/SyncLog/Model/Status.php
deleted file mode 100755
index 64f1916..0000000
--- a/SyncLog/SyncLog/Model/Status.php
+++ /dev/null
@@ -1,51 +0,0 @@
- __('Success'),'0' => __('Failed')];
-        return $options;
-    }
-
-    /**
-     * Get Grid row status labels array with empty value for option element.
-     *
-     * @return array
-     */
-    public function getAllOptions()
-    {
-        $res = $this->getOptions();
-        array_unshift($res, ['value' => '', 'label' => '']);
-        return $res;
-    }
-
-    /**
-     * Get Grid row type array for option element.
-     * @return array
-     */
-    public function getOptions()
-    {
-        $res = [];
-        foreach ($this->getOptionArray() as $index => $value) {
-            $res[] = ['value' => $index, 'label' => $value];
-        }
-        return $res;
-    }
-
-    /**
-     * {@inheritdoc}
-     */
-    public function toOptionArray()
-    {
-        return $this->getOptions();
-    }
-}
diff --git a/SyncLog/SyncLog/Model/SyncLog.php b/SyncLog/SyncLog/Model/SyncLog.php
deleted file mode 100755
index 28f878d..0000000
--- a/SyncLog/SyncLog/Model/SyncLog.php
+++ /dev/null
@@ -1,29 +0,0 @@
-_init('ActiveCampaign\SyncLog\Model\ResourceModel\SyncLog');
-    }
-
-    public function getIdentities()
-    {
-        return [self::CACHE_TAG . '_' . $this->getId()];
-    }
-
-    public function getDefaultValues()
-    {
-        $values = [];
-
-        return $values;
-    }
-}
diff --git a/SyncLog/SyncLog/Ui/Component/Listing/Grid/Column/Action.php b/SyncLog/SyncLog/Ui/Component/Listing/Grid/Column/Action.php
deleted file mode 100755
index 09aa1ed..0000000
--- a/SyncLog/SyncLog/Ui/Component/Listing/Grid/Column/Action.php
+++ /dev/null
@@ -1,61 +0,0 @@
-urlBuilder = $urlBuilder;
-        parent::__construct($context, $uiComponentFactory, $components, $data);
-    }
-
-    /**
-     * Prepare Data Source.
-     *
-     * @param array $dataSource
-     *
-     * @return array
-     */
-    public function prepareDataSource(array $dataSource)
-    {
-        if (isset($dataSource['data']['items'])) {
-            foreach ($dataSource['data']['items'] as &$item) {
-                $name = $this->getData('name');
-                if (isset($item['id'])) {
-                    $item[$name]['delete'] = [
-                        'href' => $this->urlBuilder->getUrl(self::ROW_VIEW_URL, ['id' => $item['id']]),
-                        'label' => __('View')
-                    ];
-                }
-            }
-        }
-        return $dataSource;
-    }
-}
diff --git a/SyncLog/SyncLog/composer.json b/SyncLog/SyncLog/composer.json
deleted file mode 100644
index 9e28bf7..0000000
--- a/SyncLog/SyncLog/composer.json
+++ /dev/null
@@ -1,25 +0,0 @@
-{
-    "name": "activecampaign/synclog",
-    "description": "ActiveCampaign SyncLog",
-    "type": "magento2-module",
-    "license": [
-        "OSL-3.0",
-        "AFL-3.0"
-    ],
-    "config": {
-        "sort-packages": true
-    },
-    "version": "2.1.0",
-    "require": {
-        "php": "~7.3.0||~7.4.0||~8.0||~8.1",
-        "activecampaign/core": "2.1.*"
-    },
-    "autoload": {
-        "files": [
-            "registration.php"
-        ],
-        "psr-4": {
-            "ActiveCampaign\\SyncLog\\": ""
-        }
-    }
-}
diff --git a/SyncLog/SyncLog/etc/acl.xml b/SyncLog/SyncLog/etc/acl.xml
deleted file mode 100644
index 8ad6c25..0000000
--- a/SyncLog/SyncLog/etc/acl.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-
-
-    
-        
-            
-                
-                    
-                        
-                            
-                                
-                            
-                        
-                    
-                
-            
-        
-    
-
diff --git a/SyncLog/SyncLog/etc/adminhtml/menu.xml b/SyncLog/SyncLog/etc/adminhtml/menu.xml
deleted file mode 100755
index 19f3589..0000000
--- a/SyncLog/SyncLog/etc/adminhtml/menu.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-    
-        
-        
-        
-    
-
diff --git a/SyncLog/SyncLog/etc/adminhtml/routes.xml b/SyncLog/SyncLog/etc/adminhtml/routes.xml
deleted file mode 100755
index 25e9a3c..0000000
--- a/SyncLog/SyncLog/etc/adminhtml/routes.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-
-
-    
-        
-            
-        
-    
-
diff --git a/SyncLog/SyncLog/etc/adminhtml/system.xml b/SyncLog/SyncLog/etc/adminhtml/system.xml
deleted file mode 100644
index de8278a..0000000
--- a/SyncLog/SyncLog/etc/adminhtml/system.xml
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
-    
-        
- active_campaign - ActiveCampaign_SyncLog::config_activecampaign_synclog - - - - - - Magento\Config\Model\Config\Source\Yesno - - - - - - 1 - - ActiveCampaign\SyncLog\Model\Config\CronConfig - - - - - - 1 - - - - - - - 1 - - - - - - - 1 - - - - - - - 1 - - - -
-
-
diff --git a/SyncLog/SyncLog/etc/config.xml b/SyncLog/SyncLog/etc/config.xml deleted file mode 100644 index fd49e1b..0000000 --- a/SyncLog/SyncLog/etc/config.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - 0 - * - * - * - * - * - - - - diff --git a/SyncLog/SyncLog/etc/crontab.xml b/SyncLog/SyncLog/etc/crontab.xml deleted file mode 100644 index c1471a4..0000000 --- a/SyncLog/SyncLog/etc/crontab.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - crontab/default/jobs/activecampaign_synclog/schedule/cron_expr - - - diff --git a/SyncLog/SyncLog/etc/db_schema.xml b/SyncLog/SyncLog/etc/db_schema.xml deleted file mode 100755 index bc1a015..0000000 --- a/SyncLog/SyncLog/etc/db_schema.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - - - -
-
diff --git a/SyncLog/SyncLog/etc/di.xml b/SyncLog/SyncLog/etc/di.xml deleted file mode 100755 index 5addc02..0000000 --- a/SyncLog/SyncLog/etc/di.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - sync_log - sync_log - sync_log - ActiveCampaign\SyncLog\Model\ResourceModel\SyncLog - - - - - - ActiveCampaign\SyncLog\Model\ResourceModel\SyncLog\Grid\Collection - - - - diff --git a/SyncLog/SyncLog/etc/module.xml b/SyncLog/SyncLog/etc/module.xml deleted file mode 100755 index 6434473..0000000 --- a/SyncLog/SyncLog/etc/module.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - diff --git a/SyncLog/SyncLog/registration.php b/SyncLog/SyncLog/registration.php deleted file mode 100755 index 672e895..0000000 --- a/SyncLog/SyncLog/registration.php +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - diff --git a/SyncLog/SyncLog/view/adminhtml/layout/synclog_index_view.xml b/SyncLog/SyncLog/view/adminhtml/layout/synclog_index_view.xml deleted file mode 100755 index b7d8434..0000000 --- a/SyncLog/SyncLog/view/adminhtml/layout/synclog_index_view.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/SyncLog/SyncLog/view/adminhtml/templates/synclog.phtml b/SyncLog/SyncLog/view/adminhtml/templates/synclog.phtml deleted file mode 100755 index dbe7f2e..0000000 --- a/SyncLog/SyncLog/view/adminhtml/templates/synclog.phtml +++ /dev/null @@ -1,55 +0,0 @@ -getLogCollection()); -?> -
-
-
- -
-
-
- -
-
- -
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
-
-
-
diff --git a/SyncLog/SyncLog/view/adminhtml/ui_component/synclog_record_grid_list.xml b/SyncLog/SyncLog/view/adminhtml/ui_component/synclog_record_grid_list.xml deleted file mode 100755 index da19826..0000000 --- a/SyncLog/SyncLog/view/adminhtml/ui_component/synclog_record_grid_list.xml +++ /dev/null @@ -1,132 +0,0 @@ - -- - - synclog_record_grid_list.synclog_record_grid_list_data_source - synclog_record_grid_list.synclog_record_grid_list_data_source - - synclog_records_columns - - - - Magento\Framework\View\Element\UiComponent\DataProvider\DataProvider - synclog_record_grid_list_data_source - id - id - - - - - - - - - Magento_Ui/js/grid/provider - - - - - - - ui/grid/toolbar - ui/grid/sticky/toolbar - - - - - - - - synclog_record_grid_list.synclog_record_grid_list.synclog_records_columns - - synclog_record_grid_list.synclog_record_grid_list.listing_top.bookmarks - current.filters - - - synclog_record_grid_list.synclog_record_grid_list.listing_top.listing_filters - - synclog_record_grid_list.synclog_record_grid_list.synclog_records_columns.${ $.index }:visible - - - - - column - - - - - - - - synclog_record_grid_list.synclog_record_grid_list.listing_top.bookmarks - current.paging - - synclog_record_grid_list.synclog_record_grid_list.synclog_records_columns.ids - - - - - - - - - Magento_Ui/js/grid/columns/column - - - text - asc - left - ID - 1 - - 1 - - - - - - textRange - Type - - - - - - ActiveCampaign\SyncLog\Model\Status - - select - Magento_Ui/js/grid/columns/select - select - Status - - - - - - - dateRange - Magento_Ui/js/grid/columns/date - date - Creation Date - - - - - - - dateRange - Magento_Ui/js/grid/columns/date - date - Finish Date - - - - - - - id - - - - - diff --git a/composer.json b/composer.json index ff354b6..866f673 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "ActiveCampaign extension for Magento 2.3 and 2.4", "type": "magento2-component", "license": "OSL-3.0", - "version": "2.0.5", + "version": "2.0.6", "repositories": [ { "type": "composer", From 17adf61343958176920eff155373c991919cca0d Mon Sep 17 00:00:00 2001 From: Jorge Venzon Date: Mon, 23 Jan 2023 16:03:16 -0300 Subject: [PATCH 2/5] Added "order_url" to abandoned carts --- AbandonedCart/Model/AbandonedCartSendData.php | 16 +++++++++++++--- Core/Helper/Curl.php | 8 ++++++-- Core/Helper/Data.php | 17 +++++++++++++++++ Core/etc/adminhtml/system.xml | 8 ++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/AbandonedCart/Model/AbandonedCartSendData.php b/AbandonedCart/Model/AbandonedCartSendData.php index 7133f33..945b7f5 100644 --- a/AbandonedCart/Model/AbandonedCartSendData.php +++ b/AbandonedCart/Model/AbandonedCartSendData.php @@ -22,6 +22,7 @@ use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Model\AbstractModel; use Magento\Framework\Stdlib\DateTime; +use Magento\Framework\UrlInterface; use Magento\Quote\Api\CartRepositoryInterface; use Magento\Quote\Model\QuoteFactory; use Magento\Quote\Model\ResourceModel\Quote\CollectionFactory as QuoteResourceCollectionFactory; @@ -120,10 +121,15 @@ class AbandonedCartSendData extends AbstractModel */ private $quoteRepository; + /** + * @var UrlInterface + */ + protected $urlBuilder; + private $customerId; /** - * CustomerSync constructor. + * AbandonedCartSendData constructor. * @param CustomerRepositoryInterface $customerRepository * @param AddressRepositoryInterface $addressRepository * @param CustomerResourceCollectionFactory $customerResourceCollectionFactory @@ -145,6 +151,7 @@ class AbandonedCartSendData extends AbstractModel * @param CustomerModel $customerModel * @param DateTime $dateTime * @param CartRepositoryInterface $quoteRepository + * @param UrlInterface $urlBuilder */ public function __construct( CustomerRepositoryInterface $customerRepository, @@ -167,8 +174,10 @@ public function __construct( StoreManagerInterface $storeManager, CustomerModel $customerModel, DateTime $dateTime, - CartRepositoryInterface $quoteRepository + CartRepositoryInterface $quoteRepository, + UrlInterface $urlBuilder ) { + $this->urlBuilder = $urlBuilder; $this->customerRepository = $customerRepository; $this->addressRepository = $addressRepository; $this->customerResourceCollectionFactory = $customerResourceCollectionFactory; @@ -205,7 +214,7 @@ public function sendAbandonedCartData($quoteId = null): array $abandonedCarts = $this->quoteResourceCollectionFactory->create() ->addFieldToSelect('*') ->addFieldToFilter('ac_synced_date', [ - ['gt' => new \Zend_Db_Expr('updated_at')], + ['lt' => new \Zend_Db_Expr('updated_at')], ['null' => true] ]) ->addFieldToFilter( @@ -297,6 +306,7 @@ public function sendAbandonedCartData($quoteId = null): array "orderDiscounts" => [ "discountAmount" => $this->coreHelper->priceToCents($abandonedCart->getDiscountAmount()) ], + "orderUrl" => $this->urlBuilder->getDirectUrl('checkout/cart'), "abandonedDate" => $abandonedCart->getCreatedAt(), "externalCreatedDate" => $abandonedCart->getCreatedAt(), "externalUpdatedDate" => $abandonedCart->getUpdatedAt(), diff --git a/Core/Helper/Curl.php b/Core/Helper/Curl.php index 08031a7..ea1a5e2 100644 --- a/Core/Helper/Curl.php +++ b/Core/Helper/Curl.php @@ -347,7 +347,9 @@ private function sendRequest( $synclog->setMethod($method); $synclog->setRequest($this->jsonHelper->serialize($request)); - $this->logger->info('REQUEST', $request); + if($this->activeCampaignHelper->isDebugEnabled()){ + $this->logger->info('REQUEST', $request); + } $options = []; $options[\GuzzleHttp\RequestOptions::HEADERS] = $headers; @@ -361,7 +363,9 @@ private function sendRequest( $body = $resultCurl->getBody()->getContents(); $response = $this->jsonHelper->unserialize($body); - $this->logger->info('RESPONSE', $response); + if($this->activeCampaignHelper->isDebugEnabled()){ + $this->logger->info('RESPONSE', $response); + } $synclog->setResponse($body); $synclog->setStatus(1); diff --git a/Core/Helper/Data.php b/Core/Helper/Data.php index 6a9df46..56c1314 100644 --- a/Core/Helper/Data.php +++ b/Core/Helper/Data.php @@ -9,6 +9,8 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper public const ACTIVE_CAMPAIGN_GENERAL_API_URL = 'active_campaign/general/api_url'; public const ACTIVE_CAMPAIGN_GENERAL_API_KEY = 'active_campaign/general/api_key'; public const ACTIVE_CAMPAIGN_GENERAL_CONNECTION_ID = 'active_campaign/general/connection_id'; + public const ACTIVE_CAMPAIGN_SYNLOG_DEBUG = 'active_campaign/synclog/debug_enabled'; + /** * @var \Magento\Store\Api\StoreRepositoryInterface @@ -135,6 +137,21 @@ public function getStoreLogo( $scopeCode = null): string return $url; } + /** + * Get is debug enabled + * + * @param int|string|null $scopeCode + * + * @return bool + */ + public function isDebugEnabled($scopeCode = null) + { + return $this->scopeConfig->isSetFlag( + self::ACTIVE_CAMPAIGN_SYNLOG_DEBUG, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE, + $scopeCode + ); + } /** * Converts to cents the price amount diff --git a/Core/etc/adminhtml/system.xml b/Core/etc/adminhtml/system.xml index 5feb3e7..a83524b 100644 --- a/Core/etc/adminhtml/system.xml +++ b/Core/etc/adminhtml/system.xml @@ -35,6 +35,14 @@ + + + + /var/log/activecampaign.log + Magento\Config\Model\Config\Source\Enabledisable + + From 6ecef7c0ff2d4ca1ca303ced0d6e28f971e55fbe Mon Sep 17 00:00:00 2001 From: Jorge Venzon Date: Fri, 27 Jan 2023 11:16:18 -0300 Subject: [PATCH 3/5] fixed problem with abandoned carts update --- AbandonedCart/Model/AbandonedCartSendData.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AbandonedCart/Model/AbandonedCartSendData.php b/AbandonedCart/Model/AbandonedCartSendData.php index 945b7f5..9fadef7 100644 --- a/AbandonedCart/Model/AbandonedCartSendData.php +++ b/AbandonedCart/Model/AbandonedCartSendData.php @@ -214,7 +214,7 @@ public function sendAbandonedCartData($quoteId = null): array $abandonedCarts = $this->quoteResourceCollectionFactory->create() ->addFieldToSelect('*') ->addFieldToFilter('ac_synced_date', [ - ['lt' => new \Zend_Db_Expr('updated_at')], + ['lt' => new \Zend_Db_Expr('main_table.updated_at')], ['null' => true] ]) ->addFieldToFilter( @@ -226,7 +226,8 @@ public function sendAbandonedCartData($quoteId = null): array $abandonedCarts->addFieldToFilter('entity_id', ['eq' => $quoteId]); } $abandonedCarts->setPageSize($numberOfAbandonedCart); - + $abandonedCarts->getSelect()->join(array('address' => '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) { $connectionId = $this->coreHelper->getConnectionId($abandonedCart->getStoreId()); From 5fd2d811e79726692ab43093da5c1ee569d9fbe6 Mon Sep 17 00:00:00 2001 From: Jorge Venzon Date: Fri, 27 Jan 2023 11:27:30 -0300 Subject: [PATCH 4/5] fixed problem with abandoned carts update --- AbandonedCart/Model/AbandonedCartSendData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AbandonedCart/Model/AbandonedCartSendData.php b/AbandonedCart/Model/AbandonedCartSendData.php index 9fadef7..5f4d573 100644 --- a/AbandonedCart/Model/AbandonedCartSendData.php +++ b/AbandonedCart/Model/AbandonedCartSendData.php @@ -226,7 +226,7 @@ public function sendAbandonedCartData($quoteId = null): array $abandonedCarts->addFieldToFilter('entity_id', ['eq' => $quoteId]); } $abandonedCarts->setPageSize($numberOfAbandonedCart); - $abandonedCarts->getSelect()->join(array('address' => 'quote_address'),'main_table.entity_id = address.quote_id') + $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) { $connectionId = $this->coreHelper->getConnectionId($abandonedCart->getStoreId()); From 39447130103f9c9bf8c9b9d5caf2f5db69ec7796 Mon Sep 17 00:00:00 2001 From: Jorge Venzon Date: Fri, 27 Jan 2023 11:31:15 -0300 Subject: [PATCH 5/5] fixed problem with abandoned carts update --- AbandonedCart/Model/AbandonedCartSendData.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AbandonedCart/Model/AbandonedCartSendData.php b/AbandonedCart/Model/AbandonedCartSendData.php index 5f4d573..38d49bc 100644 --- a/AbandonedCart/Model/AbandonedCartSendData.php +++ b/AbandonedCart/Model/AbandonedCartSendData.php @@ -214,7 +214,7 @@ public function sendAbandonedCartData($quoteId = null): array $abandonedCarts = $this->quoteResourceCollectionFactory->create() ->addFieldToSelect('*') ->addFieldToFilter('ac_synced_date', [ - ['lt' => new \Zend_Db_Expr('main_table.updated_at')], + ['lt' => new \Zend_Db_Expr('updated_at')], ['null' => true] ]) ->addFieldToFilter(