Cesarph Posted September 29, 2021 Share Posted September 29, 2021 I am trying to display the highest price of the specific product on the product list page. I tried to add a function but it does not work (Prestashop 1.7.6.2). For example : I have a product with three different prices according by dimention : towel_1 dimention: 16x21 price=5$ towel_1 dimention: 50x100 price=10$ towel_1 dimention: 70x140 price=15$ I would like to display the price of 15$ on my catalog of that product. Can someone help me to create this function ? Regards, César Link to comment Share on other sites More sharing options...
ps8modules Posted September 29, 2021 Share Posted September 29, 2021 https://mypresta.eu/modules/front-office-features/product-price-range-from-to.html Link to comment Share on other sites More sharing options...
ps8modules Posted September 29, 2021 Share Posted September 29, 2021 (edited) $product_prices = array(); $getProductPrice = Db::getInstance()->executeS('SELECT id_product, price FROM '._DB_PREFIX_.'product') foreach ($getProductPrice as $p){ $getMaxProductPrice = Db::getInstance()->getValue('SELECT MAX(price) as max_pice FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.$p['id_product']); if ($getMaxProductPrice > 0){ $max = ($getMaxProductPrice + $p['price']); } else { $max = $p['price']; } $product_prices[] = array('id_product' => $p['id_product'], 'min_price' => $p['price'], 'max_price' => $max); } foreach ($product_prices as $product){ echo 'ID product: '.$product['id_product'].' - from '.$product['min_price'].' to '.$product['max_price'].'<br>'; } //print_r($product_prices); This is a sample without discounts, only with attributes. Edited September 29, 2021 by WebSoft (see edit history) 1 Link to comment Share on other sites More sharing options...
ps8modules Posted September 29, 2021 Share Posted September 29, 2021 (edited) Sample show formated price with tax: <?php @ini_set('display_errors', 'on'); @error_reporting(E_ALL | E_STRICT); include('./config/config.inc.php'); include('./init.php'); $product_prices = array(); $getProductPrice = Db::getInstance()->executeS('SELECT id_product, price FROM '._DB_PREFIX_.'product'); foreach ($getProductPrice as $p){ $getMaxProductPrice = Db::getInstance()->getRow('SELECT * FROM '._DB_PREFIX_.'product_attribute WHERE id_product = '.$p['id_product'].' ORDER BY price DESC'); if ($getMaxProductPrice['price'] > 0){ $max = Product::getPriceStatic($p['id_product'], true, $getMaxProductPrice['id_product_attribute']); } else { $max = Product::getPriceStatic($p['id_product'], true); } $product_prices[] = array('id_product' => $p['id_product'], 'min_price' => Tools::displayPrice($p['price']), 'max_price' => Tools::displayPrice($max)); } foreach ($product_prices as $product){ echo 'ID product: '.$product['id_product'].' - from '.$product['min_price'].' to '.$product['max_price'].'<br>'; } //print_r($product_prices); Result: Edited September 29, 2021 by WebSoft update script (see edit history) 1 Link to comment Share on other sites More sharing options...
Cesarph Posted September 30, 2021 Author Share Posted September 30, 2021 Hey WebSoft, thank you very much for you reply. i resolved my problem! 1 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