Magento:Product thumb未加载,而是加载占位符

时间:2013-10-28 19:53:48

标签: magento

我正在努力获得类似产品系列的所有产品大拇指

    $category = Mage::getModel('catalog/category')->load($cat_id);

    $products = Mage::getResourceModel('catalog/product_collection')
            ->setStoreId(1)
            ->setPageSize(10)
            ->addAttributeToFilter(
                    'status', array('eq' => Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
            )
            ->addAttributeToFilter('visibility', Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)
            ->addCategoryFilter($category);

    $productThumbs = array();

    try {
        foreach ($products as $product) {
            $thumbUrl = $product->getThumbnailUrl(200, 60);

            $productThumbs[] = array(
                'entity_id' => $product->getId(),
                'thumb_url' => $thumbUrl
            );
        }
    } catch (Exception $e) {
        error_log($e->getMessage());
    }

它总是返回占位符图像网址......

http://magentohost/magento/media/catalog/product/cache/0/thumbnail/200x60/9df78eab33525d08d6e5fb8d27136e95/images/catalog/product/placeholder/thumbnail.jpg

不知道我做错了什么......请指导。

1 个答案:

答案 0 :(得分:1)

我发现我们需要在获取它之前加载$product,就像这样

$product= Mage::getModel('catalog/product')->load($prod_id);

然后我们可以使用

检索它的拇指

$thumbUrl = $product->getThumbnailUrl(200, 60);