首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Magento -在侧边栏比较块中显示产品图像

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

Stack Overflow用户
提问于 2014-08-13 21:44:09
回答 1查看 1.8K关注 0票数 0

注意:我不是在说下面弹出的比较页面,我指的是模板文件sidebar.phtml显示的比较块。mytheme\default\template\catalog\product\compare\sidebar.phtml

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

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

代码语言:javascript
运行
复制
$_helper = $this->helper('catalog/product_compare');
$_items = $_helper->getItemCount() > 0 ? $_helper->getItemCollection() : null;

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

代码语言:javascript
运行
复制
<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) ?>" />

问题是我不确定如何使用从"catalog/product_compare“帮助器获得的数据来获取相应的small_image。

我转储了来自catalog/product_compare帮助器的$_items,转储内容如下。我不能识别任何我可以使用的东西,比如产品id?不确定!

代码语言:javascript
运行
复制
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)
              ...
EN

回答 1

Stack Overflow用户

发布于 2014-08-14 01:25:40

经过反复试验,我找到了答案。没有任何关于这一切的真正合适的可用文档,是吗?

代码语言:javascript
运行
复制
<?php  
                    $product = Mage::getModel("catalog/product")->load($_item->getProductId());
                    echo  "<img src='" . Mage::helper('catalog/image')->init($product, 'small_image')->keepFrame(false)->resize(50) . "'>";
                    ?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25287858

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档