/**
  * View Catalog Product action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $productId = $observer->getEvent()->getProduct()->getId();
     $viewData['product_id'] = $productId;
     $viewData['store_id'] = $this->_storeManager->getStore()->getId();
     if ($this->_customerSession->isLoggedIn()) {
         $viewData['customer_id'] = $this->_customerSession->getCustomerId();
     } else {
         $viewData['visitor_id'] = $this->_customerVisitor->getId();
     }
     $this->_productIndxFactory->create()->setData($viewData)->save()->calculate();
     $this->eventSaver->save(\Magento\Reports\Model\Event::EVENT_PRODUCT_VIEW, $productId);
 }
 /**
  * Customer login action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_customerSession->isLoggedIn()) {
         return $this;
     }
     $visitorId = $this->_customerVisitor->getId();
     $customerId = $this->_customerSession->getCustomerId();
     $eventModel = $this->_eventFactory->create();
     $eventModel->updateCustomerType($visitorId, $customerId);
     $this->_productCompFactory->create()->updateCustomerFromVisitor()->calculate();
     $this->_productIndexFactory->create()->updateCustomerFromVisitor()->calculate();
     return $this;
 }
 /**
  * Customer logout processing
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $this->_productCompFactory->create()->purgeVisitorByCustomer()->calculate();
     $this->_productIndxFactory->create()->purgeVisitorByCustomer()->calculate();
 }
示例#4
0
 /**
  * View Catalog Product action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return Observer
  */
 public function catalogProductView(\Magento\Framework\Event\Observer $observer)
 {
     $productId = $observer->getEvent()->getProduct()->getId();
     $this->_productIndxFactory->create()->setProductId($productId)->save()->calculate();
     return $this->_event(\Magento\Reports\Model\Event::EVENT_PRODUCT_VIEW, $productId);
 }