Magento只显示产品与图像在主页上


Magento Only show products with image on home page

I m working with random products on my homepage and i m试图只显示有图片和库存的产品。通过使用下面的代码,我设法让它只显示带有图像和库存的产品:

<?php
 $products_noimage = Mage::getModel('catalog/product')
    ->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('image', array('neq' => 'no_selection'));     
 ?>
<?php foreach ($_productCollection as $_product): ?>
<?php  if(!$_product->isSaleable() && $products_noimage && $_product->isInStock())continue; ?>
<?php //if criteria is meet show products below     
?>

但我的问题是,当主页加载时,有时它会在网格中只显示1或2个产品,因为我有很多没有图像和缺货的产品,我认为页面正在加载缺货产品,没有图像,但只显示1或2个有图像和缺货的产品。

示例:页面将从这16个产品中加载16个产品,其中只有2个有图像和库存,其余的不符合此标准。

如何避免它,而不是只加载符合标准的2个产品,依次加载其他符合这些标准的产品(包括图像和库存).

或者它永远不会工作,因为我正在使用列表。php block ?

{{block type="catalog/product_list_random"        template="catalog/product/productrandomhom.phtml"}}      

如果有人有一个解决方案来过滤随机产品在首页感觉分享=)

你的逻辑有问题

首先从app/code/core/Mage/Catalog/Block/Product/List复制Random.phpto app/code/local/Mage/Catalog/Block/Product/List

然后goto函数和图像滤波器in _getProductCollection()

from $collection = Mage::getResourceModel('catalog/product_collection');

$collection = Mage::getResourceModel('catalog/product_collection')
        ->addAttributeToFilter('image', array('neq' => 'no_selection'));

,你只展示有销路的产品和库存

if ($ _product -> isSaleable (),,_product -> isInStock其他()= = 1){}{继续;}

试试这段代码

<?php

$products_noimage = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('*') ->addAttributeToFilter('image', array('neq' => 'no_selection'));
?>

<?php foreach ($_productCollection as $_product): ?><?php if(!$_product->isSaleable() && $_product->isInStock()==0)continue; ?> //if criteria is meet show products below ?>