2013-10-28 68 views
0

我試圖讓所有的產品豎起大拇指的類別產品收集這樣的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()); 
    } 

,它總是返回佔位符圖像的URL這樣的...

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

不知道我在做什麼錯...請指導。

回答

1

我發現,我們需要得到它的拇指,像這樣

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

之前加載$product,然後我們可以檢索使用其拇指

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