Ejemplo n.º 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()));
 }
Ejemplo n.º 2
0
 /**
  * Get customer's current status
  *
  * @return string
  */
 public function getCurrentStatus()
 {
     $log = $this->getCustomerLog();
     $interval = $this->modelLog->getOnlineMinutesInterval();
     if ($log->getLogoutAt() || strtotime($this->dateTime->now()) - strtotime($log->getLastVisitAt()) > $interval * 60) {
         return __('Offline');
     }
     return __('Online');
 }
Ejemplo n.º 3
0
 /**
  * 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->_logVisitor->getId();
 }
Ejemplo n.º 4
0
 /**
  * Retrieve Visitor Id
  *
  * @return int
  */
 public function getVisitorId()
 {
     if (!$this->hasData('visitor_id')) {
         $visitorId = $this->_logVisitor->getId();
         $this->setData('visitor_id', $visitorId);
     }
     return $this->getData('visitor_id');
 }
Ejemplo n.º 5
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->_logVisitor->getId());
     if ($this->_customerSession->isLoggedIn()) {
         $item->setCustomerId($this->_customerSession->getCustomerId());
     }
     return $this;
 }
Ejemplo n.º 6
0
 public function testLogVisitorActivity()
 {
     $visitor = $this->getMockBuilder('Magento\\Customer\\Model\\Visitor')->disableOriginalConstructor()->getMock();
     $visitor->expects($this->once())->method('setData')->will($this->returnSelf());
     $visitor->expects($this->once())->method('getData')->will($this->returnValue(['visitor_id' => 1]));
     $event = new \Magento\Framework\Object(['visitor' => $visitor]);
     $observer = new \Magento\Framework\Object(['event' => $event]);
     $this->assertSame($this->visitor, $this->visitor->logVisitorActivity($observer));
 }
Ejemplo n.º 7
0
 /**
  * Test afterGenerateXml method with enabled module PageCache and request is Ajax and Layout is not cacheable
  */
 public function testAfterGenerateXmlLayoutIsNotCacheable()
 {
     $expectedResult = $this->getMock('Magento\\Framework\\View\\Layout', array(), array(), '', false);
     $this->moduleManagerMock->expects($this->once())->method('isEnabled')->with($this->equalTo('Magento_PageCache'))->will($this->returnValue(true));
     $this->cacheConfigMock->expects($this->once())->method('isEnabled')->will($this->returnValue(true));
     $this->requestMock->expects($this->once())->method('isAjax')->will($this->returnValue(false));
     $this->layoutMock->expects($this->once())->method('isCacheable')->will($this->returnValue(false));
     $this->visitorMock->expects($this->never())->method('setSkipRequestLogging');
     $actualResult = $this->plugin->afterGenerateXml($this->layoutMock, $expectedResult);
     $this->assertSame($expectedResult, $actualResult);
 }
Ejemplo n.º 8
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->_logVisitor->getId();
     }
     return $condition;
 }
Ejemplo n.º 9
0
 public function testBindCustomerLogout()
 {
     $observer = new \Magento\Framework\Object();
     $this->_model->setCustomerId('1');
     $this->_model->bindCustomerLogout($observer);
     $this->assertTrue($this->_model->getDoCustomerLogout());
     $this->_model->unsetData();
     $this->_model->bindCustomerLogout($observer);
     $this->assertNull($this->_model->getDoCustomerLogout());
 }
Ejemplo n.º 10
0
 /**
  * Customer login action
  *
  * @param \Magento\Framework\Event\Observer $observer
  * @return $this
  */
 public function customerLogin(\Magento\Framework\Event\Observer $observer)
 {
     if (!$this->_customerSession->isLoggedIn()) {
         return $this;
     }
     $visitorId = $this->_logVisitor->getId();
     $customerId = $this->_customerSession->getCustomerId();
     $eventModel = $this->_eventFactory->create();
     $eventModel->updateCustomerType($visitorId, $customerId);
     $this->_productCompFactory->create()->updateCustomerFromVisitor()->calculate();
     $this->_productIndxFactory->create()->updateCustomerFromVisitor()->calculate();
     return $this;
 }
Ejemplo n.º 11
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;
 }
Ejemplo n.º 12
0
 /**
  * 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->_logVisitor->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;
 }
Ejemplo n.º 13
0
 /**
  * Retrieve Product Compare items collection
  *
  * @return \Magento\Catalog\Model\Resource\Product\Compare\Item\Collection
  */
 public function getItems()
 {
     if (is_null($this->_items)) {
         $this->_compareProduct->setAllowUsedFlat(false);
         $this->_items = $this->_itemCollectionFactory->create();
         $this->_items->useProductItem(true)->setStoreId($this->_storeManager->getStore()->getId());
         if ($this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
             $this->_items->setCustomerId($this->currentCustomer->getCustomerId());
         } elseif ($this->_customerId) {
             $this->_items->setCustomerId($this->_customerId);
         } else {
             $this->_items->setVisitorId($this->_logVisitor->getId());
         }
         $this->_items->addAttributeToSelect($this->_catalogConfig->getProductAttributes())->loadComparableAttributes()->addMinimalPrice()->addTaxPercents()->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds());
     }
     return $this->_items;
 }
Ejemplo n.º 14
0
 /**
  * Saving information about quote
  *
  * @param   \Magento\Log\Model\Visitor $visitor
  * @return  \Magento\Log\Model\Resource\Visitor
  */
 protected function _saveQuoteInfo($visitor)
 {
     $adapter = $this->_getWriteAdapter();
     if ($visitor->getDoQuoteCreate()) {
         $data = new \Magento\Framework\Object(array('quote_id' => (int) $visitor->getQuoteId(), 'visitor_id' => (int) $visitor->getId(), 'created_at' => $this->_date->gmtDate()));
         $bind = $this->_prepareDataForTable($data, $this->getTable('log_quote'));
         $adapter->insert($this->getTable('log_quote'), $bind);
         $visitor->setDoQuoteCreate(false);
     }
     if ($visitor->getDoQuoteDestroy()) {
         /**
          * We have delete quote from log because if original quote was
          * deleted and Mysql restarted we will get key duplication error
          */
         $condition = array('quote_id = ?' => (int) $visitor->getQuoteId());
         $adapter->delete($this->getTable('log_quote'), $condition);
         $visitor->setDoQuoteDestroy(false);
         $visitor->setQuoteId(null);
     }
     return $this;
 }