reviewFactory = $reviewFactory; $this->reviewResource = $reviewResource; $this->automationResource = $automationResource; $this->automationFactory = $automationFactory; $this->customerFactory = $customerFactory; $this->helper = $data; $this->storeManager = $storeManagerInterface; $this->customerResource = $customerResource; } /** * 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) { $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; } /** * Register review. * * @param mixed $review * * @return null */ private function registerReview($review) { try { $reviewModel = $this->reviewFactory->create(); $reviewModel->setReviewId($review->getReviewId()) ->setCustomerId($review->getCustomerId()) ->setStoreId($review->getStoreId()); $this->reviewResource->save($reviewModel); } catch (\Exception $e) { $this->helper->debug((string)$e, []); } } }