Jump to content

Product list custom page for my module


kangoo13

Recommended Posts

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

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

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

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

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 : 

 

mini_141474Sanstitre.jpg

Link to comment
Share on other sites

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

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 :

 

 mini_820916Sanstitre.jpg

 

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 by kangoo13 (see edit history)
Link to comment
Share on other sites

  • 1 year later...

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 :

 

 mini_820916Sanstitre.jpg

 

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?

  • Like 1
Link to comment
Share on other sites

  • 2 years later...
  • 1 year later...
  • 4 months later...

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 

image.thumb.png.146d52d13a14ad1b6d6c645668598dd8.png

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...