dsigg21445 2014-01-26 05:25
浏览 51
已采纳

Opencart自定义模块未在前端显示

I have just developed my first Opencart (1.5.6) plugin using the hostjars starter files.

The Admin section is working beautifully, and all the Frontend code has been placed. However, for some reason the module is not showing the on the webpage, even though the position has been defined in the Admin.

Below is the Frontend Controller code for reference (FYI, No errors are thrown which makes me think that perhaps the Controller is not being called or something):

<?php class ControllerModulebevyspecials extends Controller {
protected function index($setting) {
    //Load the language file  
    $this->language->load('module/bevy_specials');

    //Load the models  
    $this->load->model('module/bevy_specials'); 

    //Get the title from the language file
    $this->data['heading_title'] = $this->language->get('heading_title');

    //Retrieve Checkout Special Products
    $products = $this->model_module_bevy_specials->getBevySpecials();
    if(Count($products)>0){         
        foreach ($products as $product) {
            $product_info = $this->model_catalog_product->getProduct($product['product_id']);
            $this->data['title'] = $product['title'];
            if (isset($product_info)) {
                $this->data['products'][] = array(
                    'product_id'    => $product_info['product_id'],
                    'name'          => $product_info['name'],
                    'discount'      => $product['discount']
                );
            }
        }   
    }
    else{
        $this->data['noRecord'] = true;
    }

    //Choose which template to display this module with
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/module/bevy_specials.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/module/bevy_specials.tpl';
    } else {
        $this->template = 'default/template/module/bevy_specials.tpl';
    }

    //Render the page with the chosen template
    $this->render();
}  } ?>

Am I missing any specific code that displays the module on the webpage?

Opencart documentation is quite minimal when it comes to module development, and I've tried searching on web for a solution but couldn't find a definitive answer.

Any inputs will be greatly appreciated. Thanks in advance!

MORE INFO: One issue found though.....in admin panel when i add 2 or more Layouts for the module (e.g added to "Column-Left" for Contact page and "Content-Top" for Account page), the Frontend then shows the following error:

Warning: Invalid argument supplied for foreach() in D:\xampp171\htdocs\opencart\catalog\controller\common\column_left.php on line 49
  • 写回答

1条回答 默认 最新

  • douchungu0859 2014-01-26 18:34
    关注

    Issue Resolved Since i used the hostjars start files, i had to amend the code abit and the issue got fixed.

    1) In the Admin Controller of the module, i removed the section under the comment:

    "//This code handles the situation where you have multiple instances of this module, for different layouts."
    

    2) In the Admin View .tpl file, for the layout position , i had to properly format the few html tag's. For example: the <select name="my_module_<?php echo $module_row; ?>_layout_id"> was replaced with the proper format <select name="banner_module[<?php echo $module_row; ?>][layout_id]">...... This ensures that multiple Layouts can be saved in Admin control panel. (there will be 8 places in the .tpl file where this needs to be done)

    3) Last but not the least, if you do Step 2 correctly, then the Layouts will be properly serialized and saved in the database's oc_settings Table (previously my layout was not being stored in serialized form).

    Hope the above helps others too.

    Thank you!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测