diff --git a/Cron/GenerateStatistics.php b/Cron/GenerateStatistics.php index 15a254ca..4fd80243 100644 --- a/Cron/GenerateStatistics.php +++ b/Cron/GenerateStatistics.php @@ -89,19 +89,23 @@ public function execute() $data = []; foreach ($this->storeManager->getStores() as $storeId => $val) { - $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'] = $this->getBatches($storeId, $mailChimpStoreId); - $data['jobs'] = $this->getJobs(); + 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'] = $this->getBatches($storeId, $mailChimpStoreId); + $data['jobs'] = $this->getJobs(); + } + } + if (!empty($data)) { + $mailchimpNotification = $this->mailchimpNotificationFactory->create(); + $mailchimpNotification->setNotificationData(json_encode($data)); + $mailchimpNotification->setProcessed(false); + $mailchimpNotification->getResource()->save($mailchimpNotification); } - $mailchimpNotification = $this->mailchimpNotificationFactory->create(); - $mailchimpNotification->setNotificationData(json_encode($data)); - $mailchimpNotification->setProcessed(false); - $mailchimpNotification->getResource()->save($mailchimpNotification); } private function getMagentoTotals($storeId) {