5

Having issues migrating my site over and only just noticed when I try to view a products page I get this error:

<b>Fatal error</b>:  Call to a member function setTemplate() on a non-object in <b>/*/app/code/core/Mage/Catalog/Block/Product/View/Tabs.php</b> on line <b>60</b><br />

Really don't know where to begin with fixing this, tried debugging the page to no avail. It seems to put a string in $template when doing setTemplate($template).

Any help would be much appreciated.

EDIT

Tabs.php:

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage_Catalog
 * @copyright  Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */


/**
 * Product information tabs
 *
 * @category   Mage
 * @package    Mage_Catalog
 * @author     Magento Core Team <core@magentocommerce.com>
 */
class Mage_Catalog_Block_Product_View_Tabs extends Mage_Core_Block_Template
{
    protected $_tabs = array();

    /**
     * Add tab to the container
     *
     * @param string $title
     * @param string $block
     * @param string $template
     */
    function addTab($alias, $title, $block, $template)
    {

        if (!$title || !$block || !$template) {
            return false;
        }

        $this->_tabs[] = array(
            'alias' => $alias,
            'title' => $title
        );

//  echo $template."<br>";


        $this->setChild($alias,
            $this->getLayout()->createBlock($block, $alias)
                ->setTemplate($template)
            );

    }

    function getTabs()
    {
        return $this->_tabs;
    }
}

layout xml

        <block type="catalog/product_view_tabs" name="product.info.tabs" as="info_tabs" template="catalog/product/view/tabs.phtml" >
            <action method="addTab" translate="title" module="catalog"><alias>description</alias><title>Product Description</title><block>catalog/product_view_description</block><template>catalog/product/view/description.phtml</template></action>
            <action method="addTab" translate="title" module="catalog"><alias>upsell_products</alias><title>We Also Recommend</title><block>catalog/product_list_upsell</block><template>catalog/product/list/upsell.phtml</template></action>
            <action method="addTab" translate="title" module="catalog"><alias>additional</alias><title>Additional Information</title><block>catalog/product_view_attributes</block><template>catalog/product/view/attributes.phtml</template></action>
            <action method="addTab" translate="title" module="catalog"><alias>downloads</alias><title>Product Downloads</title><block>catalog/product_view_download</block><template>catalog/product/view/download.phtml</template></action>
        </block>
2

As already mentioned above, the reason for the abscence of the block that layout is trying to draw as tab.

To find the problem, you should modify the debug code (if you can't use the default debug like xDebug). You need to add the check for block existence and name logging for the class of the block that doesn't exist. You can do the following:

<?php
/**
 * Add tab to the container
 *
 * @param string $title
 * @param string $block
 * @param string $template
 */
function addTab($alias, $title, $block, $template)
{

    if (!$title || !$block || !$template) {
        return false;
    }

    $this->_tabs[] = array(
        'alias' => $alias,
        'title' => $title
    );

    // Modified code start:
    $blockInst = $this->getLayout()->createBlock($block, $alias);
    if (!is_object($blockInst)) {
        Mage::log('Not an object: ' . $block);
    }
    $blockInst->setTemplate($template);
    $this->setChild($alias, $blockInst);
    // Modified code ends;
    // Original code:
//        $this->setChild($alias,
//            $this->getLayout()->createBlock($block, $alias)
//                ->setTemplate($template)
//            );
}
?>

Then, reload the page that returns an error and look the system.log file for result. The name of the block should follow the line *Not an object: *. Then, use name of this block to search though the project. Most probably, it is located somewhere in the layout. When you manage to find it, you need to decide what to do. You can look for the reason why the block doesn't exist or simply delete this entry from the layout to make the error disappear.

| improve this answer | |
1

Your issue not in Tab.php.

Issue in layout xml code because of createBlock() does not create a block of Tab that why setTemplate() unable to add template file of tab. This tab block class does not exit in your system.

Suppose.

  <action method="addTab" translate="title" module="catalog"><alias>description</alias><title>Product Description</title><block>catalog/product_view_description</block><template>catalog/product/view/description.phtml</template></action>

Issue at the block define under <block>....</block> is wrong

| improve this answer | |
  • I'm relatively new to magento, this was thrown on my desk, where do you suppose I would find layout.xml, apologies for being a noob :) – Robert Pounder Sep 1 '15 at 10:30
  • updated original post – Robert Pounder Sep 1 '15 at 10:38
1

Make sure you do not have any rewrite. It seems like some extension is rewriting your Tabs class with a class that does not extend Mage_Core_Block_Template.

Try disabling local modules and testing one by one from app/etc/modules .

Search for product_view_tabs in your app/code/community and app/code/local folders to locate any rewrite.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.