簡體   English   中英

Opencart自定義模塊未在前端顯示

[英]Opencart custom module not showing in frontend

我剛剛使用hostjars起始文件開發了我的第一個Opencart(1.5.6)插件。

管理員部分的運行狀況很好,並且所有前端代碼都已放置。 但是,由於某些原因,即使該位置已在管理員中定義,該模塊也未在網頁上顯示。

以下是前端控制器代碼以供參考(僅供參考,沒有引發任何錯誤,這使我認為也許未在調用Controller或其他原因):

<?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();
}  } ?>

我是否缺少任何在網頁上顯示該模塊的特定代碼?

關於模塊開發,Opencart文檔非常少,我曾嘗試在網上搜索解決方案,但找不到確切的答案。

任何輸入將不勝感激。 提前致謝!

更多信息:但是,當我為模塊添加2個或更多布局(例如,添加到“聯系人”頁面的“列左”和“帳戶”頁面的“ Content-Top”)時,在管理面板中發現了一個問題。然后顯示以下錯誤:

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

解決的問題由於我使用了hostjars啟動文件,因此我不得不稍稍修改一下代碼,問題得到了解決。

1)在模塊的管理控制器中,我刪除了注釋下的部分:

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

2)在Admin View .tpl文件中,對於布局位置,我必須正確格式化幾個html標記。 例如: <select name="my_module_<?php echo $module_row; ?>_layout_id">替換為正確的格式<select name="banner_module[<?php echo $module_row; ?>][layout_id]"> ......這樣可以確保可以在“管理”控制面板中保存多個布局。 (.tpl文件中有8個地方需要完成此操作)

3)最后但並非最不重要的一點,如果您正確地執行了步驟2,則布局將被正確序列化並保存在數據庫的oc_settings表中(以前我的布局沒有以序列化形式存儲)。

希望以上內容對其他人也有幫助。

謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM