Php 随机产品列表中的自定义图像属性

Php 随机产品列表中的自定义图像属性,php,magento,magento-1.7,Php,Magento,Magento 1.7,我正在使用Magento 1.7.0.2,并试图在随机产品列表中显示我产品中的自定义图像 首先,我将属性添加到所有集合中,并设置一个占位符图像。 在数据库中,我搜索了清单*中的*used?,并将其设置为1 这是我的产品列表\u随机课程: class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List { protected function _getProductCollection

我正在使用Magento 1.7.0.2,并试图在随机产品列表中显示我产品中的自定义图像

首先,我将属性添加到所有集合中,并设置一个占位符图像。 在数据库中,我搜索了清单*中的*used?,并将其设置为1

这是我的产品列表\u随机课程:

class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List
{
    protected function _getProductCollection()
    {
        if (is_null($this->_productCollection)) { 
            $categoryID = $this->getCategoryId();            
            if($categoryID)            {              
                $category = new Mage_Catalog_Model_Category();
                $category->load($categoryID);
                $collection = $category->getProductCollection();
            } else { 
                $collection = Mage::getResourceModel('catalog/product_collection'); 
            }
            Mage::getModel('catalog/layer')->prepareProductCollection($collection);
            $collection->addAttributeToSelect('*');
            $collection->getSelect()->order('rand()');
            $collection->addStoreFilter();
            $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
            $collection->setPage(1, $numProducts)->load();

            $this->_productCollection = $collection;
        }
        return $this->_productCollection;
    }
}
在这里,我尝试添加
$collection->addAttributeToSelect('*')
获取前端图像的url

这就是我目前在前端中尝试的:

$_productCollection=$this->getLoadedProductCollection();
foreach ($_productCollection as $_product):

    echo $this->helper('catalog/image')->init($_product, 'specialprice_image')->resize(158, 270);

    echo $_product->getResource()->getAttribute('specialprice_image')->getFrontend()->getValue($_product);

    echo $_product->getAttributeText('specialprice_image');

    $product = Mage::getModel('catalog/product')->load($_product->getId()); ?>
    echo $product->getAttributeText('specialprice_image');
endforeach;
助手正在给我占位符url。其他方法对我毫无帮助


我希望有人能帮我解决这个问题。

现在它可以在编辑Mage\u Catalog\u Block\u Product\u List\u Random类后工作

我刚刚删除了两行代码:

$collection->addAttributeToSelect('*');
$collection->addStoreFilter();
完整代码:

class Mage_Catalog_Block_Product_List_Random extends Mage_Catalog_Block_Product_List
{
    protected function _getProductCollection()
    {
        if (is_null($this->_productCollection)) { 
            $categoryID = $this->getCategoryId();            
            if($categoryID)            {              
                $category = new Mage_Catalog_Model_Category();
                $category->load($categoryID);
                $collection = $category->getProductCollection();
            } else { 
                $collection = Mage::getResourceModel('catalog/product_collection'); 
            }
            Mage::getModel('catalog/layer')->prepareProductCollection($collection);
            $collection->getSelect()->order('rand()');
            $numProducts = $this->getNumProducts() ? $this->getNumProducts() : 0;
            $collection->setPage(1, $numProducts)->load();

            $this->_productCollection = $collection;
        }
        return $this->_productCollection;
    }
}
在前端,我使用以下代码:

<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
    <img src="<?php echo $this->helper('catalog/image')->init($_product, 'specialprice_image')->resize(158, 270); ?>" width="158" height="270" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
</a>


helper方法是否没有提供您所需的信息,或者您只是想了解其他方法不起作用的原因?我已经上传了一张图片并在productinformation中进行了选择。但是助手给我的是占位符的URL,而不是所选图像的URL。