kangoo13 Posted July 7, 2015 Share Posted July 7, 2015 Hello everybody, I have a module which is composed of select html form. And when the form is submited I want to display the normal product list display but with a custom query, so that I can choose which products I want to display. Can you lead me on a way to do this? Thanks Link to comment Share on other sites More sharing options...
vekia Posted July 9, 2015 Share Posted July 9, 2015 in your module controller you have to create function to get products from database for example $products[] = new Product(3); $products[] = new Product(15); where 3 and 15 are id numbers of products then pass $products variable to smarty $this->context->smarty->assign('products'=>$products); do it inside function where you call .tpl file in your module controller. then in tpl file you will be able to do foreach loop on $products variable and display products you assigned to this array Link to comment Share on other sites More sharing options...
kangoo13 Posted July 9, 2015 Author Share Posted July 9, 2015 This part of the question i already knew it it some way, my hard part is how to use a template of the current theme listing product? If you see what I mean.. 1 Link to comment Share on other sites More sharing options...
razaro Posted July 9, 2015 Share Posted July 9, 2015 Well if you check module block new products for example, homepage part, you will see {if isset($new_products) && $new_products} {include file="$tpl_dir./product-list.tpl" products=$new_products class='blocknewproducts tab-pane' id='blocknewproducts'} {else} <ul id="blocknewproducts" class="blocknewproducts tab-pane"> <li class="alert alert-info">{l s='No new products at this time.' mod='blocknewproducts'}</li> </ul> {/if} So you see it includes product-list.tpl so it will have same display as current theme. You will need to pass array of products and change class and id ... Link to comment Share on other sites More sharing options...
kangoo13 Posted July 9, 2015 Author Share Posted July 9, 2015 This is the the display of new product list no ? What If I want exactly the same display when we search for products in category ? Link to comment Share on other sites More sharing options...
razaro Posted July 9, 2015 Share Posted July 9, 2015 Yes it is new products but I give you that as example, if you check code a bit you will find this also for search {include file="$tpl_dir./product-list.tpl" products=$search_products} So you need a way to populate your array and use it like this {include file="$tpl_dir./product-list.tpl" products=$your_array} Link to comment Share on other sites More sharing options...
kangoo13 Posted July 9, 2015 Author Share Posted July 9, 2015 Here is my controlelr : parent::initContent(); $products = array(); $products = new Product(8); $this->context->smarty->assign(array('products'=>$products)); $this->setTemplate('display.tpl'); Here is my tpl : {if $products} <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix gfont"> {include file="$tpl_dir./product-sort.tpl"} {include file="$tpl_dir./nbr-product-page.tpl"} {include file="$tpl_dir./product-compare.tpl"} </div> </div> {include file="$tpl_dir./product-list.tpl" products=$products} <div class="content_sortPagiBar"> <div class="bottom-pagination-content sortPagiBar bottom clearfix"> {include file="$tpl_dir./product-sort.tpl" display='viewtype'} {include file="$tpl_dir./pagination.tpl" paginationId='bottom'} </div> </div> {/if} As you can see i'm loading only one product, have you an idea why I got like 30 blanks products on my display page ? Here is the display : Link to comment Share on other sites More sharing options...
razaro Posted July 9, 2015 Share Posted July 9, 2015 You did not do what Vekia have said $products[] = new Product(15); so you need to to try to add product to array. Also maybe try to use custom name like $my_products maybe this pick up some other $products array. Link to comment Share on other sites More sharing options...
kangoo13 Posted July 9, 2015 Author Share Posted July 9, 2015 (edited) My new php : <?php if (!defined('_PS_VERSION_')) exit; class CarBrowserDisplayModuleFrontController extends ModuleFrontController { public function initContent() { parent::initContent(); $myprod[] = new Product(8); $this->context->smarty->assign(array('myprod'=>$myprod)); $this->setTemplate('display.tpl'); } } ?> My new tpl : {if $myprod} <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix gfont"> {include file="$tpl_dir./product-sort.tpl"} {include file="$tpl_dir./nbr-product-page.tpl"} {include file="$tpl_dir./product-compare.tpl"} </div> </div> {include file="$tpl_dir./product-list.tpl" products=$myprod} <div class="content_sortPagiBar"> <div class="bottom-pagination-content sortPagiBar bottom clearfix"> {include file="$tpl_dir./product-sort.tpl" display='viewtype'} {include file="$tpl_dir./pagination.tpl" paginationId='bottom'} </div> </div> {/if} And the result is worse now .. look : The same thing happens if i rename myprod to products.. EDIT : I found that the problem happens in the product-list.tpl , so every $products are well loaded but when the product-list want to access a field by {$product.id} for exemple it is here where it bugs.. turns into blank page (but the $products are not null, i var_dump them already and it's not empty) Edited July 9, 2015 by kangoo13 (see edit history) Link to comment Share on other sites More sharing options...
eloncheur Posted September 20, 2016 Share Posted September 20, 2016 My new php : <?php if (!defined('_PS_VERSION_')) exit; class CarBrowserDisplayModuleFrontController extends ModuleFrontController { public function initContent() { parent::initContent(); $myprod[] = new Product(8); $this->context->smarty->assign(array('myprod'=>$myprod)); $this->setTemplate('display.tpl'); } } ?> My new tpl : {if $myprod} <div class="content_sortPagiBar clearfix"> <div class="sortPagiBar clearfix gfont"> {include file="$tpl_dir./product-sort.tpl"} {include file="$tpl_dir./nbr-product-page.tpl"} {include file="$tpl_dir./product-compare.tpl"} </div> </div> {include file="$tpl_dir./product-list.tpl" products=$myprod} <div class="content_sortPagiBar"> <div class="bottom-pagination-content sortPagiBar bottom clearfix"> {include file="$tpl_dir./product-sort.tpl" display='viewtype'} {include file="$tpl_dir./pagination.tpl" paginationId='bottom'} </div> </div> {/if} And the result is worse now .. look : The same thing happens if i rename myprod to products.. EDIT : I found that the problem happens in the product-list.tpl , so every $products are well loaded but when the product-list want to access a field by {$product.id} for exemple it is here where it bugs.. turns into blank page (but the $products are not null, i var_dump them already and it's not empty) Hi, bumping this thread since I have the same problem. Product-list seems to require an associative array, but when casting the object to an array, it only kinda works. How can I get an associative array from the said product? 1 Link to comment Share on other sites More sharing options...
Pedro Posted December 2, 2018 Share Posted December 2, 2018 @eloncheur Same problem here. The problem is that new Product does not create all the properties you need for product-list.tpl. Did you found a solution? 1 Link to comment Share on other sites More sharing options...
carlos.batista Posted May 20, 2020 Share Posted May 20, 2020 Same problem, any solution yet? Link to comment Share on other sites More sharing options...
changa Posted October 19, 2020 Share Posted October 19, 2020 hello every body i changed my index.tpl so i customed it as well i can i want to display the list of product in a specify block but i dont know how to do it i have been working on it for a while now please someone can highlight me 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