Jump to content

Unit_price not available on category page listing products


Recommended Posts



I'm updating some files of my theme and I want to display the products unit_price and country origin.

No problem on country origin: it's a featured product value, everything is ok.


The problem is on the unit_price. I have updated the product-miniature-2.tpl called in product.tpl.

On my home page, everything is ok, I have the information as you can see here on image 1.


But, with the same files called (i.e. product-miniature-2.tpl) the information of the unit_price is not available on the category page, on Image 2.


So I used a {$product|print_r} in product.tpl and the result I get is different.


For a same product, on the homepage, I have this (extract):

[product:protected] => Array ( [id_product] => 91 [id_supplier] => 15


[unity] => kg [unit_price_ratio] => 1.000000


[unit_price] => 2,90 


[unit_price_full] => 2,90  kg


[unit_price_ratio] => Array ( [type] => variable [value] => 1.000000 )


[unit_price] => Array ( [type] => variable [value] => 2,90  )




But on the category page,  for the same product, I get :

[product:protected] => Array ( [id_product] => 91 [id_supplier] => 15


[unity] => kg [unit_price_ratio] => 0.000000


[unit_price] => 


[unit_price_full] => 


[unit_price_ratio] => Array ( [type] => variable [value] => 0.000000 )


[unit_price] => Array ( [type] => variable [value] => )



Do you know why the values are not the same on this two pages?

How to solve this problem?



Image 1 - Homepage.png

Image 2 - Category.png

Share this post

Link to post
Share on other sites

Obviously different queries have been called for the two pages. So you have to find out which queries. The best way is to enabled profiling in /config/defines.in.php. That will produce a list of queries at the bottom of the page with to the right of them their place in the filesystem (filename and line number).

  • Like 1

Share this post

Link to post
Share on other sites

Thanks musicmaster for your help!


For those who are looking for a solution to display unit_price on category page list, here is the solution.

The problem is that product are displayed after a call to method addMissingProductFields in ProductAssembler class. In this method, product table field are retrieved. Only...


So the solution is to update the SQL query in /classes/ProductAssembler.php (around line 68), like this:

$sql = "SELECT
                    IFNULL(sa.quantity, 0) as quantity,
                    INTERVAL $nbDaysNewProduct DAY
            ) > 0) as new
                FROM {$prefix}product p
                " . Shop::addSqlAssociation('product', 'p') . "
                LEFT JOIN {$prefix}product_lang pl
                    ON pl.id_product = p.id_product
                    AND pl.id_shop = $idShop
                    AND pl.id_lang = $idLang
                LEFT JOIN {$prefix}stock_available sa
                    ON sa.id_product = p.id_product 
                    AND sa.id_shop = $idShop
                WHERE p.id_product = $idProduct";

with "product_shop.*" in SELECT block and " . Shop::addSqlAssociation('product', 'p') . " in FROM block.

This way, you have all data you need. 


Of course, use overrides to make this change !


Thanks 🙂

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