bastienu Posted April 15, 2021 Share Posted April 15, 2021 Hi! 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 € ) etc. 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] => ) etc. Do you know why the values are not the same on this two pages? How to solve this problem? Thanks. Link to comment Share on other sites More sharing options...
bastienu Posted April 17, 2021 Author Share Posted April 17, 2021 Up ? Link to comment Share on other sites More sharing options...
bastienu Posted April 19, 2021 Author Share Posted April 19, 2021 Anyone ? 😞 Link to comment Share on other sites More sharing options...
musicmaster Posted April 19, 2021 Share Posted April 19, 2021 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). 1 Link to comment Share on other sites More sharing options...
bastienu Posted April 19, 2021 Author Share Posted April 19, 2021 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 p.*, pl.*, product_shop.*, sa.out_of_stock, IFNULL(sa.quantity, 0) as quantity, (DATEDIFF( p.`date_add`, DATE_SUB( '$now', 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 🙂 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