Magento - 在侧边栏比较块中显示产品图像

时间:2014-08-13 13:44:09

标签: image magento compare

注意:我不是在谈论下面的弹出比较页面,我是指模板文件sidebar.phtml显示的比较块。     mytheme的\默认\模板\目录\产品\比较\ sidebar.phtml

我有一个使用sidebar.phtml的自定义比较块,基于标准的Magento。 我试图弄清楚如何在选择用于比较的产品旁边显示产品图像。

我在模板文件sidebar.phtml中看到,它使用帮助器来获取当前列出的产品以进行比较。

$_helper = $this->helper('catalog/product_compare');
$_items = $_helper->getItemCount() > 0 ? $_helper->getItemCollection() : null;

查看产品列表页面模板list.phtml以获取有关如何检索图像的线索,我可以看到:

<img id="product-collection-image-<?php echo $_product->getId(); ?>"
                     src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize($_imgSize); ?>"
                     alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" />

问题是我不确定如何使用我从&#34; catalog / product_compare&#34;获得的数据。帮助获得相应的small_image。

我从catalog / product_compare帮助器中转储了$ _items,转储如下。我无法识别出任何可以像产品ID一样使用的东西?不确定!

object(ET_AdvancedCompare_Model_Resource_Eav_Mysql4_Product_Compare_Item_Collection)[245]
  protected '_customerId' => int 0
  protected '_visitorId' => int 96
  protected '_comparableAttributes' => null
  protected '_flatEnabled' => 
    array (size=1)
      1 => boolean false
  protected '_productWebsiteTable' => string 'catalog_product_website' (length=23)
  protected '_productCategoryTable' => string 'catalog_category_product' (length=24)
  protected '_addUrlRewrite' => boolean true
  protected '_urlRewriteCategory' => string '' (length=0)
  protected '_addMinimalPrice' => boolean false
  protected '_addFinalPrice' => boolean false
  protected '_allIdsCache' => null
  protected '_addTaxPercents' => boolean false
  protected '_productLimitationFilters' => 
    array (size=7)
      'store_table' => string 't_compare' (length=9)
      'visibility' => 
        array (size=3)
          0 => int 3
          1 => int 2
          2 => int 4
      'store_id' => int 1
      'category_id' => string '2' (length=1)
      'use_price_index' => boolean true
      'customer_group_id' => int 0
      'website_id' => string '1' (length=1)
  protected '_productCountSelect' => null
  protected '_isWebsiteFilter' => boolean false
  protected '_priceDataFieldFilters' => 
    array (size=0)
      empty
  protected '_map' => 
    array (size=1)
      'fields' => 
        array (size=6)
          'price' => string 'price_index.price' (length=17)
          'final_price' => string 'price_index.final_price' (length=23)
          'min_price' => string 'price_index.min_price' (length=21)
          'max_price' => string 'price_index.max_price' (length=21)
          'tier_price' => string 'price_index.tier_price' (length=22)
          'special_price' => string 'price_index.special_price' (length=25)
  protected '_priceExpression' => null
  protected '_additionalPriceExpression' => null
  protected '_maxPrice' => null
  protected '_minPrice' => null
  protected '_priceStandardDeviation' => null
  protected '_pricesCount' => null
  protected '_catalogPreparePriceSelect' => null
  protected '_factory' => 
    object(Mage_Catalog_Model_Factory)[190]
      protected '_config' => 
        object(Mage_Core_Model_Config)[5]
          protected '_useCache' => boolean true
          protected '_cacheSections' => 
            array (size=6)
              ...

1 个答案:

答案 0 :(得分:1)

经过多次试验和错误,我找到了答案。 所有这些都没有真正适用的文档吗?

<?php  
                    $product = Mage::getModel("catalog/product")->load($_item->getProductId());
                    echo  "<img src='" . Mage::helper('catalog/image')->init($product, 'small_image')->keepFrame(false)->resize(50) . "'>";
                    ?>