Question

I have a sidebar whislist /app/design/frontend/base/default/template/wishlist/sidebar.phtml I need to add a "custom attribute" called manufacturer.

I have tried many options like these but all don't show a thing:

<?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); ?>

Thisone shows "3" and no manufacturer name, at least showing something..

<?php echo $this->htmlEscape($_item->getManufacturer()) ?>

How can I get my manufacturer there? I can show them about everywhere else..

Was it helpful?

Solution

Look at the loop code of sidebar, by default it's:

<?php foreach ($this->getWishlistItems() as $_item): ?>

Inside thip loop $_item->getManufacturer() will return your attribute value, but you have to be sure, that product have this attribute fulfilled.

You can display it i.e. like this:

<?php if ( $_item->getManufacturer() ): ?>
Manufacturer: <?php echo $this->htmlEscape($_item->getManufacturer()) ?>
<?php endif ?>

Edit:

Which Magento version you're using? Probably this code will work, but its not optimal:

<?php if ( $manufacturer = Mage::getModel('catalog/product')->load($_item->getId())->getAttributeText('manufacturer') ): ?>
    Manufacturer: <?php echo $this->htmlEscape( $manufacturer ) ?>
<?php endif ?>

OTHER TIPS

The reason this isn't working:

<?php echo $item->getAttributeText('manufacturer') ?> 

Is likely because manufacturer isn't in the $item's parent collection.

You need to extend the method that gets the collection and add the manufacturer attribute from 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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top