/**
  * 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;
 }
Ejemplo n.º 2
0
 /**
  * Save event
  *
  * @param int $eventTypeId
  * @param int $objectId
  * @param int|null $subjectId
  * @param int $subtype
  * @return void
  */
 public function save($eventTypeId, $objectId, $subjectId = null, $subtype = 0)
 {
     if ($subjectId === null) {
         if ($this->_customerSession->isLoggedIn()) {
             $subjectId = $this->_customerSession->getCustomerId();
         } else {
             $subjectId = $this->_customerVisitor->getId();
             $subtype = 1;
         }
     }
     /** @var \Magento\Reports\Model\Event $eventModel */
     $eventModel = $this->_eventFactory->create();
     $storeId = $this->_storeManager->getStore()->getId();
     $eventModel->setData(['event_type_id' => $eventTypeId, 'object_id' => $objectId, 'subject_id' => $subjectId, 'subtype' => $subtype, 'store_id' => $storeId]);
     $eventModel->save();
 }
Ejemplo n.º 3
0
 /**
  * Retrieve item collection
  *
  * @return mixed
  */
 public function getItemCollection()
 {
     $productCollection = $this->getData('item_collection');
     if ($productCollection === null) {
         $stores = [];
         $website = $this->_storeManager->getStore($this->getStoreId())->getWebsite();
         foreach ($website->getStores() as $store) {
             $stores[] = $store->getId();
         }
         $collection = $this->_eventFactory->create()->getCollection()->addStoreFilter($stores)->addRecentlyFiler(\Magento\Reports\Model\Event::EVENT_PRODUCT_VIEW, $this->getCustomerId(), 0);
         $productIds = [];
         foreach ($collection as $event) {
             $productIds[] = $event->getObjectId();
         }
         $productCollection = null;
         if ($productIds) {
             $productCollection = $this->_productFactory->create()->getCollection()->setStoreId($this->getQuote()->getStoreId())->addStoreFilter($this->getQuote()->getStoreId())->addAttributeToSelect('name')->addAttributeToSelect('price')->addAttributeToSelect('small_image')->addIdFilter($productIds)->load();
         }
         $this->setData('item_collection', $productCollection);
     }
     return $productCollection;
 }