I'm running code on my Product List page. First time on page get 4 items. if I refresh page, I'll get 6, then 4, then 5 etc. I can't see any reason for this. I checked my query and it's always same. If someone could point me in the right direction, that would be helpful.

$products = $layer->getProductCollection()
  • What is $numbers in your code? how do you get it? – Jaimin Sutariya Feb 11 '17 at 3:04
  • They are a list of part numbers that I get from another api call. This is set up as an attribute. The query from Magento DB always returns 18 items, but when I view $products->getItems(). Sometimes it has 4,5, or 6 items. It varies almost every time – jstrez77 Feb 11 '17 at 6:19
  • If you can log your collection query with code $product->printLogQuery(true); after you get collection and match each time it changes item count. – Jaimin Sutariya Feb 11 '17 at 6:25
  • Did that, the queries are exact but one returned 4 and the next returned 5. It's the internal _items array that keeps changing – jstrez77 Feb 11 '17 at 6:36
  • Do you have URL for this? Because of queries are correct it should give you same results. – Jaimin Sutariya Feb 11 '17 at 6:38

Figured out this was due to a couple issues. Trying to filter on an attribute that wasn't added to search_results.xml. I added that as a field and it still didn't work at first, but then I changed the code to use addFieldToFilter and it worked. I was also trying to use a custom collection and it didn't support paging. I changed it back to the productCollection.

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.