コード例 #1
0
 public function testAddProductWithoutSession()
 {
     /** @var $product \Magento\Catalog\Model\Product */
     $product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product')->load(1);
     $this->_model->addProduct($product);
     $this->assertFalse($this->_model->hasItems(1, $this->_visitor->getId()));
     $this->assertTrue($this->_model->hasItems(0, $this->_visitor->getId()));
 }
コード例 #2
0
 /**
  * Init collection select
  *
  * @return $this
  */
 protected function _initSelect()
 {
     parent::_initSelect();
     $connection = $this->getConnection();
     $lastDate = $this->date->gmtTimestamp() - $this->visitorModel->getOnlineInterval() * self::SECONDS_IN_MINUTE;
     $this->getSelect()->joinLeft(['customer' => $this->getTable('customer_entity')], 'customer.entity_id = main_table.customer_id', ['email', 'firstname', 'lastname'])->where('main_table.last_visit_at >= ?', $connection->formatDate($lastDate));
     $expression = $connection->getCheckSql('main_table.customer_id IS NOT NULL AND main_table.customer_id != 0', $connection->quote(Visitor::VISITOR_TYPE_CUSTOMER), $connection->quote(Visitor::VISITOR_TYPE_VISITOR));
     $this->getSelect()->columns(['visitor_type' => $expression]);
     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);
 }
コード例 #4
0
 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->depersonalizeChecker->checkIfDepersonalize($subject)) {
         $this->visitor->setSkipRequestLogging(true);
         $this->visitor->unsetData();
         $this->session->clearStorage();
         $this->customerSession->clearStorage();
         $this->session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->formKey);
         $this->customerSession->setCustomerGroupId($this->customerGroupId);
         $this->customerSession->setCustomer($this->customerFactory->create()->setGroupId($this->customerGroupId));
     }
     return $result;
 }
コード例 #5
0
 /**
  * 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;
 }
コード例 #6
0
ファイル: AbstractIndex.php プロジェクト: nja78/magento2
 /**
  * Retrieve visitor id
  *
  * if don't exists return current visitor id
  *
  * @return int
  */
 public function getVisitorId()
 {
     if ($this->hasData('visitor_id')) {
         return $this->getData('visitor_id');
     }
     return $this->_customerVisitor->getId();
 }
コード例 #7
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();
 }
 /**
  * @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);
 }
コード例 #9
0
 public function testBindQuoteDestroy()
 {
     $quote = new \Magento\Framework\Object(['id' => '1']);
     $observer = new \Magento\Framework\Object(['event' => new \Magento\Framework\Object(['quote' => $quote])]);
     $this->visitor->bindQuoteDestroy($observer);
     $this->assertTrue($this->visitor->getDoQuoteDestroy());
 }
コード例 #10
0
 /**
  * Clean visitor's outdated records
  *
  * @param \Magento\Customer\Model\Visitor $object
  * @return $this
  */
 public function clean(\Magento\Customer\Model\Visitor $object)
 {
     $cleanTime = $object->getCleanTime();
     $connection = $this->getConnection();
     $timeLimit = $this->dateTime->formatDate($this->date->gmtTimestamp() - $cleanTime);
     while (true) {
         $select = $connection->select()->from(['visitor_table' => $this->getTable('customer_visitor')], ['visitor_id' => 'visitor_table.visitor_id'])->where('visitor_table.last_visit_at < ?', $timeLimit)->limit(100);
         $visitorIds = $connection->fetchCol($select);
         if (!$visitorIds) {
             break;
         }
         $condition = ['visitor_id IN (?)' => $visitorIds];
         $connection->delete($this->getTable('customer_visitor'), $condition);
     }
     return $this;
 }
コード例 #11
0
ファイル: Item.php プロジェクト: kidaa30/magento2-platformsh
 /**
  * Retrieve Visitor Id
  *
  * @return int
  */
 public function getVisitorId()
 {
     if (!$this->hasData('visitor_id')) {
         $visitorId = $this->_customerVisitor->getId();
         $this->setData('visitor_id', $visitorId);
     }
     return $this->getData('visitor_id');
 }
コード例 #12
0
 /**
  * Add visitor and customer data to compare item
  *
  * @param \Magento\Catalog\Model\Product\Compare\Item $item
  * @return $this
  */
 protected function _addVisitorToItem($item)
 {
     $item->addVisitorId($this->_customerVisitor->getId());
     if ($this->_customerSession->isLoggedIn()) {
         $item->setCustomerId($this->_customerSession->getCustomerId());
     }
     return $this;
 }
コード例 #13
0
 /**
  * Retrieve Where Condition to Index table
  *
  * @return array
  */
 protected function _getWhereCondition()
 {
     $condition = array();
     if ($this->_customerSession->isLoggedIn()) {
         $condition['customer_id'] = $this->_customerSession->getCustomerId();
     } elseif ($this->_customerId) {
         $condition['customer_id'] = $this->_customerId;
     } else {
         $condition['visitor_id'] = $this->_customerVisitor->getId();
     }
     return $condition;
 }
コード例 #14
0
 /**
  * @return void
  */
 public function testCustomerLoginLoggedInFalse()
 {
     $observerMock = $this->getObserverMock(111);
     $this->customerSessionMock->expects($this->once())->method('isLoggedIn')->willReturn(false);
     $this->customerSessionMock->expects($this->never())->method('getCustomerId');
     $this->customerVisitorMock->expects($this->never())->method('getId');
     $this->productCompModelMock->expects($this->never())->method('updateCustomerFromVisitor')->willReturnSelf();
     $this->productCompModelMock->expects($this->never())->method('calculate')->willReturnSelf();
     $this->productIndexMock->expects($this->never())->method('updateCustomerFromVisitor')->willReturnSelf();
     $this->productIndexMock->expects($this->never())->method('calculate')->willReturnSelf();
     $this->observer->execute($observerMock);
 }
コード例 #15
0
 /**
  * After generate Xml
  *
  * @param \Magento\Framework\View\LayoutInterface $subject
  * @param \Magento\Framework\View\LayoutInterface $result
  * @return \Magento\Framework\View\LayoutInterface
  */
 public function afterGenerateXml(\Magento\Framework\View\LayoutInterface $subject, $result)
 {
     if ($this->moduleManager->isEnabled('Magento_PageCache') && $this->cacheConfig->isEnabled() && !$this->request->isAjax() && $subject->isCacheable()) {
         $this->visitor->setSkipRequestLogging(true);
         $this->visitor->unsetData();
         $this->session->clearStorage();
         $this->customerSession->clearStorage();
         $this->session->setData(\Magento\Framework\Data\Form\FormKey::FORM_KEY, $this->formKey);
         $this->customerSession->setCustomerGroupId($this->customerGroupId);
         $this->customer->setGroupId($this->customerGroupId);
         $this->customerSession->setCustomer($this->customer);
     }
     return $result;
 }
コード例 #16
0
 public function testAfterGenerateXmlNoDepersonalize()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', [], [], '', false);
     $this->depersonalizeCheckerMock->expects($this->once())->method('checkIfDepersonalize')->willReturn(false);
     $this->visitorMock->expects($this->never())->method('setSkipRequestLogging');
     $this->visitorMock->expects($this->never())->method('unsetData');
     $this->sessionMock->expects($this->never())->method('clearStorage');
     $this->customerSessionMock->expects($this->never())->method('clearStorage');
     $this->customerSessionMock->expects($this->never())->method('setCustomerGroupId');
     $this->customerMock->expects($this->never())->method('setGroupId');
     $this->sessionMock->expects($this->never())->method('setData');
     $this->customerSessionMock->expects($this->never())->method('setCustomer');
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertSame($expectedResult, $actualResult);
 }
コード例 #17
0
 /**
  * @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);
 }
コード例 #18
0
 /**
  * Retrieve Product Compare items collection
  *
  * @return \Magento\Catalog\Model\ResourceModel\Product\Compare\Item\Collection
  */
 public function getItems()
 {
     if ($this->_items === null) {
         $this->_compareProduct->setAllowUsedFlat(false);
         $this->_items = $this->_itemCollectionFactory->create();
         $this->_items->useProductItem(true)->setStoreId($this->_storeManager->getStore()->getId());
         if ($this->httpContext->getValue(Context::CONTEXT_AUTH)) {
             $this->_items->setCustomerId($this->currentCustomer->getCustomerId());
         } elseif ($this->_customerId) {
             $this->_items->setCustomerId($this->_customerId);
         } else {
             $this->_items->setVisitorId($this->_customerVisitor->getId());
         }
         $this->_items->addAttributeToSelect($this->_catalogConfig->getProductAttributes())->loadComparableAttributes()->addMinimalPrice()->addTaxPercents()->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds());
     }
     return $this->_items;
 }
コード例 #19
0
ファイル: Compare.php プロジェクト: shabbirvividads/magento2
 /**
  * Calculate cache product compare collection
  *
  * @param bool $logout
  * @return $this
  */
 public function calculate($logout = false)
 {
     /** @var $collection Collection */
     $collection = $this->_itemCollectionFactory->create()->useProductItem(true);
     if (!$logout && $this->_customerSession->isLoggedIn()) {
         $collection->setCustomerId($this->_customerSession->getCustomerId());
     } elseif ($this->_customerId) {
         $collection->setCustomerId($this->_customerId);
     } else {
         $collection->setVisitorId($this->_customerVisitor->getId());
     }
     /* Price data is added to consider item stock status using price index */
     $collection->addPriceData()->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds());
     $count = $collection->getSize();
     $this->_catalogSession->setCatalogCompareItemsCount($count);
     return $this;
 }
コード例 #20
0
 public function testClean()
 {
     $this->resource->expects($this->once())->method('clean')->with($this->visitor)->will($this->returnSelf());
     $this->visitor->clean();
 }
コード例 #21
0
ファイル: User.php プロジェクト: halk/recowise-magento2-demo
 /**
  * Generates user ID from Magento's visitor model
  * @return string
  */
 public function getUserIdByVisitor()
 {
     return md5($this->_customerVisitor->getId());
 }