예제 #1
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;
 }
예제 #2
0
 /**
  * Retrieve compare list items collection
  *
  * @return Collection
  */
 public function getItemCollection()
 {
     if (!$this->_itemCollection) {
         // cannot be placed in constructor because of the cyclic dependency which cannot be fixed with proxy class
         // collection uses this helper in constructor when calling isEnabledFlat() method
         $this->_itemCollection = $this->_itemCollectionFactory->create();
         $this->_itemCollection->useProductItem(true)->setStoreId($this->_storeManager->getStore()->getId());
         if ($this->_customerSession->isLoggedIn()) {
             $this->_itemCollection->setCustomerId($this->_customerSession->getCustomerId());
         } elseif ($this->_customerId) {
             $this->_itemCollection->setCustomerId($this->_customerId);
         } else {
             $this->_itemCollection->setVisitorId($this->_customerVisitor->getId());
         }
         $this->_itemCollection->setVisibility($this->_catalogProductVisibility->getVisibleInSiteIds());
         /* Price data is added to consider item stock status using price index */
         $this->_itemCollection->addPriceData();
         $this->_itemCollection->addAttributeToSelect('name')->addUrlRewrite()->load();
         /* update compare items count */
         $this->_catalogSession->setCatalogCompareItemsCount(count($this->_itemCollection));
     }
     return $this->_itemCollection;
 }