1

When i am doing add to cart its showing this error

Fatal error: Call to a member function getId() on a non-object in /public_html/app/design/frontend/ultimo/default/template/page/1column.phtml on line 50

please help me. here is code:

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-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@magentocommerce.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.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Template for Mage_Page_Block_Html
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<?php $bodyClasses = $this->getBodyClass() .' '. $this->helper('ultimo')->getThemeBodyClasses(); ?>
<body class="<?php echo $bodyClasses; ?>">
<?php echo $this->getChildHtml('after_body_start') ?>
<div id="root-wrapper">
<div class="wrapper">
    <?php echo $this->getChildHtml('global_notices') ?>
    <div class="page">
        <?php echo $this->getChildHtml('header') ?>
        <div class="main-container col1-layout">
            <div class="main-before-top-container"><?php echo $this->getChildHtml('main_before_top') ?></div>
            <div class="main container">
                <?php //echo $this->getChildHtml('breadcrumbs') ?>
                <?php $_product = Mage::registry('current_product');
                $id = $_product->getId();
                ?>

                 <div class="grid-full breadcrumbs">
                <ul>
                    <li class="home">
                        <a href="https://www.wombatframes.com.au/" title="Go to Home">Home </a><span>/ </span>
                    </li>
                    <li class="categorymy">
                    <?php $product = Mage::getModel('catalog/product')->load($id);
                    foreach ($product->getCategoryCollection() as $category) {
                    $parent_category = $category->getParentCategory();
                    $proo =  $parent_category->getId();
                    //echo $proo; 
                    } ?>
                   <a href="<?php echo $parent_category->getUrl();?>"><?php echo $parent_category->getName(); ?></a>
                   <?php if($proo > 3){?><span>/ </span><?php }?>
                   </li>
                    <li class="subcat">
                    <?php $_proId  =  $_product->getId();
                        $product = Mage::getModel('catalog/product')->load($_proId);
                        $cats = $product->getCategoryIds();

                        foreach ($cats as $category_id) {
                            $_cat = Mage::getModel('catalog/category')->load($category_id) ;
                            $currentCategory = $_cat->getName();
                            $currentURL = $_cat->getUrl();
                        }
                    ?>
                        <a href="<?php echo $currentURL; ?>"><?php echo $currentCategory; ?></a>
                        <span>/ </span>
                    </li>

                    <li class="productmy">
                        <a><?php echo $_product->getName(); ?></a>
                    </li>
                </ul>
                </div>
                <div class="preface grid-full in-col1"><?php echo $this->getChildHtml('preface') ?></div>
                <div class="col-main grid-full in-col1">
                    <?php echo $this->getChildHtml('global_messages') ?>
                    <?php echo $this->getChildHtml('content') ?>
                </div>
                <div class="postscript grid-full in-col1"><?php echo $this->getChildHtml('postscript') ?></div>
            </div>
        </div>
        <?php echo $this->getChildHtml('footer') ?>
        <?php echo $this->getChildHtml('global_cookie_notice') ?>
        <?php echo $this->getChildHtml('before_body_end') ?>
    </div>
</div>
</div> <!-- end: root-wrapper -->
<?php echo $this->getAbsoluteFooter() ?>
<script>
jQuery( document ).ready(function() {
    //alert('hi');
    jQuery("label[for = 'billing:postcode']").html("Post Code");
    jQuery("label[for = 'shipping:postcode']").html("Post Code");
    jQuery("label[for = 'billing:region']").html("State");
    jQuery("label[for = 'shipping:region']").html("State");
    });
</script>
</body>
</html>
  • Do you want this code for product page only? – Sukumar Gorai Jun 27 '18 at 10:38
  • please do add to cart here : wombatframes.com.au, you will understand – Alex Jun 27 '18 at 12:37
  • I understand your problem. But my question is you have added this code to your 1column.phtml and does this code is needed on checkout cart rather than product details page? If this code is only for product details page then put if condition for product page so that it will affect the other pages as other page doesn't have current_product in registry thats why its throwing an error. – Sukumar Gorai Jun 27 '18 at 12:44
  • my website was working perfect i dont know instantly this error comes up.. now when i i am doing add to cart its showing error please do add to cart this product : wombatframes.com.au/reatured/… – Alex Jun 27 '18 at 12:51
  • Can you copy the code of 1column.phtml here app/design/frontend/ultimo/default/template/page/1column.phtml – Sukumar Gorai Jun 27 '18 at 12:52
0

You need to change code like this:

<?php 
      if(Mage::registry('current_product'))
      {
           $_product = Mage::registry('current_product');
           $id = $_product->getId();
      }
?>
| improve this answer | |
  • please do add to cart here : wombatframes.com.au – Alex Jun 27 '18 at 9:47
  • did you check ? where i need to use this code ? – Alex Jun 27 '18 at 10:07
  • open file : /public_html/app/design/frontend/ultimo/default/template/page/1column.phtml , here you can see your code from question. then it need to replace with mine. – Chirag Rajput Jun 27 '18 at 10:16
  • I added the code , please check url its showing blank page now .. wombatframes.com.au – Alex Jun 27 '18 at 10:25
  • can you try this $_product->getProductUrl(); – Magento Developer Jun 27 '18 at 10:30
0

Please update your 1column.phtml

/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Academic Free License (AFL 3.0)
 * that is bundled with this package in the file LICENSE_AFL.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/afl-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@magentocommerce.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.magentocommerce.com for more information.
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php
/**
 * Template for Mage_Page_Block_Html
 */
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $this->getLang() ?>" lang="<?php echo $this->getLang() ?>">
<head>
<?php echo $this->getChildHtml('head') ?>
</head>
<?php $bodyClasses = $this->getBodyClass() .' '. $this->helper('ultimo')->getThemeBodyClasses(); ?>
<body class="<?php echo $bodyClasses; ?>">
<?php echo $this->getChildHtml('after_body_start') ?>
<div id="root-wrapper">
<div class="wrapper">
    <?php echo $this->getChildHtml('global_notices') ?>
    <div class="page">
        <?php echo $this->getChildHtml('header') ?>
        <div class="main-container col1-layout">
            <div class="main-before-top-container"><?php echo $this->getChildHtml('main_before_top') ?></div>
            <div class="main container">
                <?php //echo $this->getChildHtml('breadcrumbs') ?>
                <div class="grid-full breadcrumbs">
                    <ul>
                        <li class="home">
                            <a href="https://www.wombatframes.com.au/" title="Go to Home">Home </a><span>/ </span>
                        </li>
                        <?php $controller = Mage::app()->getRequest()->getControllerName(); ?>
                        <?php $action = Mage::app()->getRequest()->getActionName(); ?>
                        <?php if($controller == 'product' && $action == 'view'): ?>
                            <?php $_product = Mage::registry('current_product'); ?>
                            <li class="categorymy">
                            <?php $product = Mage::getModel('catalog/product')->load($_product->getId());
                            foreach ($product->getCategoryCollection() as $category) {
                            $parent_category = $category->getParentCategory();
                            $proo =  $parent_category->getId();
                            //echo $proo; 
                            } ?>
                           <a href="<?php echo $parent_category->getUrl();?>"><?php echo $parent_category->getName(); ?></a>
                           <?php if($proo > 3){?><span>/ </span><?php }?>
                           </li>
                            <li class="subcat">
                            <?php $cats = $product->getCategoryIds();
                                  foreach ($cats as $category_id) {
                                  $_cat = Mage::getModel('catalog/category')->load($category_id) ;
                                  $currentCategory = $_cat->getName();
                                  $currentURL = $_cat->getUrl();
                                }
                            ?>
                                <a href="<?php echo $currentURL; ?>"><?php echo $currentCategory; ?></a>
                                <span>/ </span>
                            </li>

                            <li class="productmy">
                                <a><?php echo $_product->getName(); ?></a>
                            </li>
                        <?php endif; ?>
                    </ul>
                </div>
                <div class="preface grid-full in-col1"><?php echo $this->getChildHtml('preface') ?></div>
                <div class="col-main grid-full in-col1">
                    <?php echo $this->getChildHtml('global_messages') ?>
                    <?php echo $this->getChildHtml('content') ?>
                </div>
                <div class="postscript grid-full in-col1"><?php echo $this->getChildHtml('postscript') ?></div>
            </div>
        </div>
        <?php echo $this->getChildHtml('footer') ?>
        <?php echo $this->getChildHtml('global_cookie_notice') ?>
        <?php echo $this->getChildHtml('before_body_end') ?>
    </div>
</div>
</div> <!-- end: root-wrapper -->
<?php echo $this->getAbsoluteFooter() ?>
<script>
jQuery( document ).ready(function() {
    //alert('hi');
    jQuery("label[for = 'billing:postcode']").html("Post Code");
    jQuery("label[for = 'shipping:postcode']").html("Post Code");
    jQuery("label[for = 'billing:region']").html("State");
    jQuery("label[for = 'shipping:region']").html("State");
    });
</script>
</body>
</html>
| improve this answer | |
  • you mean i need to put this code in 1column.phtml ? – Alex Jun 28 '18 at 5:55
  • @Alex yes put above code in your file. it will work – Chirag Rajput Jun 28 '18 at 6:09
  • Yes it should work. Put this code to your 1column.phtml – Sukumar Gorai Jun 28 '18 at 7:05

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.