1

As title I like to move my product name inside breadcrumbs.phtml. the following are the codes I currently have. But it returns a "Fatal error: Call to a member function getName() on a non-object". how can we fix this?

<?php if($crumbs && is_array($crumbs)): ?>
<?php $_helper = $this->helper('catalog/output'); ?>
<?php $_product = $this->getProduct(); ?>

<div class="breadcrumbs">
    <div class="container">
        <div class="container-inner">
            <ul>
                <?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
                    <li class="<?php echo $_crumbName ?>">
                    <?php if($_crumbInfo['link']): ?>
                        <a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->escapeHtml($_crumbInfo['title']) ?>"><?php echo $this->escapeHtml($_crumbInfo['label']) ?></a>
                    <?php elseif($_crumbInfo['last']): ?>
                        <strong><?php echo $this->escapeHtml($_crumbInfo['label']) ?></strong>
                    <?php else: ?>
                        <?php echo $this->escapeHtml($_crumbInfo['label']) ?>
                    <?php endif; ?>
                    <?php if(!$_crumbInfo['last']): ?>
                        <span><i class="fa fa-angle-right"></i> </span>
                    <?php endif; ?>
                    </li>
                <?php endforeach; ?>
            </ul>

            <div>
                <h1><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>

            </div>

        </div>
    </div>
</div>
<?php endif; ?>
Dylan Daicy Siao
  • 155
  • 1
  • 3
  • 13

1 Answers1

0

As per as magento code , breadcrumbs are called at every page.

In your code,You have tried to call $this->getProduct(); which is only working on product view at some blocks and it does not work on breadcrumbs.

If you have try to calling this breadcrumbs at every page then you get same error.

That we need to stop calling of <?php $_product = $this->getProduct(); ?> and <?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></h1>

at every page.

And getting product data at breadcrumbs then you need to call registry variable Mage::registry('current_product').

see details at Magento: How to tell if you're on a category page, or product page in .phtml file(s)

 <?php if( Mage::registry('current_product')):?>
<div>
<h1><?php echo $_helper->productAttribute(Mage::registry('current_product'), Mage::registry('current_product')->getName(), 'name') ?></h1>
</div>
<?php endif; ?>
Community
  • 1
  • 1
Amit Bera
  • 7,581
  • 7
  • 31
  • 57