frogtaku Posted May 30, 2014 Share Posted May 30, 2014 I am trying to make a simple list of all product names in the back-office's product tab I created. Here's what I have written in the module's .tpl: {if isset($products) && $products} <ul> {foreach from=$products item=product} <li>{$product.name}</li> {/foreach} </ul> {/if} The output is just: <ul></ul> I guess it isn't as simple as that... Link to comment Share on other sites More sharing options...
frogtaku Posted May 31, 2014 Author Share Posted May 31, 2014 I dare doing a little bump, because I am pretty sure I am missing something really basic that I'll be embarassed about shortly after. Yet I don't grasp it, looking at product-list.tpl for inspiration. Link to comment Share on other sites More sharing options...
vekia Posted May 31, 2014 Share Posted May 31, 2014 how the controller looks like? can you show it, please? Link to comment Share on other sites More sharing options...
frogtaku Posted June 1, 2014 Author Share Posted June 1, 2014 I didn't implement/override one, is this necessary to access the products array? Sorry if my question is stupid, I am still tiptoeing around module development. Link to comment Share on other sites More sharing options...
vekia Posted June 1, 2014 Share Posted June 1, 2014 let's clarify perhaps i missed something back-office's product tab I created. what you created? if you created tab in back office it means that this tab must be somewhere defined (like a controller, part of module etc.) Link to comment Share on other sites More sharing options...
frogtaku Posted June 1, 2014 Author Share Posted June 1, 2014 (edited) Sorry I misunderstood something public function hookDisplayAdminProductsExtra($params){ if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product')))){ $this->prepareNewTab(); return $this->display(__FILE__, 'product-tab.tpl'); } } The function that is called is there: public function prepareNewTab(){ $this->context->smarty->assign(array( 'custom_field' => $this->getCustomField((int)Tools::getValue('id_product')), 'languages' => $this->context->controller->_languages, 'default_language' => (int)Configuration::get('PS_LANG_DEFAULT') )); Edited June 1, 2014 by frogtaku (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted June 1, 2014 Share Posted June 1, 2014 okay so where you've got $products variable defined? at the moment there are only: 'custom_field' => $this->getCustomField((int)Tools::getValue('id_product')), 'languages' => $this->context->controller->_languages, 'default_language' => (int)Configuration::get('PS_LANG_DEFAULT') Link to comment Share on other sites More sharing options...
frogtaku Posted June 1, 2014 Author Share Posted June 1, 2014 (edited) Oh, I thought $products array was a global variable so I could access it directly through a smarty template. I have difficulty understanding how to define it this way though... Is $this->Tools::getValue() the way to go? Edited June 1, 2014 by frogtaku (see edit history) Link to comment Share on other sites More sharing options...
frogtaku Posted June 3, 2014 Author Share Posted June 3, 2014 (edited) So, looking at other threads, I tried this method and commented where it won't work: public function prepareNewTab(){ $products = Product::getProducts($this->context->language->id, 0, 100); $products_all = Product::getProductsProperties($this->context->language->id, $products); //=> WILL PRODUCE A FATAL ERROR ON TAB $this->context->smarty->assign(array( 'custom_field' => $this->getCustomField((int)Tools::getValue('id_product')), 'languages' => $this->context->controller->_languages, 'default_language' => (int)Configuration::get('PS_LANG_DEFAULT'), 'products' => $products_all; // TAB WON'T LOAD CORRECTLY )); } Any idea? Edit: Looking at the module page, it tells me I have a syntax error and a missing class. I guess it's refering to the Product class. Should I declare it? How would it affect the existing code? The lack of documentation on its use for a module is a little bothersome. Edited June 3, 2014 by frogtaku (see edit history) Link to comment Share on other sites More sharing options...
frogtaku Posted June 4, 2014 Author Share Posted June 4, 2014 No idea? Either the solution is obvious and I am too stupid to be told, or I hacked the matrix and I am on my own. Thanks in advance for any help. Link to comment Share on other sites More sharing options...
Recommended Posts