0
votes

I have been trying to display custom data in Opencart Home page page and I'm unable to locate the controller from where the data is sent to the .tpl file. And I am using pavo flshshop theme 2.0.3. I have added the data in catalog/controller/product/product.php( which I am not sure right controller or not ) file. When I call that variable in the .tpl file its says "undefined variable". Someone please help me with from where the data is coming.

This is my .tpl path:

C:\xampp\htdocs\grceducators\catalog\view\theme\pav_flashshop\template\common\product\default.tpl

Here is the default.tpl code:


<div class="product-meta clearfix">
    <h6 class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></h6>
    <h6 class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['custom_desc']; ?></a></h6>

    <?php if( isset($product['description']) ){ ?>
        <p class="description"><?php echo utf8_substr( strip_tags($product['description']),0,200);?>...</p>
    <?php } ?>
    <div class="bottom clearfix">
        <?php if ($product['price']) { ?>
            <div class="price">
              <?php if (!$product['special']) { ?>
              <span class="price-new"><?php echo $product['price']; ?></span>
              <?php } else { ?>
              <span class="price-new"><?php echo $product['special']; ?></span><span class="price-old"><?php echo $product['price']; ?></span>
              <?php } ?>
            </div>


        <?php } ?>
         <?php if ($product['description']) { ?>
        <div class="price">
              <span class="price-new"><?php echo $product['custom_desc']; ?></span>

            </div>
            <?php } ?>
    </div>
</div>

Any help will be appreciated.

1
Can you show controller code, where you set this variable?MorganFreeFarm
try use notepad++ to search where default.tpl are rendered. Use "Find in files" and add search phrase default.tplK. B.
@MorganFreeFarm I have included two blocks of my controller code here. here// $data['duration'] = html_entity_decode($product_info['duration'], ENT_QUOTES, 'UTF-8'); $data['schedule'] = html_entity_decode($product_info['schedule'], ENT_QUOTES, 'UTF-8'); and here// $data['products'][] = array( 'duration' => $result['duration'], 'schedule' => $result['schedule'], 'href' => $this->url->link('product/product', 'product_id=' . $result['product_id']) ); using this controller i am actually sucessfully displaying in product page.Sadhik Husain
@K.B. thank you for reply . I already tried searching but no sucess.Sadhik Husain
@ in common/home controller i have this files. if (isset($this->request->get['route'])) { $this->document->addLink(HTTP_SERVER, 'canonical'); } $data['column_left'] = $this->load->controller('common/column_left'); $data['column_right'] = $this->load->controller('common/column_right'); $data['content_top'] = $this->load->controller('common/content_top'); $data['content_bottom'] = $this->load->controller('common/content_bottom'); $data['footer'] = $this->load->controller('common/footer'); $data['header'] = $this->load->controller('common/header');Sadhik Husain

1 Answers

1
votes

Some of the the controller files you see in the folder catalog/controller/common are "containers of something else". I will explain you what happens for example in the file home.php

If you open that file you will see only few lines of code, some of them look like this:

$data['column_left'] = $this->load->controller('common/column_left');

With that single line of code Opencart loads all the modules assigned to the column left of the home page (from the Admin, go to the page Design -> layouts -> Home).

$data['column_left'] is a big object with a list of modules inside:

(It's just a pseudo code, to give you an idea of how stuffs work):

$data['column_left'] {

      module 1  {...}  controller + template    
      module 2  {...}  controller + template
      module 3  {...}  controller + template
}

every module has its own controller + (model) + template

To quickly get the controller that is rendering your template, first you must look at the layout of the home page (from the Admin panel). You will see four main sections: content top, content bottom, column left, column right".

Check on your home page where your content is printed out. If for example it's on the column left, the module that is rendering the tpl file is one of the modules listed in the column left section of your (Admin) home layout.

Usually module names are enough to get which modules (then which controllers) are rendering a tpl (usually you only have to look in the folder catalog/controller/extension/module to find the file name that matches with the module name in the layout page).

The method I described you works in most of the cases without need of using any debugging tool.

I have encountered third party extensions written like rubik cubes. In those cases you must use debug_backtrace().

That function, expecially on big frameworks can output tons of data. To reduce the output of that function, I advise you to:

  1. find in which section of the page the content is rendered ( content top, content bottom, column left, column right), then open the file catalog/controller/common/[your_section].php

  2. copy the following code at the bottom of that file (I am pasting you a modded version of debug_backtrace(), it formats the output so that you can easily read it from your browser):


// PHP < 5.3.6    
foreach (debug_backtrace() as $trace) {    
echo sprintf("\n%s:%s %s::%s", (isset($trace['file'])? $trace['file'] : '') , (isset($trace['line'])? $trace['line'] : ''), (isset($trace['class'])? $trace['class'] : ''), (isset($trace['function'])? $trace['function'] : ''));    

}    
die;

// PHP >= 5.3.6    
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);    
die;