/** * 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); }
/** * 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(); }
/** * Remove All Products from Compare Products * * Reset count of compared products cache * * @param \Magento\Framework\Event\Observer $observer * @return $this * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(\Magento\Framework\Event\Observer $observer) { $this->_productCompFactory->create()->calculate(); return $this; }
/** * Add Product to Compare Products List action * * Reset count of compared products cache * * @param \Magento\Framework\Event\Observer $observer * @return Observer */ public function catalogProductCompareAddProduct(\Magento\Framework\Event\Observer $observer) { $productId = $observer->getEvent()->getProduct()->getId(); $this->_productCompFactory->create()->setProductId($productId)->save()->calculate(); return $this->_event(\Magento\Reports\Model\Event::EVENT_PRODUCT_COMPARE, $productId); }