在侧边栏愿望清单中显示自定义属性
-
16-10-2019 - |
题
我有一个侧栏hislist/app/design/frontend/base/default/template/wishlist/sidebar.phtml我需要添加一个称为制造商的“自定义属性”。
我尝试了许多这样的选择,但所有这些都没有显示出来:
<?php echo $this->getManufacturer()) ?>
<?php echo $this->htmlEscape($_item->getData('manufacturer')); ?>
<?php echo $_product->getManufacturer() ?>
<?php $_item = $this->getItem()?>
<?php $_product= Mage::getSingleton('catalog/product')->load($_item->getProductId()) ?>
<?php echo $_product->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($_product); ?>
<?php echo $item->getAttributeText('manufacturer') ?>
<?php echo $item->getResource()->getAttribute('manufacturer')->getFrontend()->getValue($item); ?>
这显示了“ 3”,没有制造商的名称,至少显示了一些东西。
<?php echo $this->htmlEscape($_item->getManufacturer()) ?>
我如何把我的制造商在那里?我可以向他们展示其他地方。
解决方案
查看侧边栏的循环代码,默认情况下是:
<?php foreach ($this->getWishlistItems() as $_item): ?>
内部thip loop $ _item-> getManufacturer()将返回您的属性值,但是您必须确保,该产品已满足此属性。
您可以像这样显示它:
<?php if ( $_item->getManufacturer() ): ?>
Manufacturer: <?php echo $this->htmlEscape($_item->getManufacturer()) ?>
<?php endif ?>
编辑:
您正在使用哪个Magento版本?大概此代码会起作用,但并不最佳:
<?php if ( $manufacturer = Mage::getModel('catalog/product')->load($_item->getId())->getAttributeText('manufacturer') ): ?>
Manufacturer: <?php echo $this->htmlEscape( $manufacturer ) ?>
<?php endif ?>
其他提示
这不起作用的原因:
<?php echo $item->getAttributeText('manufacturer') ?>
可能是因为 manufacturer
不在 $item
的父母收藏。
您需要扩展获取收集的方法并从中添加制造商属性 Mage_Wishlist_Model_Resource_Item_Collection
:
/**
* Retrieve Wishlist Product Items collection
*
* @return Mage_Wishlist_Model_Resource_Item_Collection
*/
public function getWishlistItems()
{
if (is_null($this->_collection)) {
$this->_collection = clone $this->_createWishlistItemCollection();
$this->_collection->clear();
$this->_prepareCollection($this->_collection);
}
$this->_collection->addAttributeToSelect('manufacturer');
return $this->_collection;
}