OllyL Posted November 18, 2013 Share Posted November 18, 2013 Hi There, I'm trying to write a custom report module called pickinglist and I'm a bit stuck. I have created the shell of the module with an admin controller and I have added in a menu entry for it in the admin back office. The menu item is under orders: Orders -> Picking List Report and it uses the pickinglist module with the class AdminPickingList under the module I have the folder: controllers / admin / AdminPickingListController.php So far so good, I have an empty admin page appearing now when I click the link in admin. The problem is that I can't figure out how to get the controller to render a view (or where to put the view). I have tried copying the folder structure for the Gamification module but that doesn't seem to be working. I have my SQL done so all I need to do is create a view to display a table and render it out with a query in the controller. Can anyone help me? Thanks a lot, Olly Link to comment Share on other sites More sharing options...
OllyL Posted November 18, 2013 Author Share Posted November 18, 2013 So I still cannot get this to work. But I have made some progress. My controller currently looks like this: class AdminPickingListController extends ModuleAdminController { /** * Constructor */ public function __construct() { //$this->display = 'view'; $this->meta_title = $this->l('Picking List'); parent::__construct(); if (!$this->module->active) Tools::redirectAdmin($this->context->link->getAdminLink('AdminHome')); } /** * initContent */ public function initContent() { $this->setTemplate('pickinglist.tpl'); $sql = "SELECT product_name, COUNT(id_order_detail) quantity FROM ps_orders a INNER JOIN ps_order_detail b ON a.id_order = b.id_order WHERE invoice_date >= '2013-11-15' AND invoice_date <= '2013-11-16' GROUP BY product_name ORDER BY product_name ASC"; $products = array(); if ($results = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql)) { foreach ($results as $row) { $products[] = array('product'=>$row['product_name'], 'quantity'=>$row['quantity']); } } $this->tpl_view_vars = array('products'=>$products); parent::initContent(); } } And my view - which I can only get to work by placing in /admin##/themes/default/template - looks like this: <h2>Picking / Production List (2013-11-07 - 2013-11-07)</h2> <table> <tr> <th>Product</th> <th>Quantity</th> </tr> {foreach from=$products key=key item=product} <tr> <td>{$product['product']}</td> <td>{$product['quantity']}</td> </tr> {/foreach} </table> However the $products variable in the template refuses to populate no matter what I do. It is defintely getting populated correctly in the controller because I've dumped it out but the view does not pick the variable up. Can anyone help here? I'm really bashing my head against a brick wall here!! Thanks very much, Olly Link to comment Share on other sites More sharing options...
amavis Posted December 17, 2013 Share Posted December 17, 2013 (edited) Hi Olly, Why not use $this->context->smarty->assign('products',$products); //$this->tpl_view_vars = array('products'=>$products); If you write a module with admin, you can put pickinglist.tpl in /module/yourmodule/views/templates/admin/<pickinglist>/pickinglist.tpl Gr. Patrick Edited December 17, 2013 by amavis (see edit history) 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now