0

下面的脚本有一个奇怪的问题。我整天都在努力。我正在尝试在 Magento 购物车的产品视图页面的侧栏中显示每个类别的畅销商品。此脚本在 IE(全部)中有效,但不一样。实际上 IE 做对了,而我尝试过的所有其他浏览器都做错了。

这就是问题所在。它是 php,而 php 应该是一种服务器端语言。但似乎 IE 收到了不同的信息。在下面,您会注意到我在一个部分周围有一个红色边框,在另一部分周围有一个绿色边框。IE 得到红色边框,其余的得到绿色边框。红色边框具有“类别名称”,它在 IE 中工作,但绿色边框......如果我为类别名称放置脚本,它会打印一条错误消息。

除了我得到的多个“被零除”警告(不知道为什么)我想知道如果 php 是一种服务器端语言,为什么两种浏览器会收到两条不同的消息!?

谢谢

<?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

/**
 * Each product in foreach loop is array of following fields
 *

Array
(
    [ordered_qty] => 2.0000
    [entity_id] => 150
    [entity_type_id] => 10
    [attribute_set_id] => 62
    [type_id] => simple
    [sku] => 500gb7200
    [category_ids] => 29,36
    [created_at] => 2008-07-25 01:12:44
    [updated_at] => 2008-07-25 02:09:26
    [has_options] => 0
    [visibility] => 4
    [hardrive] => 500 GB
    [meta_keyword] =>
    [description] => 500GB- 7200RPM, SATA 3.0Gb/s, 32MB Cache
    [short_description] => 500GB - 7200RPM, SATA 3.0Gb/s, 32MB Cache
    [custom_layout_update] =>
    [status] => 1
    [tax_class_id] => 1
    [manufacturer] => 118
    [weight] => 1.0000
    [price] => 299.0000
    [name] => Western Digital 500GB HD - 7200RPM
    [url_key] => 500gb-7200rpm
    [gift_message_available] => 2
    [harddrive_speed] => 7200 rpm
    [meta_title] =>
    [meta_description] =>
    [thumbnail] => /w/e/western-digital-500gb-hd-7200rpm.jpg
    [small_image] => /w/e/western-digital-500gb-hd-7200rpm.jpg
    [image] => /w/e/western-digital-500gb-hd-7200rpm.jpg
    [custom_design] =>
    [options_container] => container2
    [stock_item (Mage_CatalogInventory_Model_Stock_Item)] => Array
        (
            [item_id] => 119
            [product_id] => 150
            [stock_id] => 1
            [qty] => 999994.0000
            [min_qty] => 0.0000
            [use_config_min_qty] => 1
            [is_qty_decimal] => 0
            [backorders] => 0
            [use_config_backorders] => 1
            [min_sale_qty] => 1.0000
            [use_config_min_sale_qty] => 1
            [max_sale_qty] => 0.0000
            [use_config_max_sale_qty] => 1
            [is_in_stock] => 1
            [low_stock_date] => 0000-00-00 00:00:00
            [use_config_notify_stock_qty] => 1
            [manage_stock] => 0
            [use_config_manage_stock] => 1
            [product (Mage_Catalog_Model_Product)] => *** RECURSION ***
        )

    [is_salable] => 1
)


 */
 $_collectionSize = $_productCollection->count();


 if($current_category && $_collectionSize) :

?>
<div class="block" style="border:1px solid red">
<div class="block-title">
<strong><span><?php echo $current_category->getName()  ?> <?php echo $this->__('Bestseller') ?></span></strong>
</div>
<?php else: ?>
<div class="block" style="border:1px solid green">
<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): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul>
        <?php endif ?>
            <li class="">
                <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>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
</div>
        <?php endif ?>
        <?php endforeach ?>
4

1 回答 1

0

没有足够的信息来快速调试您的问题(这段代码在哪里,它是如何运行的),但这里有两个快速建议可能会为您指明正确的方向。

首先,保存 Web 浏览器的源代码(使用 View -> Source)命令(而不是各种 Web 检查器,它们有时会将 DOM 调整为正确的形式)并比较两个浏览器的输出。您可能会遇到输出相同的情况但是有关 CSS 规则和 javascript 的某些内容会导致浏览器页面看起来不同。

如果页面中存在差异,那么可能发生的情况是浏览器从 IE 与您的其他浏览器向 PHP 发送不同的信息和/或在不同浏览器中的 PHP 会话中有不同的信息导致 PHP 代码出现有不同的结果。

希望有帮助。

于 2013-01-11T22:56:40.617 回答