/**
  * Add product to shopping cart action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $quoteItem = $observer->getEvent()->getItem();
     if (!$quoteItem->getId() && !$quoteItem->getParentItem()) {
         $productId = $quoteItem->getProductId();
         $this->eventSaver->save(\Magento\Reports\Model\Event::EVENT_PRODUCT_TO_CART, $productId);
     }
     return $this;
 }
 /**
  * Add Product to Compare Products List action
  *
  * Reset count of compared products cache
  *
  * @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];
     if ($this->_customerSession->isLoggedIn()) {
         $viewData['customer_id'] = $this->_customerSession->getCustomerId();
     } else {
         $viewData['visitor_id'] = $this->_customerVisitor->getId();
     }
     $this->_productCompFactory->create()->setData($viewData)->save()->calculate();
     $this->eventSaver->save(\Magento\Reports\Model\Event::EVENT_PRODUCT_COMPARE, $productId);
 }
 /**
  * @param bool $isLoggedIn
  * @param string $userKey
  * @param int $userId
  * @dataProvider catalogProductCompareAddProductDataProvider
  * @return void
  */
 public function testCatalogProductCompareAddProduct($isLoggedIn, $userKey, $userId)
 {
     $productId = 111;
     $customerId = 222;
     $visitorId = 333;
     $viewData = ['product_id' => $productId, $userKey => $userId];
     $observerMock = $this->getObserverMock($productId);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn($isLoggedIn);
     $this->customerSessionMock->expects($this->any())->method('getCustomerId')->willReturn($customerId);
     $this->customerVisitorMock->expects($this->any())->method('getId')->willReturn($visitorId);
     $this->productCompModelMock->expects($this->any())->method('setData')->with($viewData)->willReturnSelf();
     $this->productCompModelMock->expects($this->any())->method('save')->willReturnSelf();
     $this->productCompModelMock->expects($this->any())->method('calculate')->willReturnSelf();
     $this->eventSaverMock->expects($this->once())->method('save');
     $this->observer->execute($observerMock);
 }
 /**
  * @return void
  */
 public function testCatalogProductViewVisitor()
 {
     $productId = 6;
     $visitorId = 88;
     $storeId = 1;
     $expectedViewedData = ['product_id' => $productId, 'visitor_id' => $visitorId, 'store_id' => $storeId];
     $expectedEventData = ['event_type_id' => \Magento\Reports\Model\Event::EVENT_PRODUCT_VIEW, 'object_id' => $productId, 'subject_id' => $visitorId, 'subtype' => 1, 'store_id' => $storeId];
     $this->storeMock->expects($this->any())->method('getId')->willReturn($storeId);
     $this->customerSessionMock->expects($this->any())->method('isLoggedIn')->willReturn(false);
     $this->customerVisitorMock->expects($this->any())->method('getId')->willReturn($visitorId);
     $this->eventSaverMock->expects($this->once())->method('save');
     $this->prepareProductIndexMock($expectedViewedData);
     $this->prepareReportEventModel($expectedEventData);
     $eventObserver = $this->getObserverMock($productId);
     $this->observer->execute($eventObserver);
 }
 /**
  * Share customer wishlist action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $this->eventSaver->save(\Magento\Reports\Model\Event::EVENT_WISHLIST_SHARE, $observer->getEvent()->getWishlist()->getId());
 }
 /**
  * Send Product link to friends action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return void
  */
 public function execute(\Magento\Framework\Event\Observer $observer)
 {
     $this->eventSaver->save(\Magento\Reports\Model\Event::EVENT_PRODUCT_SEND, $observer->getEvent()->getProduct()->getId());
 }