Jump to content

Recommended Posts

I want to be able to display the amount like this $7.00.

 

Instead it is displaying like this 7.

 

This is the code in my PHP script:

 

$cartplog['product_price'] = round(floatval($cartplog_product_info['price']), 2);

 

Am I looking at the right code?

How would I change this to reflect the desired result?

Link to comment
https://forums.phpfreaks.com/topic/88391-solved-pricing-in-php/
Share on other sites

Ok. Sorry to bring this back up, but I'm getting an error.

 

When I click to view cart it is showing a 0 for Total price.

 

With the original code I got a price of 7, a quantity of 1, and a total of 7 USD:

 

if ($cartplog_basket_check['products'])
{
	$cartplog_basket_check['products'] = unserialize($cartplog_basket_check['products']);
	if (!is_array($cartplog_basket_check['products']))
	{
		$cartplog_basket_check['products'] = array();
	}
	foreach($cartplog_basket_check['products'] AS $cartplog_basket_productid => $cartplog_basket_array)
	{
		$cartplog['basket_productid'] = intval($cartplog_basket_productid);
		$cartplog['basket_quantity'] = intval($cartplog_basket_array['quantity']);
		$cartplog['basket_thumb'] = strval($cartplog_basket_array['thumb']);
		$cartplog['basket_title'] = htmlspecialchars_uni($cartplog_basket_array['title']);
		$cartplog['basket_price'] = round(floatval($cartplog_basket_array['price']), 2);
		$cartplog['basket_options'] = nl2br(htmlspecialchars_uni($cartplog_basket_array['options']));
		$cartplog['basket_lineprice'] = round($cartplog['basket_quantity'] * $cartplog['basket_price'], 2);
		$cartplog['basket_total'] += $cartplog['basket_lineprice'];

		eval('$cartplog[\'basket_items\'] .= "' . fetch_template('cartplog_basket_item') . '";');

 

But when I make the change to $cartplog['basket_price'] I get a price of $7.00, a quantity of 1, and a total price of 0 USD.

This is the change I made:

if ($cartplog_basket_check['products'])
{
	$cartplog_basket_check['products'] = unserialize($cartplog_basket_check['products']);
	if (!is_array($cartplog_basket_check['products']))
	{
		$cartplog_basket_check['products'] = array();
	}
	foreach($cartplog_basket_check['products'] AS $cartplog_basket_productid => $cartplog_basket_array)
	{
		$cartplog['basket_productid'] = intval($cartplog_basket_productid);
		$cartplog['basket_quantity'] = intval($cartplog_basket_array['quantity']);
		$cartplog['basket_thumb'] = strval($cartplog_basket_array['thumb']);
		$cartplog['basket_title'] = htmlspecialchars_uni($cartplog_basket_array['title']);
		$cartplog['basket_price'] = '$' . number_format($cartplog_basket_array['price'], 2);
		$cartplog['basket_options'] = nl2br(htmlspecialchars_uni($cartplog_basket_array['options']));
		$cartplog['basket_lineprice'] = round($cartplog['basket_quantity'] * $cartplog['basket_price'], 2);
		$cartplog['basket_total'] +=  round(floatval($cartplog['basket_lineprice']), 2);

		eval('$cartplog[\'basket_items\'] .= "' . fetch_template('cartplog_basket_item') . '";');

 

I need it to show a price of $7.00, a quantity of 1 and a total of $7.00 USD.

Link to comment
https://forums.phpfreaks.com/topic/88391-solved-pricing-in-php/#findComment-452497
Share on other sites

The change SHOULD be made in the template instead of this code. But this should also make it work:

 

if ($cartplog_basket_check['products'])
{
	$cartplog_basket_check['products'] = unserialize($cartplog_basket_check['products']);
	if (!is_array($cartplog_basket_check['products']))
	{
		$cartplog_basket_check['products'] = array();
	}
	foreach($cartplog_basket_check['products'] AS $cartplog_basket_productid => $cartplog_basket_array)
	{
		$cartplog['basket_productid'] = intval($cartplog_basket_productid);
		$cartplog['basket_quantity'] = intval($cartplog_basket_array['quantity']);
		$cartplog['basket_thumb'] = strval($cartplog_basket_array['thumb']);
		$cartplog['basket_title'] = htmlspecialchars_uni($cartplog_basket_array['title']);
		$cartplog['basket_price'] = round(floatval($cartplog_basket_array['price']), 2);
		$cartplog['basket_options'] = nl2br(htmlspecialchars_uni($cartplog_basket_array['options']));
		$cartplog['basket_lineprice'] = round($cartplog['basket_quantity'] * $cartplog['basket_price'], 2);
		$cartplog['basket_total'] += $cartplog['basket_lineprice'];
		//Fix Basketprice
		$cartplog['basket_price'] = '$' . number_format($cartplog['basket_price'], 2);

		eval('$cartplog[\'basket_items\'] .= "' . fetch_template('cartplog_basket_item') . '";');

Link to comment
https://forums.phpfreaks.com/topic/88391-solved-pricing-in-php/#findComment-452587
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.