/**
  * Execute method.
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     try {
         if (!$this->registry->registry('core_config_data_save_after_done')) {
             if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
                 if (isset($groups['catalog_sync']['fields']['catalog_values']['value'])) {
                     $configAfter = $groups['catalog_sync']['fields']['catalog_values']['value'];
                     $configBefore = $this->registry->registry('core_config_data_save_before');
                     if ($configAfter != $configBefore) {
                         //reset catalog to re-import
                         $this->connectorCatalogFactory->create()->reset();
                     }
                     $this->registry->register('core_config_data_save_after_done', true);
                 }
             }
         }
         if (!$this->registry->registry('core_config_data_save_after_done_status')) {
             if ($groups = $observer->getEvent()->getConfigData()->getGroups()) {
                 if (isset($groups['data_fields']['fields']['order_statuses']['value'])) {
                     $configAfter = $groups['data_fields']['fields']['order_statuses']['value'];
                     $configBefore = $this->registry->registry('core_config_data_save_before_status');
                     if ($configAfter != $configBefore) {
                         //reset all contacts
                         $this->connectorContactFactory->create()->resetAllContacts();
                     }
                     $this->registry->register('core_config_data_save_after_done_status', true);
                 }
             }
         }
     } catch (\Exception $e) {
         $this->helper->debug((string) $e, []);
     }
     return $this;
 }
 /**
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function execute()
 {
     $redirectUrl = $this->getUrl('adminhtml/system_config/edit', ['section' => 'connector_developer_settings']);
     $result = $this->contactFactory->create()->deleteContactIds();
     $this->messageManager->addSuccessMessage('Contact id\'s reseted ' . $result);
     $this->_redirect($redirectUrl);
 }
 /**
  * Refresh suppressed contacts.
  */
 public function execute()
 {
     $this->contactFactory->create()->resetSubscribers();
     $this->messageManager->addSuccessMessage(__('Done.'));
     $redirectUrl = $this->getUrl('adminhtml/system_config/edit', ['section' => 'connector_developer_settings']);
     $this->_redirect($redirectUrl);
 }
 /**
  * Execute method.
  *
  * @param \Magento\Framework\Event\Observer $observer
  *
  * @return $this
  * @codingStandardsIgnoreStart
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     //@codingStandardsIgnoreEnd
     $contactModel = $this->contactResourceFactory->create();
     $numImported = $this->contactFactory->create()->getNumberOfImportedContacs();
     $updated = $contactModel->resetAllContacts();
     $this->helper->log('-- Imported contacts: ' . $numImported . ' reseted :  ' . $updated . ' --');
     return $this;
 }
 /**
  * Initial sync the transactional data.
  *
  * @return array
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function sync()
 {
     $response = ['success' => true, 'message' => 'Done.'];
     // Initialise a return hash containing results of our sync attempt
     $this->_searchAccounts();
     foreach ($this->accounts as $account) {
         $orders = $account->getOrders();
         $orderIds = $account->getOrderIds();
         $ordersForSingleSync = $account->getOrdersForSingleSync();
         $orderIdsForSingleSync = $account->getOrderIdsForSingleSync();
         //@codingStandardsIgnoreStart
         $numOrdersForSingleSync = count($ordersForSingleSync);
         $website = $account->getWebsites();
         $numOrders = count($orders);
         //@codingStandardsIgnoreEnd
         $this->countOrders += $numOrders;
         $this->countOrders += $numOrdersForSingleSync;
         //send transactional for any number of orders set
         if ($numOrders) {
             $this->helper->log('--------- Order sync ---------- : ' . $numOrders);
             //queue order into importer
             $this->helper->error('orders', $orders);
             try {
                 $this->importerFactory->create()->registerQueue(\Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_ORDERS, $orders, \Dotdigitalgroup\Email\Model\Importer::MODE_BULK, $website[0]);
             } catch (\Exception $e) {
                 $this->helper->debug((string) $e, []);
             }
             $this->_setImported($orderIds);
             $this->helper->log('----------end order sync----------');
         }
         if ($numOrdersForSingleSync) {
             $error = false;
             foreach ($ordersForSingleSync as $order) {
                 $this->helper->log('--------- register Order sync in single with importer ---------- : ');
                 //register in queue with importer
                 $this->importerFactory->create()->registerQueue(\Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_ORDERS, $order, \Dotdigitalgroup\Email\Model\Importer::MODE_SINGLE, $website[0]);
                 $this->helper->log('----------end order sync in single----------');
             }
             //if no error then set imported
             if (!$error) {
                 $this->_setImported($orderIdsForSingleSync, true);
             }
         }
         unset($this->accounts[$account->getApiUsername()]);
     }
     /**
      * Add guest to contacts table.
      */
     if (!empty($this->guests)) {
         $this->contactFactory->create()->insert($this->guests);
     }
     if ($this->countOrders) {
         $response['message'] = 'Orders updated ' . $this->countOrders;
     }
     return $response;
 }