1

custom filter of getLoadedProductCollection() function,

getSize() method does not give correct value

$this->getCollection()->getSize()
  • Can you share the custom filter code – Saravanan DS May 22 '18 at 11:46
  • $_productCollection = $_productCollection->addAttributeToFilter('name', array( array('like' => '%'.$search_txt.'%') )); where variable $search_txt is input from user – Alam Zaib May 22 '18 at 11:49
  • where you try to get count phtml or block class? – Amit Bera May 22 '18 at 11:51
  • @AlamZaib check my answer I think it will help you. – Nikunj Vadariya May 22 '18 at 11:52
  • use count() instead of getSize(), for the getSize() the collection is not loaded, for count() it is. look magento.stackexchange.com/a/4039/48355 – PЯINCƏ May 22 '18 at 11:54
1

You can do it like this

$_productCollection = $_productCollection->addAttributeToFilter('name', array( array('like' => '%'.$search_txt.'%') ));

Clone the collection object

$clone = clone $_productCollection;

Get the total size from the clone.

echo $clone->getSize();
  • it is not giving me correct number , – Alam Zaib May 22 '18 at 12:13
  • 1
    @AlamZaib past your full code to your question so we can check it and help you. – Nikunj Vadariya May 22 '18 at 12:15
  • Collection are cached, using a clone should reinitiate the cache. However using getSize() is correct. See info.magento.com/rs/magentocommerce/images/… – B00MER May 23 '18 at 1:34
-1

Please Use -

$totalProduct = count($this->getCollection()->getData());

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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