Change contact subscription status.

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

@return $this
329777
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $subscriber = $observer->getEvent()->getSubscriber();
        $this->isSubscriberNew = $subscriber->isObjectNew();
        $email = $subscriber->getEmail();
        $storeId = $subscriber->getStoreId();
        $subscriberStatus = $subscriber->getSubscriberStatus();
        $websiteId = $this->storeManager->getStore($subscriber->getStoreId())
            ->getWebsiteId();

        //api is enabled
        if (!$this->helper->isEnabled($websiteId)) {
            return $this;
        }

        try {
            $contactEmail = $this->contactFactory->create()
                ->loadByCustomerEmail($email, $websiteId);

            //update the contact
            $contactEmail->setStoreId($storeId)
                ->setSubscriberStatus($subscriberStatus);

            // only for subscribers
            if ($subscriberStatus == \Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED) {
                //Set contact as subscribed
                $contactEmail->setSubscriberImported(null)
                    ->setIsSubscriber('1');

                //Subscriber subscribed when it is suppressed in table then re-subscribe
                if ($contactEmail->getSuppressed()) {
                    $this->importerFactory->registerQueue(
                        \Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_SUBSCRIBER_RESUBSCRIBED,
                        ['email' => $email],
                        \Dotdigitalgroup\Email\Model\Importer::MODE_SUBSCRIBER_RESUBSCRIBED,
                        $websiteId
                    );
                    //Set to subscriber imported and reset the subscriber as suppressed
                    $contactEmail->setSubscriberImported(1)
                        ->setSuppressed(null);
                }
                //save contact
                $this->contactResource->save($contactEmail);

                //not subscribed
            } else {
                //skip if contact is suppressed
                if ($contactEmail->getSuppressed()) {
                    return $this;
                }
                $contactEmail->setSubscriberImported(1)
                    ->setIsSubscriber(null);
                //save contact
                $this->contactResource->save($contactEmail);

                //need to confirm enabled, to keep before the subscription data for contentinsight.
                if ($subscriberStatus == \Magento\Newsletter\Model\Subscriber::STATUS_UNCONFIRMED ||
                    $subscriberStatus == \Magento\Newsletter\Model\Subscriber::STATUS_NOT_ACTIVE) {
                    return $this;
                }

                //Add subscriber update to importer queue
                $this->importerFactory->registerQueue(
                    \Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_SUBSCRIBER_UPDATE,
                    ['email' => $email, 'id' => $contactEmail->getId()],
                    \Dotdigitalgroup\Email\Model\Importer::MODE_SUBSCRIBER_UPDATE,
                    $websiteId
                );
            }

            // fix for a multiple hit of the observer. stop adding the duplicates on the automation
            $emailReg = $this->registry->registry($email . '_subscriber_save');
            if ($emailReg) {
                return $this;
            }
            $this->registry->unregister($email . '_subscriber_save'); // additional measure
            $this->registry->register($email . '_subscriber_save', $email);
            //add subscriber to automation
            $this->addSubscriberToAutomation($email, $subscriber, $websiteId);
        } catch (\Exception $e) {
            $this->helper->debug((string)$e, []);
        }

        return $this;
    }
1080965
public function notify()
    {
        if (0 < count($this->observers)) {
            foreach ($this->observers as $observer) {
                /** @var \Liip\Drupal\Modules\EventManager\EventObserverInterface $observer */
                $observer->update($this);
            }
        }
    }
633696
public function add_subscriber( EventSubscriber $subscriber ) {

		foreach ( $subscriber->get_subscribed_events() as $event => $params ) {

			if ( is_string( $params ) ) {
				$this->add_listener( $event, array( $subscriber, $params ) );
			} elseif ( is_array( $params ) && isset( $params[0] ) ) {

				$method        = $params[0];
				$priority      = isset( $params[1] ) ? $params[1] : self::PRIORITY;
				$accepted_args = isset( $params[2] ) ? $params[2] : self::ACCEPTED;

				$this->add_listener( $event, array( $subscriber, $method ), $priority, $accepted_args );
			} else {
				throw new \InvalidArgumentException( 'Invalid return format from EventSubscriber.' );
			}
		}

		return $this;
	}
382855
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        /** define local working data */
        /** @var \Magento\Catalog\Model\Product $product */
        $product = $observer->getData(self::DATA_PRODUCT);

        /** perform processing */
        if ($product instanceof \Magento\Catalog\Model\Product) {
            $product->setSpecialPrice(null);
        }
    }
711001
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $order = $observer->getEvent()->getOrder();
        $incrementId = $order->getIncrementId();
        $websiteId = $this->storeManager->getStore($order->getStoreId())
            ->getWebsiteId();

        $orderSync = $this->helper->isOrderSyncEnabled($websiteId);

        if ($this->helper->isEnabled($websiteId) && $orderSync) {
            //register in queue with importer
            $this->importerFactory->create()
                ->registerQueue(
                    \Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_ORDERS,
                    [$incrementId],
                    \Dotdigitalgroup\Email\Model\Importer::MODE_SINGLE_DELETE,
                    $websiteId
                );
        }

        return $this;
    }
922058
protected function validateObserver($observer): bool
    {
        return !$this->isDisable($observer)
            && (new ReflectionClass($observer))->implementsInterface(EventHandlerInterface::class)
            && $this->accessible($observer);
    }
863529
public function update($subscription){
        if(!isset($this->_id) || null == $this->_id){
            throw new \Exception("You must especify an Id to perform subscription updates");
        }
        if($subscription instanceof SubscriptionFactory){
            $context = new ContextFactory((array) $subscription->get());
        }elseif(is_array($subscription) || is_object($subscription)){
            $context = new ContextFactory((array)$subscription);
        }
        return $this->_orion->patch($this->getBaseURI(), $context);
    }
974613
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $dataObject = $observer->getEvent()->getDataObject();

        if ($dataObject->getCustomerId()
            && $dataObject->getStatusId()
            == \Magento\Review\Model\Review::STATUS_APPROVED
        ) {
            $customerId = $dataObject->getCustomerId();
            $this->helper->setConnectorContactToReImport($customerId);
            //save review info in the table
            $this->registerReview($dataObject);
            $store = $this->storeManager->getStore($dataObject->getStoreId());
            $storeName = $store->getName();
            $website = $this->storeManager->getStore($store)->getWebsite();
            $customer = $this->customerFactory->create();
            $this->customerResource->load($customer, $customerId);
            //if api is not enabled
            if (!$this->helper->isEnabled($website)) {
                return $this;
            }

            $programId
                = $this->helper->getWebsiteConfig('connector_automation/visitor_automation/review_automation');
            if ($programId) {
                $automation = $this->automationFactory->create();
                $automation->setEmail($customer->getEmail())
                    ->setAutomationType(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_TYPE_NEW_REVIEW)
                    ->setEnrolmentStatus(\Dotdigitalgroup\Email\Model\Sync\Automation::AUTOMATION_STATUS_PENDING)
                    ->setTypeId($dataObject->getReviewId())
                    ->setWebsiteId($website->getId())
                    ->setStoreName($storeName)
                    ->setProgramId($programId);
                $this->automationResource->save($automation);
            }
        }

        return $this;
    }
1095884
public function subscribe(string $eventName, callable $subscriber): self
    {
        if ($subscriber instanceof Closure || ($staticMethod = $this->parseStaticMethod($subscriber)) === null) {
            $this->subscribers[$eventName][] = $subscriber;
        } else {
            assert($staticMethod !== null);
            $this->subscribers[$eventName][] = $this->getUnifiedStaticMethodRepresentation($staticMethod);
        }

        $this->addAllowedEvent($eventName);

        return $this;
    }
1125667
public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $customer = $observer->getEvent()->getCustomer();
        $websiteId  = $customer->getWebsiteId();
        $storeId = $customer->getStoreId();

        //check if enabled
        if (!$this->helper->isEnabled($websiteId)) {
            return $this;
        }

        $email      = $customer->getEmail();
        $customerId = $customer->getEntityId();
        $subscriber = $this->subscriberFactory->create()
            ->loadByCustomerId($customerId);
        $isSubscribed = $subscriber->isSubscribed();

        $emailBefore = '';

        try {
            // fix for a multiple hit of the observer
            $emailReg = $this->registry->registry($email . '_customer_save');
            if ($emailReg) {
                return $this;
            }
            $this->registry->unregister($email . '_customer_save'); // additional measure
            $this->registry->register($email . '_customer_save', $email);

            $isContactExist = $this->contactFactory->create()
                ->loadByCustomerId($customerId);

            if ($isContactExist->getId()) {
                $emailBefore = $isContactExist->getEmail();
            }

            $emailAddress = empty($emailBefore) ? $email : $emailBefore;

            $contactModel = $this->contactFactory->create()
                ->loadByCustomerEmail($emailAddress, $websiteId);

            //email change detection
            if ($emailBefore && $email != $emailBefore) {
                //Reload contact model up update email
                $contactModel = $this->contactFactory->create()
                    ->loadByCustomerEmail($emailAddress, $websiteId);
                $contactModel->setEmail($email);

                $data = [
                    'emailBefore' => $emailBefore,
                    'email' => $email,
                    'isSubscribed' => $isSubscribed,
                ];
                $this->importerFactory->create()->registerQueue(
                    \Dotdigitalgroup\Email\Model\Importer::IMPORT_TYPE_CONTACT_UPDATE,
                    $data,
                    \Dotdigitalgroup\Email\Model\Importer::MODE_CONTACT_EMAIL_UPDATE,
                    $websiteId
                );
            } elseif (!$emailBefore) {
                //for new contacts update email
                $contactModel->setEmail($email);
            }
            $contactModel->setEmailImported(\Dotdigitalgroup\Email\Model\Contact::EMAIL_CONTACT_NOT_IMPORTED)
                ->setStoreId($storeId)
                ->setCustomerId($customerId);
            $this->contactResource->save($contactModel);
        } catch (\Exception $e) {
            $this->helper->debug((string)$e, []);
        }

        return $this;
    }
288871
public function execute(Observer $observer) {

        // Get the order
        $order = $observer->getEvent()->getOrder();

        // Get the payment method
        $paymentMethod = $order->getPayment()->getMethod();

        // Test the current method used
        if ($paymentMethod == ConfigProvider::CODE || $paymentMethod == ConfigProvider::CC_VAULT_CODE || $paymentMethod == ConfigProvider::THREE_DS_CODE) {

            // Update the hub API for cancelled order
            $this->orderService->cancelTransactionToRemote($order);    
        }

        return $this;
    }
339924
public function setCardCookie($observer)
    {
        $quoteData = $observer->getQuote()->debug();
        unset($quoteData['updated_at']);
        $this->setCookies(array(
            self::COOKIE_CART => $this->_hashData($quoteData),
            self::COOKIE_SEGMENT => $this->_hashData($this->_getHelper()->getCustomerSegment())
        ));
    }
548126
public function subscribe($subscriber)
    {
        if (is_object($subscriber)) {
            $subscriber->subscribe($this);
            return;
        }
        $this->subscribe(new $subscriber);
    }
141165
public function handleShipGroupChargeType(Varien_Event_Observer $observer)
    {
        $event = $observer->getEvent();
        $shipGroup = $event->getShipGroupPayload();
        Mage::helper('radial_core/shipping_chargetype')->setShippingChargeType($shipGroup);
        return $this;
    }
205999
public function notify($type = 'default')
    {
        if (isset($this->observers[$type])) {
            foreach ($this->observers[$type] as $obs) {
                $obs->update($this);
            }
        }
        return $this;
    }
458642
public function AttachObserver($observer)
	{
		parent::AttachObserver($observer);
		foreach ($this->DataAdapters as $adapter) {
			$adapter->AttachObserver($observer);
		}
	}
751310
public function unserialize($subscription): self
    {
        $data = json_decode($subscription, true);

        $this->operationName = $data['operation_name'];
        $this->channel = $data['channel'];
        $this->args = $data['args'];
        $this->context = $this->contextSerializer()->unserialize(
            $data['context']
        );
        $this->query = AST::fromArray(
            unserialize($data['query'])
        );

        return $this;
    }