Struggling with some php code.

Hello, I’m no expert with php, but i like to think i can read it okay, just not always fix it!!

I am having some trouble with my website, the issue is when numbers are calculatated on the checkout form it comes up with hundreds of decimals!! I’m sure there must be an easy fix, but cant work it out.

Any help would be very much appriciated! Thanks in advance. Jamie.

The script i am using is php, but uses the yii framework. The code i think needs changing is:

[php] public function columns()
{
return array(
array(‘header’ => $this->t(‘Description’), ‘name’ => ‘description’),
array(‘header’ => $this->t(‘Quantity’),
‘value’ => ‘$data[“quantity”]!==null
? wm()->get(“payment.cart”)->quantityField($data)
: NULL’,
‘type’ => ‘raw’),
array(‘header’ => $this->t(‘Price’), ‘value’ => '$data[“price”]
? m(“payment”)->param(“cSymbol”)
. “<span class=‘price’>”.app()-

numberFormatter->formatDecimal($data[“price”]).""
: NULL’,
‘type’ => ‘raw’),
array(‘header’ => $this->t(‘Total’),
‘value’ => 'm(“payment”)->param(“cSymbol”) . "<span class=

‘total’>"
. app()->numberFormatter->formatDecimal(isset($data

[“total”])?$data[“total”]:$data[“quantity”]*$data[“price”]).""’,
‘type’ => ‘raw’),
);
}

public function dataProvider()
{
	$credit = wm()->get('payment.helper')->credit();
	if($credit)
		$this->put('payment',0,$this->t('Use my {site} credit: {credit}',
			array('{site}'=>app()->name,'{credit}' => m('payment')-

format($credit))),
0.25, -1);

	$data = array_values($this->_cart);
	
	$total = 0;
	foreach($data as $d)
		$total+= $d['price']*$d['quantity'];
	$data[] = array(
		'id' => 'total',
		'module' => 'payment',
		'description' => $this->t('My Price'),
		'quantity' => NULL,
		'price' => NULL,
		'total' => $total,
	);
	return new CArrayDataProvider($data);
}[/php]

maybe this would work:
[php]
$data[] = array(
‘id’ => ‘total’,
‘module’ => ‘payment’,
‘description’ => $this->t(‘My Price’),
‘quantity’ => NULL,
‘price’ => NULL,
‘total’ => number_format($total, 2) // changed from $total
);
[/php]

This would be the first thing i’d try… :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service