0

I am calling a block method of another module in one of the .phtml file using below code--

Mage::app()->getLayout()->createBlock('tablisting/list')->toHtml();

this code works but it takes too much time in loading (approx.- 12 sec). When I dig it deeper I found toHtml() function which calling $this->renderView() in Mage_Core_Block_Template file. This line of code taking much time in loading.

Block file List.php -

protected function _toHtml(){
        if(!$this->getConfig('isenabled')) return;
        $is_ajax = Mage::app()->getRequest()->getParam('is_ajax');
        if( $is_ajax ){
            $cat_id    = Mage::app()->getRequest()->getParam('tab_cat_id');
            $order_id  = Mage::app()->getRequest()->getParam('order_id');
            $type      = Mage::app()->getRequest()->getParam('data_type');
            if( $type == 'order' ){
                $child_items = $this->getProductsOrder($order_id);
            } else {
                $child_items = $this->getProducts($cat_id);
            }
            $template_file = 'sm/tablisting/default_items.phtml';
        }else{
            $template_file = 'sm/tablisting/default.phtml';
        }
        $this->setTemplate($template_file);
        return parent::_toHtml();
    }

Is there any other way to call that block method in my template file ? How can reduce loading time ? Please help me. Thanks in Advance.

3
  • Could you please give a link to the module's source? If you bought the module, I think it's better to contact the module's developer to get support. In the code you provided, there's nothing that takes any time. Aug 3, 2016 at 11:51
  • 1
    I would recommend turning on the Profiler see. inchoo.net/magento/… or maybe trying out the AOE_Profiler github.com/AOEpeople/Aoe_Profiler this will give you more details as what part of your custom code is taking so much of the time and resources. Aug 3, 2016 at 11:56
  • I see that the variable $child_items maybe that's the one that takes a lot of time (most likely the code is not the best code)
    – Marius
    Aug 3, 2016 at 13:43

1 Answer 1

2

You need to optimize code in your custom block in this case. In whatever way you are going to include your block in your layout, it will eventually call Mage_Core_Block_Template::renderView() and will take time to render it.

Content of block tablisting/list is what makes problem here. From the type name, I believe you have a collection associated with that block and most probably this collection is what makes problem here.

We cannot give a specific solution in this situation unless we see your block code.

Edit

Your edit is not enough to give you a proper solution. I recommend you to use profiler tool in Magento to debug such issues. You can try Aoe_Profiler module for better results.

2
  • Hello @Rajeev..I have a large block file to copy/paste here. Although I have edited my question with the methods which is being called. Please see my updated question. Aug 3, 2016 at 11:45
  • @shashank please see my edit. Update is not give clue of real problem. You may need to use profiler tool of magento to find out the culprit. Aug 3, 2016 at 12:32

Your Answer

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

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