在Magento畅销书脚本中分为零

时间:2013-04-25 10:17:03

标签: magento division zero

我发现这个脚本用于显示magentos畅销书,但我在第135和163行得到了 ERR(3):警告:除零(参见下面的代码)。我一直试图解决它并放弃它,但我的错误日志中的警告让我感到困惑。有人可以看看,看看他们是否能告诉我什么是错的?感谢

<?php

/**
 * @author Branko Ajzele | http://activecodeline.com | branko.ajzele@surgeworks.com
 * @license GPL
 */

/**
*
*
05/06/2011 Modified by Erik Gabor | erikvail@gmail.com | 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 ?>

1 个答案:

答案 0 :(得分:1)

$ _ columnCount是null0所以它会抛出除零错误。

$_columnCount更改为1,一切正常。