0

我正在尝试为这样的类别产品集合获取所有产品拇指

    $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

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

4

1 回答 1

1

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

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

然后我们可以使用

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

于 2014-01-08T08:03:39.477 回答