Baru-baru ni ada projek memerlukan penggunaan penggunaan Opencart Custom Page.
Maka, terpaksala menggodek bagaimana nak buat custom page.
Kebanyakan tutorial custom page menggunakan Opencart 1.5, aku guna Opencart 2.3.0.3 maka disebabkan itu aku pun edit code org lain dan reshare tutorial ini untuk kegunaan sendiri kemudian hari.
Agak bernasib baik sebenarnya, rupanya Opencart ni pun menggunakan konsep MVC (Model-View-Controller). Sama je macam Laravel. Maka kerja pun jadi mudahlah.
Controller
/catalog/controller/custompage/mycustompage.php
<?php class ControllerCustompageMycustompage extends Controller{ public function index(){ // set title of the page $this->document->setTitle("My Custom Page"); $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'); // set data to the variable $data['my_custom_text'] = "This is my custom page."; // set view if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/custompage/mycustompage.tpl')) { $this->response->setOutput($this->load->view($this->config->get('config_template') . '/template/custompage/mycustompage.tpl', $data)); } else { $this->response->setOutput($this->load->view('custompage/mycustompage.tpl', $data)); } } } ?>
View
/catalog/view/theme/default/template/custompage/mycustompage.tpl
<?php echo $header; //echo $column_left; //echo $column_right; ?> <div class="container"> <div class="row"> <?php // echo $header; echo $content_top; // echo $column_left; echo $my_custom_text; //echo $column_right; echo $content_bottom; //echo $footer; ?> </div> </div> <?php echo $footer; ?>