Jump to content

Smarty assign all products to .tpl


muynck

Recommended Posts

I made my very first plugin :D , however, I want to show all products in a .tpl. So far it wasn't a problem in the php-file I made. But i really want to manipulate it through a controller, as recommended.

 

It ALMOST works, I found a snippet with this: 

$this->context->smarty->assign(
    'products', $this->context->cart->getProducts()
);
$this->setTemplate('details.tpl'); 

This shows all products in the cart... not exactly what I need.

 
Who can help me change this in to all products available in the shop?
 
I have another snippet that works fine with a php file and a template, maybe it helps:
 
$this->context->smarty->assign(array(
    'products' => Product::getNewProducts(intval($cookie->id_lang), 0, 100000, false, $orderBy, $orderWay)
)
);

I set the limit to 100,000, if you know another way, more professional, please let me know.

 

Help would be very appreciated.

 

Edit: PS 1.5

Edited by muynck (see edit history)
Link to comment
Share on other sites

hi

 

for PS 1.5.6.1 you have one function in classes=>product.php

/**
	* Get all available products
	*
	* @param integer $id_lang Language id
	* @param integer $start Start number
	* @param integer $limit Number of products to return
	* @param string $order_by Field for ordering
	* @param string $order_way Way for ordering (ASC or DESC)
	* @return array Products details
	*/
	public static function getProducts($id_lang, $start, $limit, $order_by, $order_way, $id_category = false,$only_active = false, Context $context = null)

then for all products

$id_lang = (int)$this->context->language->id;​
$limit =0;
$products =array();
$products = product::getProducts($id_lang,$limit);
$this->context->smarty->assign(products; $products);

 $limit = 0; => all products

 

for your tpl you can adapt the product-list.tpl of your theme and  the product_list.css

 

@++

 

loulou66

Edited by loulou66 (see edit history)
Link to comment
Share on other sites

@loulou66

 

Your code seems very plausible, but it still doesn't work. I had a lot of scripts alike. This is the full code now, which gives a blanc page:

if (!defined('_PS_VERSION_'))
exit;

class alphabetDetailsModuleFrontController extends ModuleFrontController
{
public function initContent()
{
parent::initContent();

$id_lang = (int)$this->context->language->id;​
$limit =0;
$products =array();
$products = product::getProducts($id_lang,$limit);
$this->context->smarty->assign(products; $products);

$this->setTemplate('details.tpl');
}
}

@vekia

 

I'm fully aware of that. I really want to show all products on one page. It will be somewhere around 300 products.

 

I'm thinking about loading it with AJAX after scrolling... But first get the whole list :D

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...