Magento:如何在猫头鹰旋转木马上展示产品

时间:2017-03-20 08:40:50

标签: magento magento-1.9 owl-carousel-2

我正在使用magento 1.9.3,我想在猫头鹰旋转木马的主页上显示特色产品。

我的模块块中有一个方法,它返回我想在旋转木马中显示的集合。我从我的模板中这样称呼它:

$_productCollection=$this->getFeaturedProducts();

我在堆栈溢出中发现了前一个问题:Owl Carousel - Magento Products

并且在上一个问题之后,我在模板中找到了这个问题:

<div class="owl-carousel">
    <?
        $products = $this->getFeaturedProducts();
        foreach ($products as $_product) { // iterate through the entire collection
            echo '<div class="item"><img src='.$this->helper('catalog/image')->init($_product, 'small_image')->keepFrame(false)->resize($_imgSize).'></div>'; // print the image url inside of the required Owl markup
        }
    ?>
</div>

但是没有显示owl-carousel的div。如果我检查页面,div就在那里,里面的图像也没有显示。如果我删除了owl-carousel类,我会看到列表中显示的所有图像。

我从magento connect安装了“Responsive Owl Slider”扩展程序,我在页面顶部有另一个猫头鹰轮播,用管理cms显示图像幻灯片(不是产品),它运行正常。唯一失败的是我试图用代码做的那个。

我看到owl-carousel类有一个display: none所以显然没有显示任何内容,但是如果我删除display: none它会同时显示所有图像,而不是旋转木马

如何在猫头鹰旋转木马中显示我选择的产品?

2 个答案:

答案 0 :(得分:0)

请尝试此扩展程序

  

https://www.magentocommerce.com/magento-connect/new-products-2.html

     

希望它对你有所帮助。

答案 1 :(得分:0)

首先转到链接&gt;&gt; https://magento.stackexchange.com/questions/83912/featured-products-on-homepage

  
    

将所有文件创建为以下答案。

         

然后打开featured.phtml

  

复制并粘贴代码

<?php
    $_helper = $this->helper('catalog/output');
    $_productCollection = $this->getProductCollection();
?>
<div class="featured-products">
    <ol class="featured-products-list owl-carousel" id="featured-products-list">
    <?php foreach ($_productCollection as $_product): ?>
        <li><img src="<?php echo $this->helper('catalog/image')->init($_product, 'thumbnail')->resize(200) ?>"  alt="<?php echo $this->escapeHtml($_product->getName()) ?>" /></li>
    <?php endforeach; ?>
    </ol>
</div>
<script type="text/javascript">
    jQuery(document).ready(function(){
  jQuery(".owl-carousel").owlCarousel();
});
</script>

请不要忘记创建属性并为产品分配。