如何用magento在主页左侧显示特色产品

时间:2014-08-23 10:21:07

标签: magento magento-1.8

我想在主页的左侧显示所有特色产品。我添加了一个属性'特色'在特色产品的管理员中。现在我想显示那些特色属性设置为“是”的产品。 我在前端创建了一个页面featured.phtml并编写了这段代码

<?php
        function cut_string($string,$number){
            if(strlen($string) <= $number) {
                return $string;
            }
            else {  
                if(strpos($string," ",$number) > $number){
                    $new_space = strpos($string," ",$number);
                    $new_string = substr($string,0,$new_space)."..";
                    return $new_string;
                }
                $new_string = substr($string,0,$number)."..";
                return $new_string;
            }
        }
    ?>
<?php if($this->getConfig('enabled')){ // start enable module?> 
    <?php $this->getProducts() ?>
    <?php $_productCollection=$this->getProductCollection() ?>
    <div class="ma-featured-products">  <!-- start mt products list -->
        <?php if($this->getConfig('title')){?>
            <div class="ma-featured-product-title"><h2><?php echo $this->getConfig('title')?></h2></div>
        <?php }?>
        <?php if(!$_productCollection->count()): ?> <!-- start if exist product -->
            <p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
        <?php else: ?>
            <div class="featured-products">
                <?php $_collectionSize = $_productCollection->count() ?>
                <?php if( !$this->getConfig('items') ) { $_columnCount = 1 ; } else { $_columnCount = $this->getConfig('items'); }?>
                <?php $i=0; foreach ($_productCollection as $_product): ?>
                    <?php if ( $i++ % $_columnCount==0): ?>
                    <ul class="products-grid <?php if( $i == 1 ) echo ' first';?>">
                    <?php endif ?>
                        <?php 
                            if ( !$this->getConfig('width') ){
                                $w=135;
                            } else {
                                $w = $this->getConfig('width');
                            }
                            if( !$this->getConfig('height') ){
                                $h=135;
                             }
                            else {
                                $h = $this->getConfig('height');
                            }
                        ?>
                        <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
                            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" class="product-image"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($w,$h); ?>" width="<?php echo $w?>" height="<?php echo $h?>" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" /></a>
                            <div class="box-feature">
                        <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h2>
                        <?php if ( $this->getConfig('review') ): ?>
                        <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                        <?php endif; ?>
                        <?php echo $this->getPriceHtml($_product, true) ?>
                        <div class="actions">
                            <?php if ($this->getConfig('addtocart')) { ?>
                                        <?php if($_product->isSaleable()): ?>
                                            <button type="button" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><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; ?>
                            <?php }?>
                            <?php if( $this->getConfig('addtowishlist') || $this->getConfig('addtocompare')){?>
                                        <ul class="add-to-links">
                                            <?php if( $this->getConfig('addtowishlist')){?>
                                            <?php if ($this->helper('wishlist')->isAllow()) : ?>
                                                <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('+ Wishlist') ?></a></li>
                                            <?php endif; ?>
                                            <?php } ?>
                                            <?php if( $this->getConfig('addtocompare') ){?>
                                            <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                                                <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('+ Compare') ?></a></li>
                                            <?php endif; ?>
                                            <?php }?>
                                        </ul>
                            <?php }?>
                        </div>
                        <?php if( $this->getConfig('description')){?>
                        <div class="ma-desc">
                            <?php if(!$this->getConfig('maxlength')){?>
                            <?php echo nl2br($this->htmlEscape($_product->getShortDescription())) ?>
                            <?php } else {?>
                            <?php echo nl2br(cut_string($this->htmlEscape($_product->getShortDescription()),$this->getConfig('maxlength'))) ?>                      
                            <?php }?>                               
                        </div>
                    </div>
                            <?php }?>
                        </li>
                    <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
                    </ul>
                <?php endif ?> <!--  -->
                <?php endforeach ?>
                <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>              
            </div>      
        <?php endif; ?> <!-- end exist product -->
    </div> <!-- end products list -->
<?php } ?>

但问题是它正在调用页面但显示

There are no products matching the selection.

它没有进入其他条件。当我echo $_collectionSize = $_productCollection->count()时,它显示0意味着它没有得到任何产品。我不明白我在哪里做错了。 如果有人知道那么请帮助我。 谢谢!

0 个答案:

没有答案