Forums / General Questions / Display product price in product listing titles

Display product price in product listing titles

Started by nick1973 on 24 Jun 2017, 6:38 PM · Views: 308

Results 1 to 5 of 5
24 Jun 2017, 6:38 PM
#1
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Display product price in product listing titles

I need to move the price in the product listing so it sits just under the title.

I can do this by adding . $listing->fields['products_price'] . like this . $listing->fields['products_name'] . $listing->fields['products_price'] .

But it adds two extra zero's on the end so the price displays like this 72.0000

I did it before but can't remember how to strip the extra zero's.

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk

24 Jun 2017, 6:56 PM
#2
lankeeyankee avatar

lankeeyankee

Totally Zenned

Join Date:
Jan 2007
Posts:
1,514
Plugin Contributions:
1

Re: Display product price in product listing titles

You can permanently change it to 2 decimals in includes/functions/functions_prices, I think there are 4 places to change from 4 to 2. Or you can do round($listing->fields['products_price'], 2) to apply 2 decimal rounding just for that part.


Zen Cart and it's community are the best!!

24 Jun 2017, 9:50 PM
#3
davewest avatar

davewest

Totally Zenned

Join Date:
Dec 2007
Location:
Payson, AZ
Posts:
1,075
Plugin Contributions:
7

Re: Display product price in product listing titles

Nick1973:

$listing->fields['products_name'] . $listing->fields['products_price'] .
.

try

$currencies->format($listing->fields['products_price']);

Which should match whatever currencies the user selected.

Dave
Always forward thinking... Lost my mind!

25 Jun 2017, 8:41 AM
#4
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Display product price in product listing titles

davewest:

try

$currencies->format($listing->fields['products_price']);

> 
> Which should match whatever currencies the user selected.

That seems to work without any need to edit includes/functions/functions_prices

Thanks to both of you for these suggestions, davewest - yours is the one I will use as its more simple.

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk

25 Jun 2017, 8:55 AM
#5
nick1973 avatar

nick1973

Totally Zenned

Join Date:
Sep 2008
Location:
Cleethorpes
Posts:
1,230
Plugin Contributions:
3

Re: Display product price in product listing titles

Even better - I realised after implementing davewest's solution, which works, what happens if I apply a special offer? That solution doesn't pick up the offer.

So I just moved from roughly line 106 just below case 'PRODUCT_LIST_PRICE':

$lc_price = zen_get_products_display_price($listing->fields['products_id'])

So now my Product Listing Title in modules/TEMPLATENAME/product_listing.php looks like this:

$lc_text = '<h3 class="itemTitle"><a href="' . zen_href_link(zen_get_info_page($listing->fields['products_id']), 'cPath=' . (($_GET['manufacturers_id'] > 0 and $_GET['filter_id'] > 0) ? zen_get_generated_category_path_rev($_GET['filter_id']) : ($_GET['cPath'] > 0 ? zen_get_generated_category_path_rev($_GET['cPath']) : zen_get_generated_category_path_rev($listing->fields['master_categories_id']))) . '&products_id=' . $listing->fields['products_id']) . '">' . $listing->fields['products_name'] . '<br /><h2>' . $lc_price = zen_get_products_display_price($listing->fields['products_id']) . '</h2>' . '</a></h3><div class="listingDescription">' . zen_trunc_string((stripslashes(zen_get_products_description($listing->fields['products_id'], $_SESSION['languages_id']))), PRODUCT_LIST_DESCRIPTION) . '</div>';

Then on line 108 I just commented out $lc_text = $lc_price; - this is to stop the price from displaying twice on the product listing.

Like this:

/$lc_text = $lc_price;/

Nick Smith - Venture Design and Print
https://venturedesignandprint.co.uk