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())); }
/** * 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(); }
/** * 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'); }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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; }