예제 #1
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->_customerVisitor->getId());
         }
         $this->_items->addAttributeToSelect($this->_catalogConfig->getProductAttributes())->loadComparableAttributes()->addMinimalPrice()->addTaxPercents()->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds());
     }
     return $this->_items;
 }
예제 #2
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->_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;
 }
예제 #3
0
 /**
  * @return \Magento\Catalog\Model\Resource\Product\Compare\Item\Collection
  */
 protected function _createProductCompareCollection()
 {
     return $this->_itemsCompareFactory->create();
 }
예제 #4
0
 /**
  * Retrieve Compare Items Collection
  *
  * @return Collection
  */
 public function getItemCollection()
 {
     return $this->_itemCollectionFactory->create();
 }