1

Fatal error: Call to a member function count() on a non-object in C:\xampp2\htdocs\magento1.9\app\design\frontend\rwd\default\template\catalog\product\list.phtml on line 2

<?php // Grid Mode ?>
<?php $_collectionSize = $_productCollection->count(); ?>
<?php $_columnCount = $this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<ul class="products-grid">
<?php endif; ?>
<li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last <?php endif; ?>"></li>
<!--bof free shipping--->
<?php if ($_product->getAttributeText('new_sale') == "Yes"): ?>
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('new_sale')->toHtml(); ?>
<?php endif; ?>
<!--eof freeshipping-->
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image">
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(153); ?>" width="153" height="153" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
<h2 class="product-name">
<a href="<?php echo  $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?>
</a>
</h2>
<?php if($_product->getRatingSummary()): ?>
<?php echo $this->getReviewsSummaryHtml($_product, 'short'); ?>
<?php endif; ?>
<?php endforeach; ?>
  • 1
    for some reason, $_productCollection is null (or an array). Are you using this template for your own custom module? If so, you should post the code from the block that uses the template. – Marius Sep 6 '16 at 7:14
  • $_productCollection is null. you can print the query use printlogquery(true) – Balaji Setti Sep 6 '16 at 7:21
  • $_productCollection is null or is not object – Minesh Patel Sep 6 '16 at 7:23
  • ok, i change this code, error is solved..but now new error are comes........ Fatal error: Call to a member function productAttribute() on a non-object in C:\xampp2\htdocs\magento1.9\app\design\frontend\rwd\default\template\catalog\product\list.phtml on line 65 – Rushikesh Solanki Sep 6 '16 at 9:38
2

To resolve this error, simply try this one

<?php $_collectionSize = $_productCollection->count(); ?>

to

<?php $_collectionSize = count($_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.