diff --git a/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php b/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php index c123d9e8..40c474ee 100755 --- a/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php +++ b/Block/Adminhtml/System/Config/Form/Field/MailchimpMap.php @@ -79,7 +79,7 @@ protected function _getMailchimpTags() $ret[$item['tag']] = $item['tag'] . ' (' . $item['name'] . ' : ' . $item['type'] . ')'; } } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } return $ret; diff --git a/Controller/Adminhtml/Ecommerce/CreateWebhook.php b/Controller/Adminhtml/Ecommerce/CreateWebhook.php index db029081..39575d20 100644 --- a/Controller/Adminhtml/Ecommerce/CreateWebhook.php +++ b/Controller/Adminhtml/Ecommerce/CreateWebhook.php @@ -47,7 +47,7 @@ public function __construct( \Ebizmarts\MailChimp\Helper\Data $helper, \Magento\Config\Model\ResourceModel\Config $config ) { - + parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->helper = $helper; @@ -74,11 +74,12 @@ public function execute() $message = $return['message']; } $resultJson = $this->resultJsonFactory->create(); - - return $resultJson->setData([ + $ret = [ 'valid' => (int)$valid, 'message' => $message, - ]); + ]; + $this->helper->buttonPressed("CreateWebhook", $ret); + return $resultJson->setData($ret); } protected function _isAllowed() { diff --git a/Controller/Adminhtml/Ecommerce/DeleteStore.php b/Controller/Adminhtml/Ecommerce/DeleteStore.php index dcea11be..4fa89ccf 100644 --- a/Controller/Adminhtml/Ecommerce/DeleteStore.php +++ b/Controller/Adminhtml/Ecommerce/DeleteStore.php @@ -51,7 +51,7 @@ public function __construct( \Ebizmarts\MailChimp\Helper\Data $helper, \Magento\Config\Model\ResourceModel\Config $config ) { - + parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->helper = $helper; @@ -89,10 +89,12 @@ public function execute() $valid = 0; $message = $e->getMessage(); } - return $resultJson->setData([ + $ret = [ 'valid' => (int)$valid, 'message' => $message, - ]); + ]; + $this->helper->buttonPressed("DeleteStore",$ret); + return $resultJson->setData($ret); } protected function _isAllowed() { diff --git a/Controller/Adminhtml/Ecommerce/FixMailchimpJS.php b/Controller/Adminhtml/Ecommerce/FixMailchimpJS.php index 70646e4c..5fc3fc9d 100644 --- a/Controller/Adminhtml/Ecommerce/FixMailchimpJS.php +++ b/Controller/Adminhtml/Ecommerce/FixMailchimpJS.php @@ -48,7 +48,7 @@ public function __construct( \Magento\Framework\App\Cache\TypeListInterface $typeList, \Ebizmarts\MailChimp\Helper\Data $helper ) { - + parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->helper = $helper; @@ -76,11 +76,12 @@ public function execute() $valid = 0; $message = $e->getMessage(); } - - return $resultJson->setData([ + $ret = [ 'valid' => (int)$valid, 'message' => $message, - ]); + ]; + $this->helper->buttonPressed("FixMailchimpJS", $ret); + return $resultJson->setData($ret); } protected function _isAllowed() { diff --git a/Controller/Adminhtml/Ecommerce/GetInterest.php b/Controller/Adminhtml/Ecommerce/GetInterest.php index 7850f5e8..5e2c3b96 100644 --- a/Controller/Adminhtml/Ecommerce/GetInterest.php +++ b/Controller/Adminhtml/Ecommerce/GetInterest.php @@ -73,7 +73,7 @@ public function execute() if (is_array($result['categories']) && count($result['categories'])) { $rc = $result['categories']; } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); $error = 1; } diff --git a/Controller/Adminhtml/Ecommerce/Getaccountdetails.php b/Controller/Adminhtml/Ecommerce/Getaccountdetails.php index b75b451e..73fc66e2 100644 --- a/Controller/Adminhtml/Ecommerce/Getaccountdetails.php +++ b/Controller/Adminhtml/Ecommerce/Getaccountdetails.php @@ -86,7 +86,7 @@ public function execute() $options['nostore'] = ['label' => __('Ecommerce disabled, only subscribers will be synchronized (your orders, products,etc will be not synchronized)'), 'value' => '']; } } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); $options['error'] = ['label' => 'Error', 'value' => __('--- Invalid API Key ---')]; } diff --git a/Controller/Adminhtml/Ecommerce/ResetLocalErrors.php b/Controller/Adminhtml/Ecommerce/ResetLocalErrors.php index bcd00905..c134a8b7 100644 --- a/Controller/Adminhtml/Ecommerce/ResetLocalErrors.php +++ b/Controller/Adminhtml/Ecommerce/ResetLocalErrors.php @@ -93,10 +93,12 @@ public function execute() $valid = 0; $message = $e->getMessage(); } - return $resultJson->setData([ + $ret = [ 'valid' => (int)$valid, 'message' => $message, - ]); + ]; + $this->helper->buttonPressed("ResetLocalErrors",$ret); + return $resultJson->setData($ret); } protected function _isAllowed() { diff --git a/Controller/Adminhtml/Ecommerce/ResetLocalErrorsNoRetry.php b/Controller/Adminhtml/Ecommerce/ResetLocalErrorsNoRetry.php index 838cd4ec..b96e4ddd 100644 --- a/Controller/Adminhtml/Ecommerce/ResetLocalErrorsNoRetry.php +++ b/Controller/Adminhtml/Ecommerce/ResetLocalErrorsNoRetry.php @@ -93,10 +93,12 @@ public function execute() $valid = 0; $message = $e->getMessage(); } - return $resultJson->setData([ + $ret = [ 'valid' => (int)$valid, 'message' => $message, - ]); + ]; + $this->helper->buttonPressed("ResetLocalErrorNoRetry",$ret); + return $resultJson->setData($ret); } protected function _isAllowed() { diff --git a/Controller/Adminhtml/Ecommerce/ResetStore.php b/Controller/Adminhtml/Ecommerce/ResetStore.php index 2a45252d..1a2ff3bf 100644 --- a/Controller/Adminhtml/Ecommerce/ResetStore.php +++ b/Controller/Adminhtml/Ecommerce/ResetStore.php @@ -45,7 +45,7 @@ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManagerInterface, \Ebizmarts\MailChimp\Helper\Data $helper ) { - + parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->helper = $helper; @@ -82,10 +82,12 @@ public function execute() $valid = 0; $message = $e->getMessage(); } - return $resultJson->setData([ + $ret = [ 'valid' => (int)$valid, 'message' => $message, - ]); + ]; + $this->helper->buttonPressed("ResetStore",$ret); + return $resultJson->setData($ret); } protected function _isAllowed() { diff --git a/Controller/Adminhtml/Ecommerce/ResyncProducts.php b/Controller/Adminhtml/Ecommerce/ResyncProducts.php index d68d83f2..cd53b66f 100644 --- a/Controller/Adminhtml/Ecommerce/ResyncProducts.php +++ b/Controller/Adminhtml/Ecommerce/ResyncProducts.php @@ -32,23 +32,30 @@ class ResyncProducts extends \Magento\Backend\App\Action * @var SyncHelper */ private $syncHelper; + /** + * @var \Ebizmarts\MailChimp\Helper\Data + */ + private $helper; /** * @param \Magento\Backend\App\Action\Context $context * @param JsonFactory $resultJsonFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManagerInterface * @param SyncHelper $syncHelper + * @param \Ebizmarts\MailChimp\Helper\Data $helper */ public function __construct( \Magento\Backend\App\Action\Context $context, JsonFactory $resultJsonFactory, \Magento\Store\Model\StoreManagerInterface $storeManagerInterface, - SyncHelper $syncHelper + SyncHelper $syncHelper, + \Ebizmarts\MailChimp\Helper\Data $helper ) { parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->storeManager = $storeManagerInterface; $this->syncHelper = $syncHelper; + $this->helper = $helper; } public function execute() @@ -64,10 +71,12 @@ public function execute() $valid = 0; $message = $e->getMessage(); } - return $resultJson->setData([ + $ret = [ 'valid' => (int)$valid, 'message' => $message, - ]); + ]; + $this->helper->buttonPressed("ResyncProducts", $ret); + return $resultJson->setData($ret); } protected function _isAllowed() { diff --git a/Controller/Adminhtml/Ecommerce/ResyncSubscribers.php b/Controller/Adminhtml/Ecommerce/ResyncSubscribers.php index 9e5a43da..6eaa40ab 100644 --- a/Controller/Adminhtml/Ecommerce/ResyncSubscribers.php +++ b/Controller/Adminhtml/Ecommerce/ResyncSubscribers.php @@ -32,24 +32,31 @@ class ResyncSubscribers extends \Magento\Backend\App\Action * @var SyncHelper */ private $syncHelper; + /** + * @var \Ebizmarts\MailChimp\Helper\Data + */ + private $helper; /** * @param \Magento\Backend\App\Action\Context $context * @param JsonFactory $resultJsonFactory * @param \Magento\Store\Model\StoreManagerInterface $storeManagerInterface * @param SyncHelper $syncHelper + * @param \Ebizmarts\MailChimp\Helper\Data $helper */ public function __construct( \Magento\Backend\App\Action\Context $context, JsonFactory $resultJsonFactory, \Magento\Store\Model\StoreManagerInterface $storeManagerInterface, - SyncHelper $syncHelper + SyncHelper $syncHelper, + \Ebizmarts\MailChimp\Helper\Data $helper ) { parent::__construct($context); $this->resultJsonFactory = $resultJsonFactory; $this->storeManager = $storeManagerInterface; $this->syncHelper = $syncHelper; + $this->helper = $helper; } public function execute() @@ -65,10 +72,12 @@ public function execute() $valid = 0; $message = $e->getMessage(); } - return $resultJson->setData([ + $ret = [ 'valid' => (int)$valid, 'message' => $message, - ]); + ]; + $this->helper->buttonPressed("ResyncSubscribers", $ret); + return $resultJson->setData($ret); } protected function _isAllowed() { diff --git a/Controller/Adminhtml/Lists/Get.php b/Controller/Adminhtml/Lists/Get.php index 8d2f73a6..8cbc7c4a 100644 --- a/Controller/Adminhtml/Lists/Get.php +++ b/Controller/Adminhtml/Lists/Get.php @@ -44,7 +44,7 @@ public function __construct( \Ebizmarts\MailChimp\Helper\Data $helper, \Magento\Framework\Encryption\Encryptor $encryptor ) { - + parent::__construct($context); $this->_resultFactory = $context->getResultFactory(); $this->_helper = $helper; @@ -62,7 +62,7 @@ public function execute() $result['lists'][] = ['id' => $list['id'], 'name' => $list['name']]; } $result['valid'] = 1; - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $result['valid'] = 0; $result['errormsg'] = $e->getTitle(); $this->_helper->log($e->getFriendlyMessage()); diff --git a/Controller/Adminhtml/Stores/Delete.php b/Controller/Adminhtml/Stores/Delete.php index b325b3e1..ec470d21 100644 --- a/Controller/Adminhtml/Stores/Delete.php +++ b/Controller/Adminhtml/Stores/Delete.php @@ -27,7 +27,7 @@ public function execute() $api->ecommerce->stores->delete($storeModel->getStoreid()); $this->messageManager->addSuccess(__('You deleted the store.')); return $resultRedirect->setPath('mailchimp/stores'); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->messageManager->addError(__('Store could not be deleted.'.$e->getMessage())); $this->_mhelper->log($e->getFriendlyMessage()); return $resultRedirect->setPath('mailchimp/stores/edit', ['id'=>$storeId]); diff --git a/Controller/Adminhtml/Stores/Get.php b/Controller/Adminhtml/Stores/Get.php index 3716546a..e3efa417 100644 --- a/Controller/Adminhtml/Stores/Get.php +++ b/Controller/Adminhtml/Stores/Get.php @@ -69,7 +69,7 @@ public function execute() $result['valid'] = 1; } } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_mhelper->log($e->getFriendlyMessage()); $result['valid'] = 0; $result['errormsg'] = $e->getTitle(); diff --git a/Controller/Adminhtml/Stores/Save.php b/Controller/Adminhtml/Stores/Save.php index 5e67c32c..19cbc803 100644 --- a/Controller/Adminhtml/Stores/Save.php +++ b/Controller/Adminhtml/Stores/Save.php @@ -40,7 +40,7 @@ public function execute() } else { return $resultRedirect->setPath('mailchimp/stores'); } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->messageManager->addErrorMessage(__('Store could not be saved.'.$e->getMessage())); $this->_mhelper->log($e->getFriendlyMessage()); return $resultRedirect->setPath('mailchimp/stores/edit', ['id'=>$storeId]); diff --git a/Cron/Ecommerce.php b/Cron/Ecommerce.php index 7a3b096c..d45fb120 100644 --- a/Cron/Ecommerce.php +++ b/Cron/Ecommerce.php @@ -282,7 +282,7 @@ protected function _processStore($storeId, $mailchimpStoreId, $listId) $this->markWithError($BadOperations, $mailchimpStoreId, $listId); } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } catch (\Exception $e) { $this->_helper->log($e->getMessage()); @@ -340,7 +340,7 @@ protected function apiUpdateSyncFlag($storeId, $mailchimpStoreId) null, false ); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log('MailChimp error when updating syncing flag for store ' . $storeId); $this->_helper->log($e->getFriendlyMessage()); } @@ -350,7 +350,7 @@ protected function _ping($storeId) try { $api = $this->_helper->getApi($storeId); $api->root->info(); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); return false; } diff --git a/Cron/GenerateStatistics.php b/Cron/GenerateStatistics.php new file mode 100644 index 00000000..e0d6abb8 --- /dev/null +++ b/Cron/GenerateStatistics.php @@ -0,0 +1,296 @@ + 'Unsubscribe', + 1 => 'Delete', + ]; + public function __construct( + Data $helper, + StoreManager $storeManager, + CustomerCollectionFactory $customerCollectionFactory, + ProductCollectionFactory $productCollectionFactory, + OrderCollectionFactory $orderCollectionFactory, + MailchimpSyncBatchesCollectionFactory $mailchimpSyncBatchesCollectionFactory, + ScheduleCollectionFactory $scheduleCollectionFactory, + ProductMetadataInterface $productMetadata, + ModuleVersion $moduleVersion, + TimezoneInterface $locale + ) + { + $this->helper = $helper; + $this->storeManager = $storeManager; + $this->customerCollectionFactory = $customerCollectionFactory; + $this->productCollectionFactory = $productCollectionFactory; + $this->orderCollectionFactory = $orderCollectionFactory; + $this->mailChimpSyncBatchesCollectionFactory = $mailchimpSyncBatchesCollectionFactory; + $this->scheduleCollectionFactory = $scheduleCollectionFactory; + $this->productMetadata = $productMetadata; + $this->moduleVersion = $moduleVersion; + $this->locale = $locale; + } + public function execute() + { + $data = []; + $data['storeURL'] = $this->storeManager->getStore()->getBaseUrl(); + $data['time'] = $this->helper->getGmtDate(); + foreach ($this->storeManager->getStores() as $storeId => $val) + { + if ($this->helper->isMailChimpEnabled($storeId)) { + $mailChimpStoreId = $this->helper->getConfigValue(Data::XML_MAILCHIMP_STORE, $storeId); + $storeStatistics = []; + // Get currents mailchimp totals (orders, products, customers) + $storeStatistics['mailchimp'] = $this->getMailchimpTotals($storeId); + $storeStatistics['magento'] = $this->getMagentoTotals($storeId); + $data['statistics']['store'][$storeId] = $storeStatistics; + $data['batches']['store'][$storeId] = $this->getBatches($storeId, $mailChimpStoreId); + } + } + $data['jobs'] = $this->getJobs(); + if (!empty($data)) { + $this->helper->saveNotification($data); + } + } + private function getMagentoTotals($storeId) + { + $options = []; + $customerCollection = $this->customerCollectionFactory->create(); + $customerCollection->addFieldToFilter('store_id', ['eq'=>$storeId]); + $customerCollection->getSelect()->reset(\Magento\Framework\DB\Select::COLUMNS)->columns(['entity_id','store_id']); + $totalCustomers = $customerCollection->count(); + $options['total_customers'] = $totalCustomers; + + $productCollection = $this->productCollectionFactory->create(); + $productCollection->addStoreFilter($storeId); + $productCollection->getSelect()->reset(\Magento\Framework\DB\Select::COLUMNS)->columns(['entity_id']); + $totalProducts = $productCollection->count(); + $options['total_products'] = $totalProducts; + + $orderCollection = $this->orderCollectionFactory->create(); + $orderCollection->addFieldToFilter('store_id', ['eq' => $storeId]); + $orderCollection->getSelect()->reset(\Magento\Framework\DB\Select::COLUMNS)->columns(['entity_id']); + $totalOrders = $orderCollection->count(); + $options['total_orders'] = $totalOrders; + $storeUrl = stripslashes($this->storeManager->getStore($storeId)->getUrl()); + $options['store_url'] = stripslashes($storeUrl); + // get all de configuration + $config = []; + $config['general']['active'] = $this->helper->getConfigValue(Data::XML_PATH_ACTIVE, $storeId); + $config['general']['store'] = $this->helper->getConfigValue(Data::XML_MAILCHIMP_STORE, $storeId); + $config['general']['list'] = $this->helper->getConfigValue(Data::XML_PATH_LIST, $storeId); + $config['general']['popup_form'] = $this->helper->getConfigValue(Data::XML_POPUP_FORM, $storeId); + if ($config['general']['popup_form']) { + $config['general']['popup_url'] = $this->helper->getConfigValue(Data::XML_POPUP_URL, $storeId); + } + $config['general']['magento_email'] = $this->helper->getConfigValue(Data::XML_MAGENTO_MAIL, $storeId); + $config['general']['two-way_sync'] = $this->helper->getConfigValue(Data::XML_PATH_WEBHOOK_ACTIVE, $storeId); + if ( $config['general']['two-way_sync']) { + $config['general']['delete_action'] = $this->deleteAction[$this->helper->getConfigValue(Data::XML_PATH_WEBHOOK_DELETE)]; + } + $config['general']['enable_log'] = $this->helper->getConfigValue(Data::XML_PATH_LOG,$storeId); +// $config['general']['field_mapping'] = $this->helper->getConfigValue(Data::XML_MERGEVARS, $storeId); + $config['general']['mapping'] = $this->helper->getMapFields($storeId, false); + $config['general']['interest'] = $this->helper->getConfigValue(Data::XML_INTEREST, $storeId); + $config['general']['show_groups'] = $this->helper->getConfigValue(Data::XML_INTEREST_IN_SUCCESS); + if ($config['general']['show_groups']) { + $config['general']['group_description'] = $this->helper->getConfigValue(Data::XML_INTEREST_SUCCESS_HTML_BEFORE, $storeId); + $config['general']['succes_message'] = $this->helper->getConfigValue(Data::XML_INTEREST_SUCCESS_HTML_AFTER, $storeId); + } + $config['general']['timeout'] = $this->helper->getConfigValue(Data::XML_PATH_TIMEOUT, $storeId); + $config['ecommerce']['enabled'] = $this->helper->getConfigValue(Data::XML_PATH_ECOMMERCE_ACTIVE, $storeId); + $config['ecommerce']['sync_all_customers'] = $this->helper->getConfigValue(Data::XML_PATH_ALL_CUSTOMERS, $storeId); + $config['ecommerce']['subscribe_all_customers'] = $this->helper->getConfigValue(Data::XML_ECOMMERCE_OPTIN, $storeId); + $config['ecommerce']['first_date'] = $this->helper->getConfigValue(Data::XML_ECOMMERCE_FIRSTDATE, $storeId); + $config['ecommerce']['send_promo'] = $this->helper->getConfigValue(Data::XML_SEND_PROMO, $storeId); + $config['ecommerce']['include_taxes'] = $this->helper->getConfigValue(Data::XML_INCLUDING_TAXES, $storeId); + $config['ecommerce']['campaign_attribution'] = $this->helper->getConfigValue(Data::XML_CAMPAIGN_ACTION, $storeId); + $config['ecommerce']['monts_to_clear_error_table'] = $this->helper->getConfigValue(Data::XML_CLEAN_ERROR_MONTHS, $storeId); + $config['ac']['enabled'] = $this->helper->getConfigValue(Data::XML_ABANDONEDCART_ACTIVE, $storeId); + $config['ac']['first_date'] = $this->helper->getConfigValue(Data::XML_ABANDONEDCART_FIRSTDATE, $storeId); + $config['ac']['redirect_page'] = $this->helper->getConfigValue(Data::XML_ABANDONEDCART_PAGE, $storeId); + $config['ac']['save_email'] = $this->helper->getConfigValue(Data::XML_ABANDONEDCART_EMAIL, $storeId); + $options['config'] = $config; + $options['magento_version'] = $this->productMetadata->getVersion(); + $options['mc2-version'] = $this->moduleVersion->getModuleVersion('Ebizmarts_MailChimp'); + try { + $options['lib-version'] = $this->moduleVersion->getLibVersion('ebizmarts/mailchimp-lib'); + } catch (\Exception $e) { + $this->helper->log($e->getMessage()); + } + $options['time_zone'] = $this->locale->getConfigTimezone(\Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId); + return $options; + } + private function getMailchimpTotals($storeId) + { + $mailchimpList = $this->helper->getGeneralList($storeId); + $mailChimpStoreId = $this->helper->getConfigValue(Data::XML_MAILCHIMP_STORE, $storeId); + $api = $this->helper->getApi($storeId); + $apiInfo = $api->root->info(); + $options = []; + $options ['store'] = $mailChimpStoreId; + if (isset($apiInfo['account_name'])) { + $options['webhooks'] = $this->getWebhooks($api, $mailchimpList); + $options['username'] =$apiInfo['account_name']; + $options['total_subscribers'] = $apiInfo['total_subscribers']; + if ($storeId != -1) { + $storeData = $api->ecommerce->stores->get($mailChimpStoreId); + $options['list_id'] = $storeData['list_id']; + $list = $api->lists->getLists($storeData['list_id']); + $options['list_name'] = $list['name']; + $options['total_list_subscribers'] = $list['stats']['member_count']; + $totalCustomers = $api->ecommerce->customers->getAll($mailChimpStoreId, 'total_items'); + $options['total_customers'] = $totalCustomers['total_items']; + $totalProducts = $api->ecommerce->products->getAll($mailChimpStoreId, 'total_items'); + $options['total_products'] = $totalProducts['total_items']; + $totalOrders = $api->ecommerce->orders->getAll($mailChimpStoreId, 'total_items'); + $options['total_orders'] = $totalOrders['total_items']; + $totalCarts = $api->ecommerce->carts->getAll($mailChimpStoreId, 'total_items'); + $options['total_carts'] = $totalCarts['total_items']; + $options['currency_code'] = $storeData['currency_code']; + $options['money_format'] = $storeData['money_format']; + $options['primary_locale'] = $storeData['primary_locale']; + $options['timezone'] = $storeData['timezone']; + $options['is_syncing'] = $storeData['is_syncing']; + $contact = []; + $contact['email_address'] = $storeData['email_address']; + $contact['phone_number'] = $storeData['phone']; + $contact['address'] = $storeData['address']; + $options['contact'] = $contact; + } else { + $options['nostore'] = ['label' => __('Ecommerce disabled, only subscribers will be synchronized (your orders, products,etc will be not synchronized)'), 'value' => '']; + } + } + return $options; + } + private function getWebhooks($api, $listId) + { + $ret = []; + $webhooks = $api->lists->webhooks->getAll($listId); + foreach ($webhooks['webhooks'] as $webhook) { + $item =[]; + $item['url'] = $webhook['url']; + $item['events'] = $webhook['events']; + $item['sources'] = $webhook['sources']; + $ret[] = $item; + } + return $ret; + } + private function getBatches($storeId,$mailchimpStoreId) + { + $batches = []; + $collection = $this->mailChimpSyncBatchesCollectionFactory->create(); + $collection + ->addFieldToFilter('store_id', ['eq' => $storeId]) + ->addFieldToFilter('mailchimp_store_id', ['eq' => $mailchimpStoreId]); + $collection->setOrder('modified_date', 'DESC'); + $collection->getSelect()->limit(10); + foreach ($collection as $item) { + $batch = []; + $batch['id'] = $item['batch_id']; + $batch['mailchimp_store_id'] = $item['mailchimp_store_id']; + $batch['date'] = $item['modified_date']; + $batch['status'] = $item['status']; + $counters = []; + $counters['carts_new'] = $item['carts_new_count']; + $counters['order_new'] = $item['orders_new_count']; + $counters['products_new'] = $item['products_new_count']; + $counters['customers_new'] = $item['customers_new_count']; + $counters['subscribers_new'] = $item['subscribers_new_count']; + $counters['carts_modified'] = $item['carts_modified_count']; + $counters['customers_modified'] = $item['customers_modified_count']; + $counters['orders_modified'] = $item['orders_modified_count']; + $counters['products_modified'] = $item['products_modified_count']; + $counters['subscribers_modified'] = $item['subscribers_modified_count']; + $batch['counters'] = $counters; + $batches[] = $batch; + } + return $batches; + } + private function getJobs() + { + $jobs = []; + $collection = $this->scheduleCollectionFactory->create(); + $collection->addFieldToFilter('job_code', ['eq'=> 'ebizmarts_ecommerce']); + $collection->setOrder('scheduled_at', 'DESC'); + $collection->getSelect()->limit(10); + foreach ($collection as $item) { + $job =[]; + $job['job_code'] = $item['job_code']; + $job['status'] = $item['status']; + $job['messages'] = $item['messages']; + $job['scheduled_at'] = $item['scheduled_at']; + $job['executed_at'] = $item['executed_at']; + $job['finished_at'] = $item['finished_at']; + $jobs[] = $job; + } + $collection = $this->scheduleCollectionFactory->create(); + $collection->addFieldToFilter('job_code', ['eq'=> 'ebizmarts_webhooks']); + $collection->setOrder('scheduled_at', 'DESC'); + $collection->getSelect()->limit(10); + foreach ($collection as $item) { + $job =[]; + $job['job_code'] = $item['job_code']; + $job['status'] = $item['status']; + $job['messages'] = $item['messages']; + $job['scheduled_at'] = $item['scheduled_at']; + $job['executed_at'] = $item['executed_at']; + $job['finished_at'] = $item['finished_at']; + $jobs[] = $job; + } + return $jobs; + } +} diff --git a/Cron/SyncStatistics.php b/Cron/SyncStatistics.php new file mode 100644 index 00000000..a89c69d0 --- /dev/null +++ b/Cron/SyncStatistics.php @@ -0,0 +1,77 @@ +helper = $helper; + $this->mailchimpNotificationCollectionFactory = $mailchimpNotificationCollectionFactory; + $this->mailchimpNotification = $mailchimpNotification; + } + public function execute() + { + $this->helper->log("Sync statistics started"); + if ($this->helper->isSupportEnabled()) + { + $collection = $this->getCollection(); + /** + * @var $collectionItem \Ebizmarts\MailChimp\Model\MailChimpNotification + */ + foreach ($collection as $collectionItem) + { + $this->syncData($collectionItem->getNotificationData()); + $collectionItem->setProcessed(true); + $collectionItem->setSyncedAt($this->helper->getGmtDate()); + $collectionItem->getResource()->save($collectionItem); + } + } else { + $this->helper->log("Support is off"); + } + $this->cleanData(); + $this->helper->log("Sync statistics finished"); + } + private function getCollection() + { + $collection = $this->mailchimpNotificationCollectionFactory->create(); + $collection->addFieldToFilter('processed', 0); + $collection->setOrder('generated_at', 'ASC'); + + return $collection; + } + private function syncData($data) + { + $this->helper->log($data); + } + private function cleanData() + { + try { + $connection = $this->mailchimpNotification->getConnection(); + $tableName = $this->mailchimpNotification->getMainTable(); + $connection->delete($tableName, ['date_add(generated_at , interval 1 week) <= NOW()']); + $connection->delete($tableName, ['processed' => 1]); + } catch (\Exception $e) { + $this->helper->log($e->getMessage()); + } + } +} diff --git a/Cron/Webhook.php b/Cron/Webhook.php index d2fe8123..0b5432df 100644 --- a/Cron/Webhook.php +++ b/Cron/Webhook.php @@ -258,7 +258,7 @@ protected function _profile($data) $this->_subscribeMember($subscriber, \Magento\Newsletter\Model\Subscriber::STATUS_UNSUBSCRIBED); } } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } } diff --git a/Helper/Data.php b/Helper/Data.php index 01358eef..e8af1e5b 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -15,6 +15,7 @@ use Magento\Framework\Exception\ValidatorException; use Magento\Store\Model\Store; use Symfony\Component\Config\Definition\Exception\Exception; +use Ebizmarts\MailChimp\Model\MailchimpNotificationFactory as MailchimpNotificationFactory; class Data extends \Magento\Framework\App\Helper\AbstractHelper { @@ -54,6 +55,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper const XML_POPUP_FORM = 'mailchimp/general/popup_form'; const XML_POPUP_URL = 'mailchimp/general/popup_url'; const XML_CLEAN_ERROR_MONTHS = 'mailchimp/ecommerce/clean_errors_months'; + const XML_ENABLE_SUPPORT = 'mailchimp/general/enable_support'; const ORDER_STATE_OK = 'complete'; @@ -193,6 +195,11 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper /** * @var \Magento\Framework\Locale\Resolver */ + /** + * @var MailchimpNotificationFactory + */ + protected $mailchimpNotificationFactory; + protected $resolver; private $customerAtt = null; private $addressAtt = null; @@ -222,6 +229,7 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper * @param \Magento\Framework\Stdlib\DateTime\DateTime $date * @param \Magento\Directory\Model\CountryFactory $countryFactory * @param \Magento\Framework\Locale\Resolver $resolver + * @param MailchimpNotificationFactory $mailchimpNotificationFactory */ public function __construct( \Magento\Framework\App\Helper\Context $context, @@ -246,7 +254,8 @@ public function __construct( \Magento\Framework\App\DeploymentConfig $deploymentConfig, \Magento\Framework\Stdlib\DateTime\DateTime $date, \Magento\Directory\Model\CountryFactory $countryFactory, - \Magento\Framework\Locale\Resolver $resolver + \Magento\Framework\Locale\Resolver $resolver, + MailchimpNotificationFactory $mailchimpNotificationFactory ) { $this->_storeManager = $storeManager; @@ -273,6 +282,7 @@ public function __construct( $this->_date = $date; $this->countryFactory = $countryFactory; $this->resolver = $resolver; + $this->mailchimpNotificationFactory = $mailchimpNotificationFactory; parent::__construct($context); } @@ -284,6 +294,10 @@ public function isMailChimpEnabled($store = null) { return $this->getConfigValue(self::XML_PATH_ACTIVE, $store); } + public function isSupportEnabled() + { + return $this->getConfigValue(self::XML_ENABLE_SUPPORT); + } /** * @param null $store @@ -316,6 +330,8 @@ public function getApi($store = null, $scope = null) $apiKey = $this->getApiKey($store, $scope); $timeOut = $this->getTimeOut($store,$scope); $this->_api->setApiKey($apiKey); + $this->_api->setHelper($this); + $this->_api->setStoreURL($this->_storeManager->getStore($store)->getBaseUrl()); $this->_api->setUserAgent('Mailchimp4Magento' . (string)$this->getModuleVersion()); if ($timeOut) { $this->_api->setTimeOut($timeOut); @@ -404,7 +420,7 @@ public function resetMapFields() { $this->_mapFields = null; } - public function getMapFields($storeId = null) + public function getMapFields($storeId = null, $options=true) { if (!$this->_mapFields) { $customerAtt = $this->getBindableAttributes(); @@ -418,7 +434,7 @@ public function getMapFields($storeId = null) 'customer_field' => $customerAtt[$customerFieldId]['attCode'], 'isDate' => $customerAtt[$customerFieldId]['isDate'], 'isAddress' => $customerAtt[$customerFieldId]['isAddress'], - 'options' => $customerAtt[$customerFieldId]['options'] + 'options' => $options ? $customerAtt[$customerFieldId]['options'] : false ]; } } @@ -446,7 +462,11 @@ public function getApiByApiKey($apiKey, $encrypted = false) } else { $this->_api->setApiKey($apiKey); } + $this->_api->setUserAgent('Mailchimp4Magento' . (string)$this->getModuleVersion()); + $this->_api->setHelper($this); + $this->_api->setStoreURL($this->_storeManager->getStore()->getBaseUrl()); + return $this->_api; } @@ -548,7 +568,14 @@ public function log($message, $store = null, $file = null) $this->_mlogger->mailchimpLog($message, $file); } } + public function saveNotification($data) + { + $mailchimpNotification = $this->mailchimpNotificationFactory->create(); + $mailchimpNotification->setNotificationData(json_encode($data)); + $mailchimpNotification->setProcessed(false); + $mailchimpNotification->getResource()->save($mailchimpNotification); + } /** * @return string * @throws \Magento\Framework\Exception\LocalizedException @@ -568,7 +595,7 @@ public function deleteStore($mailchimpStore) // $storeId = $this->getConfigValue(self::XML_MAILCHIMP_STORE); $this->getApi()->ecommerce->stores->delete($mailchimpStore); $this->cancelAllPendingBatches($mailchimpStore); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->log($e->getFriendlyMessage()); } catch (Exception $e) { $this->log($e->getMessage()); @@ -769,7 +796,7 @@ public function getListForMailChimpStore($mailchimpStoreId, $apiKey) if (isset($store['list_id'])) { return $store['list_id']; } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->log($e->getFriendlyMessage()); } return null; @@ -799,14 +826,13 @@ public function loadStores() } $this->_api->setApiKey(trim($apiKey)); $this->_api->setUserAgent('Mailchimp4Magento' . (string)$this->getModuleVersion()); + $this->_api->setHelper($this); + try { $apiStores = $this->_api->ecommerce->stores->get(null, null, null, self::MAXSTORES); - } catch (\Mailchimp_Error $mailchimpError) { - $this->log($mailchimpError->getFriendlyMessage()); - continue; - } catch (\Mailchimp_HttpError $mailchimpError) { - $this->log($mailchimpError->getMessage()); + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { + $this->log($e->getFriendlyMessage()); continue; } @@ -852,7 +878,7 @@ public function loadStores() $mstore->setMcAccountName($mcUserName[$apiKey]); $mstore->getResource()->save($mstore); } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->log($e->getFriendlyMessage()); } } @@ -876,7 +902,7 @@ public function saveJsUrl($storeId, $scope = null, $mailChimpStoreId = null) $storeId ); } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->log($e->getFriendlyMessage()); } } @@ -899,7 +925,7 @@ public function getJsUrl($storeId) $storeId ); } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->log($e->getFriendlyMessage()); } } @@ -939,7 +965,7 @@ public function createWebHook($apikey, $listId, $scope=null, $scopeId=null) '_secure' => true]); // the urlencode of the hookUrl not work $ret = $api->lists->webhooks->add($listId, $hookUrl, $events, $sources); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->log($e->getFriendlyMessage()); $ret ['message']= $e->getMessage(); } @@ -963,7 +989,7 @@ public function deleteWebHook($apikey, $listId) } } } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->log($e->getFriendlyMessage()); } } @@ -1070,7 +1096,7 @@ public function getInterest($storeId) $this->log(__('Error retrieving interest groups for store ').$storeId); $rc = []; } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->log($e->getFriendlyMessage()); } return $rc; @@ -1114,7 +1140,9 @@ public function getSubscriberInterest($subscriberId, $storeId, $interest = null) } } } - } catch (\Exception $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { + $this->log($e->getFriendlyMessage()); + } catch (Exception $e) { $this->log($e->getMessage()); } } @@ -1208,4 +1236,14 @@ public function encrypt($value) { return $this->_encryptor->encrypt($value); } + public function buttonPressed($button, $result) + { + $data = []; + $data['storeURL'] = $this->_storeManager->getStore()->getBaseUrl(); + $data['time'] = $this->getGmtDate(); + $data['button']['action'] = $button; + $data['button']['result'] = $result; + $this->saveNotification($data); + + } } diff --git a/Model/Api/PromoRules.php b/Model/Api/PromoRules.php index 72ebf0e6..e0b2e5af 100644 --- a/Model/Api/PromoRules.php +++ b/Model/Api/PromoRules.php @@ -121,7 +121,7 @@ protected function _getDeletedPromoRules($mailchimpStoreId, $magentoStoreId) $batchArray[$count]['path'] = "/ecommerce/stores/$mailchimpStoreId/promo-rules/$ruleId"; $batchArray[$count]['operation_id'] = $this->_batchId . '_' . $ruleId; $count++; - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } $this->syncHelper->ecommerceDeleteAllByIdType( diff --git a/Model/Api/Result.php b/Model/Api/Result.php index 77f92d61..299826b1 100644 --- a/Model/Api/Result.php +++ b/Model/Api/Result.php @@ -176,7 +176,7 @@ public function getBatchResponse($batchId, $storeId = null) self::MAILCHIMP_TEMP_DIR . DIRECTORY_SEPARATOR . $batchId . '/' . $batchId . '.tar'); $this->_driver->deleteFile($fileName . '.tar.gz'); } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); return false; } catch (\Exception $e) { diff --git a/Model/Api/Subscriber.php b/Model/Api/Subscriber.php index 530335fd..aed30fcb 100644 --- a/Model/Api/Subscriber.php +++ b/Model/Api/Subscriber.php @@ -186,7 +186,7 @@ public function deleteSubscriber(\Magento\Newsletter\Model\Subscriber $subscribe try { $md5HashEmail = hash('md5', strtolower($subscriber->getSubscriberEmail())); $api->lists->members->update($listId, $md5HashEmail, null, 'cleaned'); - } catch (\MailChimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage(), $storeId); $this->_message->addErrorMessage($e->getMessage()); } catch (\Exception $e) { diff --git a/Model/Config/Backend/MonkeyStore.php b/Model/Config/Backend/MonkeyStore.php index a185729f..a2bd8368 100644 --- a/Model/Config/Backend/MonkeyStore.php +++ b/Model/Config/Backend/MonkeyStore.php @@ -155,7 +155,7 @@ private function getStore($apiKey, $store) $api = $this->_helper->getApiByApiKey($apiKey); $store = $api->ecommerce->stores->get($store); return $store['list_id']; - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } return null; diff --git a/Model/Config/ModuleVersion.php b/Model/Config/ModuleVersion.php index cf8a129a..c1c537ec 100644 --- a/Model/Config/ModuleVersion.php +++ b/Model/Config/ModuleVersion.php @@ -15,7 +15,7 @@ use Magento\Framework\Component\ComponentRegistrarInterface; use Magento\Framework\Exception\FileSystemException; use Magento\Framework\Filesystem\Directory\ReadFactory; - +use Composer\InstalledVersions; class ModuleVersion { const COMPOSER_FILE_NAME = 'composer.json'; @@ -38,6 +38,16 @@ public function __construct(ComponentRegistrarInterface $componentRegistrar, Rea $this->componentRegistrar = $componentRegistrar; $this->readFactory = $readFactory; } + public function getLibVersion($libName) + { + $emptyVersionNumber = ''; + try { + $lib = InstalledVersions::getVersion($libName); + return $lib; + } catch (\Exception $e) { + return $emptyVersionNumber; + } + } public function getModuleVersion($moduleName) : string { $emptyVersionNumber = ''; @@ -50,11 +60,17 @@ public function getModuleVersion($moduleName) : string return $emptyVersionNumber; } catch (FileSystemException $fsException) { return $emptyVersionNumber; + } catch (\Exception $exception) { + return $emptyVersionNumber; } - $jsonData = json_decode($composerJsonData); - if ($jsonData === null) { + try { + $jsonData = json_decode($composerJsonData); + if ($jsonData === null) { + return $emptyVersionNumber; + } + return $jsonData->version ?? $emptyVersionNumber; + } catch (\Exception $exception) { return $emptyVersionNumber; } - return $jsonData->version ?? $emptyVersionNumber; } } diff --git a/Model/Config/Source/Details.php b/Model/Config/Source/Details.php index e7e0273f..832a807d 100644 --- a/Model/Config/Source/Details.php +++ b/Model/Config/Source/Details.php @@ -99,7 +99,7 @@ public function __construct( } else { $this->_options['store_exists'] = false; } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); $this->_error = $e->getMessage(); $this->_options['store_exists'] = false; diff --git a/Model/Config/Source/Interest.php b/Model/Config/Source/Interest.php index 92c603d8..b39193d0 100644 --- a/Model/Config/Source/Interest.php +++ b/Model/Config/Source/Interest.php @@ -26,7 +26,7 @@ public function __construct( \Ebizmarts\MailChimp\Helper\Data $helper, \Magento\Framework\App\RequestInterface $request ) { - + $storeId = (int) $request->getParam("store", 0); if ($request->getParam('website', 0)) { $scope = 'website'; @@ -45,7 +45,7 @@ public function __construct( null, 200 ); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $helper->log($e->getFriendlyMessage()); } } diff --git a/Model/Config/Source/MonkeyList.php b/Model/Config/Source/MonkeyList.php index 08798e0f..d709bdfe 100644 --- a/Model/Config/Source/MonkeyList.php +++ b/Model/Config/Source/MonkeyList.php @@ -42,7 +42,7 @@ public function __construct( $this->options = $helper->getApi($storeId, $scope)->lists->getLists( $helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_LIST, $storeId, $scope) ); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $helper->log($e->getFriendlyMessage()); } } diff --git a/Model/Config/Source/MonkeyStore.php b/Model/Config/Source/MonkeyStore.php index 2a77ab1c..a1920816 100644 --- a/Model/Config/Source/MonkeyStore.php +++ b/Model/Config/Source/MonkeyStore.php @@ -44,7 +44,7 @@ public function __construct( null, \Ebizmarts\MailChimp\Helper\Data::MAXSTORES ); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $helper->log($e->getFriendlyMessage()); } } diff --git a/Model/MailchimpNotification.php b/Model/MailchimpNotification.php new file mode 100644 index 00000000..1932f9a3 --- /dev/null +++ b/Model/MailchimpNotification.php @@ -0,0 +1,11 @@ +_init(\Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification::class); + } +} diff --git a/Model/Plugin/Subscriber.php b/Model/Plugin/Subscriber.php index a8f2c7b1..60024204 100644 --- a/Model/Plugin/Subscriber.php +++ b/Model/Plugin/Subscriber.php @@ -33,7 +33,7 @@ public function __construct( \Ebizmarts\MailChimp\Helper\Data $helper, \Magento\Store\Model\StoreManagerInterface $storeManager ) { - + $this->_helper = $helper; $this->_storeManager = $storeManager; } @@ -63,7 +63,7 @@ public function afterDelete( } else { $api->lists->members->delete($this->_helper->getDefaultList($storeId), $md5HashEmail); } - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } } @@ -103,7 +103,7 @@ public function afterLoadBySubscriberEmail(\Magento\Newsletter\Model\Subscriber return $subscriber; } - + /** * @param \Magento\Newsletter\Model\Subscriber $subscriber * @param $customerId diff --git a/Model/Plugin/SubscriptionManager.php b/Model/Plugin/SubscriptionManager.php index 21825f50..374ff648 100644 --- a/Model/Plugin/SubscriptionManager.php +++ b/Model/Plugin/SubscriptionManager.php @@ -84,7 +84,7 @@ public function beforeUnsubscribeCustomer( null, 'unsubscribed' ); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } } @@ -136,7 +136,7 @@ public function beforeSubscribeCustomer( $email, $status ); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } } @@ -185,7 +185,7 @@ public function beforeSubscribe( $email, $status ); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } } @@ -214,7 +214,7 @@ public function beforeUnsubscribe( null, 'unsubscribed' ); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } } diff --git a/Model/ResourceModel/MailchimpNotification.php b/Model/ResourceModel/MailchimpNotification.php new file mode 100644 index 00000000..326d502e --- /dev/null +++ b/Model/ResourceModel/MailchimpNotification.php @@ -0,0 +1,14 @@ +_init('mailchimp_notification', 'id'); + } + +} diff --git a/Model/ResourceModel/MailchimpNotification/Collection.php b/Model/ResourceModel/MailchimpNotification/Collection.php new file mode 100644 index 00000000..c8f4d8e8 --- /dev/null +++ b/Model/ResourceModel/MailchimpNotification/Collection.php @@ -0,0 +1,14 @@ +_init( + \Ebizmarts\MailChimp\Model\MailchimpNotification::class, + \Ebizmarts\MailChimp\Model\ResourceModel\MailchimpNotification::class + ); + } +} diff --git a/Observer/Subscriber/SaveAfter.php b/Observer/Subscriber/SaveAfter.php index c0b29452..9eecd32c 100644 --- a/Observer/Subscriber/SaveAfter.php +++ b/Observer/Subscriber/SaveAfter.php @@ -92,7 +92,7 @@ public function execute(\Magento\Framework\Event\Observer $observer) $subscriberOld->getEmail(), $status ); - } catch (\Mailchimp_Error $e) { + } catch (\Mailchimp_Error | \Mailchimp_HttpError $e) { $this->_helper->log($e->getFriendlyMessage()); } diff --git a/composer.json b/composer.json index 27dd0bf3..c3d348c5 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ }, "require" : { "magento/framework": "103.0.*", - "ebizmarts/mailchimp-lib": ">=3.0.38", + "ebizmarts/mailchimp-lib": ">=3.0.43", "ext-json": "*" } } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 5c56900a..ca171448 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -116,7 +116,17 @@ - + + Magento\Config\Model\Config\Source\Yesno + + 1 + + + + + + this]]> + Magento\Config\Model\Config\Source\Yesno 1 diff --git a/etc/crontab.xml b/etc/crontab.xml index 4647e4a2..67d78f7c 100644 --- a/etc/crontab.xml +++ b/etc/crontab.xml @@ -29,5 +29,11 @@ 0 * * * * + + * */12 * * * + + + 0 */6 * * * + diff --git a/etc/db_schema.xml b/etc/db_schema.xml index 395f4115..7ba50bb6 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -1,16 +1,16 @@ - + - +
- +
- +
@@ -54,7 +54,7 @@ - + @@ -104,11 +104,11 @@ - + - + - + + + + + + + + + + + diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json index 1a29b7b9..d0a86ebb 100644 --- a/etc/db_schema_whitelist.json +++ b/etc/db_schema_whitelist.json @@ -155,5 +155,17 @@ "mailchimp_sync_error": true, "mailchimp_sent": true } + }, + "mailchimp_notification": { + "column": { + "id": true, + "notification_data": true, + "generated_at": true, + "synced_at": true, + "processed": true + }, + "constraint": { + "PRIMARY": true + } } }