Observer/Newsletter/RemoveContact.php
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $subscriber = $observer->getEvent()->getSubscriber();
        $email = $subscriber->getEmail();
        $websiteId = $this->storeManager->getStore($subscriber->getStoreId())
            ->getWebsiteId();
        $apiEnabled = $this->helper->isEnabled($websiteId);

        /*
         * Remove contact.
         */
        if ($apiEnabled) {
            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
                    $this->contactResource->delete($contactModel);
                }
            } catch (\Exception $e) {
                $this->helper->debug((string)$e, []);
            }
        }

        return $this;
    }
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $subscriber = $observer->getEvent()->getSubscriber();
        $email = $subscriber->getEmail();
        $websiteId = $this->storeManager->getStore($subscriber->getStoreId())
            ->getWebsiteId();
        $apiEnabled = $this->helper->isEnabled($websiteId);

        /*
         * Remove contact.
         */
        if ($apiEnabled) {
            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
                    $this->contactResource->delete($contactModel);
                }
            } catch (\Exception $e) {
                $this->helper->debug((string)$e, []);
            }
        }

        return $this;
    }
public function execute ( \ Magento \ Framework \ Event \ Observer $ observer ) { $ subscriber = $ observer -> getEvent ( ) -> getSubscriber ( ) ; $ email = $ subscriber -> getEmail ( ) ; $ websiteId = $ this -> storeManager -> getStore ( $ subscriber -> getStoreId ( ) ) -> getWebsiteId ( ) ; $ apiEnabled = $ this -> helper -> isEnabled ( $ websiteId ) ; /*
         * Remove contact.
         */ if ( $ apiEnabled ) { 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 $ this -> contactResource -> delete ( $ contactModel ) ; } } catch ( \ Exception $ e ) { $ this -> helper -> debug ( ( string ) $ e , [ ] ) ; } } return $ this ; }
Remove contact from account

@param \Magento\Framework\Event\Observer $observer

@return $this
Remove contact from account