0

Collection

protected function _getProductCollection()
{
        $tagModel = $this->tagTagFactory->create();
        $this->_productCollection = $this->_productCollection
            ->addAttributeToSelect($this->_catalogConfig->getProductAttributes())
            ->addTagFilter($this->getTag()->getId())
            ->addStoreFilter($this->_storeManager->getStore()->getId())
           // ->addMinimalPrice()
            ->addUrlRewrite()
            ->setActiveFilter();


      $this->_productCollection->addAttributeToFilter('status', ['in' => 
      $this->_productStatus->getVisibleStatusIds()]);
      $this->_productCollection->setVisibility($this->_productVisibility->getVisibleInSiteIds());
      return $this->_productCollection;
}

I am trying to get $this->_productCollection->getSize() which doesnot reflect proper result.

6
  • Did you want count of product? Commented Apr 4, 2019 at 7:18
  • Yes by using getSize()
    – Unknown
    Commented Apr 4, 2019 at 7:19
  • Without using ->addTagFilter($this->getTag()->getId()) and check ` $this->_productCollection->getSize()` give proper value and or use $this->_productCollection->count() getting proper data
    – Amit Bera
    Commented Apr 4, 2019 at 7:32
  • @AmitBera i remove ->addTagFilter($this->getTag()->getId()) but not working and i want to get value using getSize() for toolbar data
    – Unknown
    Commented Apr 4, 2019 at 8:42
  • @AmitBera Can u please suggest me another solution
    – Unknown
    Commented Apr 4, 2019 at 9:21

1 Answer 1

0

Have you tried $this->_productCollection->count()

2
  • Yes tried but still not working. Can u suggest me some way to use getSelectCountSql()
    – Unknown
    Commented Apr 5, 2019 at 4:27
  • @Parthavi is the collection returning any results? count() should give you the number of results returned by the collection. Can you please edit your post to include your entire class file. I'd like to see the constructor.
    – NSwanson7
    Commented Apr 5, 2019 at 13:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.