Skip to content

Commit

Permalink
Make PayPal total match OpenCart total
Browse files Browse the repository at this point in the history
As PayPal uses less precision in its calculations, its total can differ
from the cart total. Calculating subtotal this way ensures they match.
  • Loading branch information
ADDCreative committed Nov 24, 2015
1 parent 795bf86 commit c34c867
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions upload/catalog/controller/payment/pp_standard.php
Expand Up @@ -24,6 +24,8 @@ public function index() {


$data['products'] = array(); $data['products'] = array();


$subtotal = 0;

foreach ($this->cart->getProducts() as $product) { foreach ($this->cart->getProducts() as $product) {
$option_data = array(); $option_data = array();


Expand All @@ -46,10 +48,13 @@ public function index() {
); );
} }


$price = $this->currency->format($product['price'], $order_info['currency_code'], false, false);
$subtotal += $price * $product['quantity'];

$data['products'][] = array( $data['products'][] = array(
'name' => htmlspecialchars($product['name']), 'name' => htmlspecialchars($product['name']),
'model' => htmlspecialchars($product['model']), 'model' => htmlspecialchars($product['model']),
'price' => $this->currency->format($product['price'], $order_info['currency_code'], false, false), 'price' => $price,
'quantity' => $product['quantity'], 'quantity' => $product['quantity'],
'option' => $option_data, 'option' => $option_data,
'weight' => $product['weight'] 'weight' => $product['weight']
Expand All @@ -58,7 +63,7 @@ public function index() {


$data['discount_amount_cart'] = 0; $data['discount_amount_cart'] = 0;


$total = $this->currency->format($order_info['total'] - $this->cart->getSubTotal(), $order_info['currency_code'], false, false); $total = $this->currency->format($this->currency->convert($order_info['total'], $this->config->get('config_currency'), $order_info['currency_code']) - $subtotal, $order_info['currency_code'], 1.0, false);


if ($total > 0) { if ($total > 0) {
$data['products'][] = array( $data['products'][] = array(
Expand Down

0 comments on commit c34c867

Please sign in to comment.