Деление на ноль в Magento Bestseller Script

Я нашел этот скрипт для отображения бестселлеров magentos, но получаю ERR (3): Предупреждение: деление на ноль в строке 135 и 163 (см. код ниже). Я пытался исправить это несколько часов и отказался от этого, но предупреждение в моих журналах ошибок меня беспокоит. Может кто-нибудь посмотреть и посмотреть, могут ли они сказать мне, что не так? Спасибо

<?php

/**
 * @author Branko Ajzele | http://activecodeline.com | [email protected]
 * @license GPL
 */

/**
*
*
05/06/2011 Modified by Erik Gabor | [email protected] | http://www.mage-contacts.com
* @license GPL

*/ 

$storeId = Mage::app()->getStore()->getId();

$totalPerPage = ($this->show_total) ? $this->show_total :1;
$counter = 1;
$visibility = array(
                      Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                      Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
                  );

$storeId = Mage::app()->getStore()->getId();
$_productCollection = Mage::getResourceModel('reports/product_collection')
                              ->addAttributeToSelect('*')
                              ->setStoreId($storeId)
                  ->addStoreFilter($storeId)
                              ->addOrderedQty()
                              ->addAttributeToFilter('visibility', $visibility);


        if ($current_category = Mage::registry('current_category'))
    $_productCollection->addCategoryFilter($current_category);
    $_productCollection->setPage(1,$totalPerPage);  
        $_productCollection->setOrder('ordered_qty', 'desc');

        Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
        Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($_productCollection);

        $_helper = $this->helper('catalog/output');


//Mage_Reports_Model_Mysql4_Product_Collection
?>

<?php

 $_collectionSize = $_productCollection->count();


 if($current_category && $_collectionSize) :

?>
<div class="block">
<div class="block-title">
<strong><span><?php echo $current_category->getName()  ?> <?php echo $this->__('Bestseller') ?></span></strong>
</div>
<?php else: ?>
<div class="block">
<div class="block-title">
<strong><span> <?php echo $this->__('Bestseller') ?></span></strong>
</div>
 <?php endif;?>
  <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
RIGHT HERE LINE 135 ---->   <?php if ($i++%$_columnCount==0): ?>
        <ul>
        <?php endif ?>
            <li id="category-bettseller">
                <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')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(195); ?>" width="195" height="284" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>

                <h2 class="product-name" style="float:left;width:180px;margin:7px"><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>
                 <div style="float:left;width:180px;margin:7px">
                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>
                <?php  echo Mage::helper('core')->currency($_product->getPrice()) ?>

                    <?php if($_product->isSaleable()): ?>
                        <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add', array('product' => $_product->getId())) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif; ?>
                    <ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a id="wish" href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                        <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            <li><a id="compare" href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul>
                </div>
            </li>
RIGHT HERE LINE 163------>   <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
</div>
        <?php endif ?>
        <?php endforeach ?>

person qrs    schedule 25.04.2013    source источник
comment
Проверьте значение $_columnCount, оно должно быть 0   -  person Kalpesh    schedule 25.04.2013
comment
Это понял. Я изменил $_columnCount = $this->getColumnCount(); в $_columnCount = 1; а ошибка уже история. Спасибо   -  person qrs    schedule 25.04.2013
comment
Большой! Я просто опубликовал это как ответ.   -  person Kalpesh    schedule 25.04.2013


Ответы (1)


$_columnCount был либо null, либо 0, поэтому он выдавал ошибку деления на ноль.

Изменил $_columnCount на 1, и все работает нормально.

person Kalpesh    schedule 25.04.2013