1

I am facing an error during the checkout process when I select a payment method and press the button continue to next step to place order its an error as follows:

Fatal error Call to a member function insert() on boolean in /home/buildi59/public_html/app/code/community/Lof/Slideshow/Model/Observer.php on line 58

Here is the code for observer.php:

class Lof_Slideshow_Model_Observer
{

    public function beforeRender(Varien_Event_Observer $observer)
    {
        $controller_name = Mage::app()->getRequest()->getControllerModule();
        $menu_name = $controller_name . "_" . Mage::app()->getRequest()->getControllerName();
        $helper = Mage::helper('lof_slideshow/data');

        if ($helper->checkAvaiable($controller_name)) {
            $config = $helper->get();
            $event = $observer->getEvent();

            if ($helper->checkMenuItem($menu_name, $config)) {
                /*Define slider block*/
                $this->_loadMedia($config);
                $layout = Mage::getSingleton('core/layout'); // we are taking the item with 'object' key from array passed to dispatcher
                $title = $config["title"];
                $position = isset($config["blockPosition"]) ? $config["blockPosition"] : "content";
                $custom_pos = isset($config["customBlockPosition"]) ? $config["customBlockPosition"] : "";

                if (!empty($custom_pos)) {
                    $position = $custom_pos;
                }

                $display = isset($config["blockDisplay"]) ? $config["blockDisplay"] : "after";
                $display = $display == "after" ? true : false;
                $source = $config["source"];
                $block = $layout->createBlock('lof_slideshow/source_' . $source);
                // echo $source;die;
                $layout->getBlock($position)->insert($block, $title, $display);
                /*End defined*/
            } else {

            }
        }
    }

    function _loadMedia($config = [])
    {
        if (!defined('_LOADED_LOFSLIDESHOW_')) {
            $mediaHelper = Mage::helper('lof_slideshow/media');

            if ($config['enable_jquery']) {
                $mediaHelper->addMediaFile("js", "lof_slideshow/jquery.js");
            }

            $mediaHelper->addMediaFile("js", "lof_slideshow/jquery-ui.js");
            $mediaHelper->addMediaFile("js", "lof_slideshow/script.js");
            define('_LOADED_LOFSLIDESHOW_', 1);
        }
    }
}

Can any bobdy tell me how to fix this.

Thanks!

2
  • Please post the code in app/code/community/Lof/Slideshow/Model/Observer.php Sep 8, 2016 at 11:45
  • Please see the updated question at Digital Pianism
    – Xabby
    Sep 8, 2016 at 11:46

1 Answer 1

2

This is the line causing the problem:

$layout->getBlock( $position )->insert($block, $title , $display);

Basically the insert() does not work because $layout->getBlock( $position ) does not retrieve an existing block from the layout.

You need to find what $position is, where the corresponding block is declared in your layout and find out why it has been renamed/deleted.

If the fact that the block is not there is a normal behavior and you just want to skip the insert in this case then you can modify your code like this:

if ($parentBlock = $layout->getBlock($position)) {
    $parentBlock->insert($block, $title , $display);
}
5
  • Thanks a lot for this great help. i have just replaced my lines of code with yours and its worked like charm.. Thanks! @Raphael at Digital Pianism
    – Xabby
    Sep 8, 2016 at 11:58
  • @Xabby ensure your code still works properly as the code I pasted won't insert the block if the parent block is not present Sep 8, 2016 at 12:02
  • Actually its just pass one step Payment method. at the end its not placing order. just stuck there @Raphael at Digital Pianism
    – Xabby
    Sep 8, 2016 at 12:12
  • @Xabby well follow the instructions I gave you to debug that issue, I can't help you more here unfortunately as there's too many possible problems Sep 8, 2016 at 12:13
  • Ok Sure let me debug my issues.
    – Xabby
    Sep 8, 2016 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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