注意:我不是在说下面弹出的比较页面,我指的是模板文件sidebar.phtml显示的比较块。mytheme\default\template\catalog\product\compare\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) ?>" />问题是我不确定如何使用从"catalog/product_compare“帮助器获得的数据来获取相应的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)
...发布于 2014-08-14 01:25:40
经过反复试验,我找到了答案。没有任何关于这一切的真正合适的可用文档,是吗?
<?php
$product = Mage::getModel("catalog/product")->load($_item->getProductId());
echo "<img src='" . Mage::helper('catalog/image')->init($product, 'small_image')->keepFrame(false)->resize(50) . "'>";
?>https://stackoverflow.com/questions/25287858
复制相似问题