Skip to content

Commit

Permalink
Continued rounding errors, ref #987
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Feb 1, 2018
1 parent 29b0c2f commit 11bf481
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 18 deletions.
59 changes: 42 additions & 17 deletions classes/wc-gateway-calculations-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
if (!class_exists('WC_Gateway_Calculation_AngellEYE')) :

class WC_Gateway_Calculation_AngellEYE {

public $order_total;
public $taxamt;
public $shippingamt;
Expand All @@ -25,7 +26,7 @@ public function __construct($payment_method = null) {
$this->order_items = array();
$this->is_adjust = false;
$this->payment_method = $payment_method;
if( $this->payment_method == 'paypal_pro_payflow' || $this->payment_method == 'paypal_advanced') {
if ($this->payment_method == 'paypal_pro_payflow' || $this->payment_method == 'paypal_advanced') {
$this->is_separate_discount = true;
}
$is_zdp_currency = in_array(get_woocommerce_currency(), $this->zdp_currencies);
Expand Down Expand Up @@ -135,7 +136,7 @@ public function cart_calculation() {
}

$this->order_total = round($this->itemamt + $this->taxamt + $this->shippingamt, $this->decimals);

if ($this->itemamt == $this->discount_amount) {
unset($this->order_items);
$this->itemamt -= $this->discount_amount;
Expand Down Expand Up @@ -256,7 +257,7 @@ public function order_calculation($order_id) {
$this->itemamt -= $this->discount_amount;
$this->order_total -= $this->discount_amount;
} else {
if( $this->is_separate_discount == false ) {
if ($this->is_separate_discount == false) {
if ($this->discount_amount > 0) {
$discLineItem = array(
'name' => 'Discount',
Expand Down Expand Up @@ -296,7 +297,7 @@ public function cart_re_calculate() {
}
}
$this->itemamt = round($temp_roundedPayPalTotal, $this->decimals);
if( $this->is_separate_discount == true ) {
if ($this->is_separate_discount == true) {
$this->temp_total = round($this->itemamt + $this->taxamt + $this->shippingamt - $this->discount_amount, $this->decimals);
} else {
$this->temp_total = round($this->itemamt + $this->taxamt + $this->shippingamt, $this->decimals);
Expand All @@ -315,10 +316,12 @@ public function cart_re_calculate() {
} else {
foreach ($this->order_items as $key => $value) {
if ($value['qty'] == 1 && $this->is_adjust == false) {
$this->order_items[$key]['amt'] = $this->order_items[$key]['amt'] + round($cartItemAmountDifference, $this->decimals);
$this->order_total += round($cartItemAmountDifference, $this->decimals);
$this->itemamt += round($cartItemAmountDifference, $this->decimals);
$this->is_adjust = true;
if ($this->order_items[$key]['amt'] * 1000 > 0) {
$this->order_items[$key]['amt'] = $this->order_items[$key]['amt'] + round($cartItemAmountDifference, $this->decimals);
$this->order_total += round($cartItemAmountDifference, $this->decimals);
$this->itemamt += round($cartItemAmountDifference, $this->decimals);
$this->is_adjust = true;
}
}
}
if ($this->is_adjust == false) {
Expand All @@ -329,6 +332,7 @@ public function cart_re_calculate() {
}
}
}
$this->angelleye_disable_line_item();
}

public function order_re_calculate($order) {
Expand All @@ -339,7 +343,7 @@ public function order_re_calculate($order) {
}
}
$this->itemamt = $temp_roundedPayPalTotal;
if( $this->is_separate_discount == true ) {
if ($this->is_separate_discount == true) {
$this->temp_total = round($this->itemamt + $this->taxamt + $this->shippingamt - $this->discount_amount, $this->decimals);
} else {
$this->temp_total = round($this->itemamt + $this->taxamt + $this->shippingamt, $this->decimals);
Expand All @@ -358,10 +362,12 @@ public function order_re_calculate($order) {
} else {
foreach ($this->order_items as $key => $value) {
if ($value['qty'] == 1 && $this->is_adjust == false) {
$this->order_items[$key]['amt'] = $this->order_items[$key]['amt'] + round($cartItemAmountDifference, $this->decimals);
$this->order_total += round($cartItemAmountDifference, $this->decimals);
$this->itemamt += round($cartItemAmountDifference, $this->decimals);
$this->is_adjust = true;
if ($this->order_items[$key]['amt'] * 1000 > 0) {
$this->order_items[$key]['amt'] = $this->order_items[$key]['amt'] + round($cartItemAmountDifference, $this->decimals);
$this->order_total += round($cartItemAmountDifference, $this->decimals);
$this->itemamt += round($cartItemAmountDifference, $this->decimals);
$this->is_adjust = true;
}
}
}
if ($this->is_adjust == false) {
Expand All @@ -372,6 +378,7 @@ public function order_re_calculate($order) {
}
}
}
$this->angelleye_disable_line_item();
}

public function get_giftcard_amount($order_id = null) {
Expand All @@ -392,13 +399,13 @@ public function get_giftcard_amount($order_id = null) {
return false;
}
}

public function yith_get_giftcard_amount() {
if (class_exists('YITH_YWGC_Cart_Checkout')) {
$amount = 0;
if ( isset( WC()->cart->applied_gift_cards ) ) {
foreach ( WC()->cart->applied_gift_cards as $code ) {
$amount += isset( WC()->cart->applied_gift_cards_amounts[ $code ] ) ? WC()->cart->applied_gift_cards_amounts[ $code ] : 0;
if (isset(WC()->cart->applied_gift_cards)) {
foreach (WC()->cart->applied_gift_cards as $code) {
$amount += isset(WC()->cart->applied_gift_cards_amounts[$code]) ? WC()->cart->applied_gift_cards_amounts[$code] : 0;
}
}
return $amount;
Expand All @@ -407,11 +414,29 @@ public function yith_get_giftcard_amount() {
}
}

public function angelleye_disable_line_item() {
if ($this->shippingamt * 1000 < 0) {
unset($this->order_items);
$this->order_total = WC()->cart->total;
$this->itemamt = WC()->cart->total;
}

if ($this->itemamt * 1000 < 0) {
unset($this->order_items);
$this->order_total = WC()->cart->total;
$this->itemamt = WC()->cart->total;
}
}

}










endif;
4 changes: 3 additions & 1 deletion classes/wc-gateway-paypal-advanced-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -1461,7 +1461,9 @@ public function save_payment_token($order, $payment_tokens_id) {
public function angelleye_paypal_advanced_encrypt_gateway_api($settings) {
if( !empty($settings['resellerid'])) {
$resellerid = $settings['resellerid'];
}
} else {
$resellerid = '';
}
if(strlen($resellerid) > 28 ) {
return $settings;
}
Expand Down

0 comments on commit 11bf481

Please sign in to comment.