Jump to content

Custom variables in product card / miniature listing


Recommended Posts

Hi, I am a newbie in prestashop developing and I'm trying to do some change.

Basically I want that on category pages / search page / miniatures from product page, all product card to have one more variable.

I that all product with only 1 combination to have directly addtocart button, not select option button.

So I started with getting num of combinations of every product.. but this was the problem :)

I tried this: 

if($numarcomb = Db::getInstance()->executeS('SELECT COUNT(*) AS nrcomb FROM `ps_product_attribute` WHERE id_product = ' . $this->product->id . ''))
			$nrcomb = (int)$numarcomb[0]['nrcomb'];
		$this->context->smarty->assign('numar_comb', $nrcomb);

in ProductController, InitContent and output on miniatures/product.tpl 

It worked, but the problem is that for any product showed the num of combinations of the product accessed.

So the problem is that I didn't use the right controller.

Have any idea how can I do it?


Thank you.

Share this post

Link to post
Share on other sites


Ok, I tried to edit getProducts function in class Category.php with:

paa.COUNT(*) as numarcombinatii

LEFT JOIN `' . _DB_PREFIX_ . 'product_attribute` paa
                    ON p.`id_product` = paa.`id_product`

in the $sql.

Then I see that the result are sent to: Product.php : getProductsProperties function

and this one to getProductProperties for every product full variables.

So I added in getProductProperties:

$row['combinatii'] = $row['numarcombinatii'];

Now how can I pass this to product list? 

I read that these rows are called from tpl with $product.variable, but $product.combinatii is not working..

Can you help me please?

Share this post

Link to post
Share on other sites

14 hours ago, ventura said:

For these cases it is much better practice to use a specific hook for the product list, for example the hook, displayProductListReviews.

Hi. Thank you for response. I was thinking that way but I don't want to show it, I just need it for a condition in product list:

if number of combination > 1 => show Select option button

if number of combination <= 1  => show AddToCart button

I still can't find the product of catalog/partials/miniatures/product.tpl controller. Or I don't pass it the right way. 

Please help :(. Any idea I will appreciate it.

Share this post

Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More