Answer the question
In order to leave comments, you need to log in
How to solve error with Warning: count(): Parameter must be an array or an object that implements Countable in ....?
Magento logs the following errors:
ERR (3): Warning: count(): Parameter must be an array or an object that implements Countable in .../app/code/local/Mage/Catalog/Block/Product/List. php on line 299
Code like this:
/**
* Retrieve block cache tags based on product collection
*
* @return array
*/
public function getCacheTags()
{
$data = array(self::CACHE_TAG);
if ($category = Mage::registry('current_category')) {
$data[] = Mage_Catalog_Model_Category::CACHE_TAG . "_" . $category->getId();
}
!!!Это строка 299 ---> if (count($products = $this->getProductList())) {
foreach ($products as $p) {
$data[] = Mage_Catalog_Model_Product::CACHE_TAG . "_" . $p->getId();
}
}
return $data;
}
public function getCacheLifetime()
{
return ($this->getData('cache_lifetime'))?intval($this->getData('cache_lifetime')):3600;
}
}
Answer the question
In order to leave comments, you need to log in
This error is returned by count when null is passed to it. Prior to php 7.2 it will return 0, but from php 7.2 there will be the described error.
You can fix it like this
$products = $this->getProductList();
if ($products) {
$products = $this->getProductList();
if (is_iterable($products)) {
$products = $this->getProductList();
if (is_countable($products)) {
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question