/** * If it's configured to capture on shipment - do this. * * @param \Magento\Framework\Event\Observer $observer * * @return $this */ public function execute(\Magento\Framework\Event\Observer $observer) { $customer = $observer->getEvent()->getCustomer(); $email = $customer->getEmail(); $websiteId = $customer->getWebsiteId(); $apiEnabled = $this->helper->isEnabled($websiteId); $customerSync = $this->helper->isCustomerSyncEnabled($websiteId); /* * Remove contact. */ if ($apiEnabled && $customerSync) { try { //register in queue with importer $this->importerFactory->create()->registerQueue(\Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_CONTACT, $email, \Dotdigitalgroup\Email\Model\Importer::MODE_CONTACT_DELETE, $websiteId); $contactModel = $this->contactFactory->create()->loadByCustomerEmail($email, $websiteId); if ($contactModel->getId()) { //remove contact $contactModel->delete(); } } catch (\Exception $e) { $this->helper->debug((string) $e, []); } } return $this; }
/** * Contact sync. * * @return array */ public function sync() { //result message $result = ['success' => true, 'message' => '']; //starting time for sync $this->start = microtime(true); //resourse allocation $started = false; //export bulk contacts foreach ($this->helper->getWebsites() as $website) { $apiEnabled = $this->helper->isEnabled($website); $customerSyncEnabled = $this->helper->isCustomerSyncEnabled($website); $customerAddressBook = $this->helper->getCustomerAddressBook($website); //api, customer sync and customer address book must be enabled if ($apiEnabled && $customerSyncEnabled && $customerAddressBook) { //start log $contactsUpdated = $this->exportCustomersForWebsite($website); if ($this->countCustomers && !$started) { $this->helper->log('---------- Start customer sync ----------'); $started = true; } // show message for any number of customers if ($contactsUpdated) { $result['message'] .= $website->getName() . ', exported contacts ' . $contactsUpdated; } } } //sync proccessed if ($this->countCustomers) { $message = 'Total time for sync : ' . gmdate('H:i:s', microtime(true) - $this->start) . ', Total contacts ' . $this->countCustomers; $this->helper->log($message); $message .= $result['message']; $result['message'] = $message; } return $result; }