Example #1
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;
 }