首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >销售产品不显示标题,如果没有退货。

问销售产品不显示标题,如果没有退货。
EN

Stack Overflow用户
提问于 2014-05-22 12:13:47
回答 1查看 71关注 0票数 0

我有这段代码,它显示了4种正在出售的产品,但是我想要将它包装在一个IF语句中,基本上是说如果没有产品,那么什么都不要显示。例如,fi没有产品,它仍然显示标题为“这些伟大的产品正在销售”。我知道这似乎是一个简单的任务,但当您没有真正使用PHP,那么它是非常有压力的。

代码语言:javascript
复制
<?php
Mage::getSingleton('core/session', array('name' => 'frontend'));
$_category = Mage::registry('current_category');
            $currentCategoryId= $_category->getId();

$_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addMinimalPrice()
            ->addCategoryFilter($_category)
            ->addStoreFilter();

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


$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);

$_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
    ->addAttributeToFilter('special_to_date', array('or'=> array(
    0 => array('date' => true, 'from' => $tomorrowDate),
    1 => array('is' => new Zend_Db_Expr('null')))
    ), 'left');

?>

<div class="for_sale_div">
<!--heading for sale products-->

<h1 class="sale_title"> These Great Products Are On Sale</h1>

<!-- set it into a grid format -->
<div class="products-grid two_columns_5">

<?php $_collectionSize = $_productCollection->count() ?>
<?php $i=0; foreach($_productCollection as $_product):?>
<?php if($i++%3==0): ?>

<ol class="grid">
 <?php endif; ?>

<li class="item">


<p class="product-image">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>"
                        width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>"
                        title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
                    </a>
                </p>
                <h5><a href="<?php echo $_product->getProductUrl() ?>" 
                title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <?php echo $this->htmlEscape($_product->getName()) ?></a></h5>

                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>

                <?php echo $this->getPriceHtml($_product, true) ?>
                 </li>

        <?php if($i%3==0 || $i==$_collectionSize): ?>
        </ol>
        <?php endif; ?>
    <!-- Set the product count to 4-->
    <?php if($this->getIsHomepage() && $i==4) break; ?>

 <?php endforeach ?>
 </div>
 </div>

如果你能帮忙的话谢谢你。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-22 12:19:34

如果没有从收藏中返回的产品,则不希望显示标题,则可以这样做

代码语言:javascript
复制
<?php if($_productCollection->count() > 0):?>
<h1 class="sale_title"> These Great Products Are On Sale</h1>
<?php endif;?>

您可以在此<div>条件下包装任何您想要的IF。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23806528

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档