Skip to content

Commit

Permalink
YITH Gift Cards Compatibility, ref #949
Browse files Browse the repository at this point in the history
  • Loading branch information
kcppdevelopers committed Nov 30, 2017
1 parent 9ad3778 commit 30d08cf
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion classes/wc-gateway-calculations-angelleye.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
if (!class_exists('WC_Gateway_Calculation_AngellEYE')) :

class WC_Gateway_Calculation_AngellEYE {

public $order_total;
public $taxamt;
public $shippingamt;
Expand Down Expand Up @@ -53,6 +52,9 @@ public function cart_calculation() {
if ($this->get_giftcard_amount() != false) {
$this->discount_amount = round($this->discount_amount + $this->get_giftcard_amount(), $this->decimals);
}
if ($this->yith_get_giftcard_amount() != false) {
$this->discount_amount = round($this->discount_amount + $this->yith_get_giftcard_amount(), $this->decimals);
}
if (WC()->cart->has_discount() && $this->discount_amount == 0) {
$applied_coupons = WC()->cart->get_applied_coupons();
if (!empty($applied_coupons)) {
Expand Down Expand Up @@ -133,6 +135,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 @@ -179,6 +182,12 @@ public function order_calculation($order_id) {
if ($order->get_discount_total() > 0 && $this->discount_amount == 0) {
$this->discount_amount = round($order->get_discount_total(), $this->decimals);
}
if ($this->get_giftcard_amount($order_id) != false) {
$this->discount_amount = round($this->discount_amount + $this->get_giftcard_amount($order_id), $this->decimals);
}
if ($this->yith_get_giftcard_amount() != false) {
$this->discount_amount = round($this->discount_amount + $this->yith_get_giftcard_amount(), $this->decimals);
}
$desc = '';
foreach ($order->get_items() as $cart_item_key => $values) {
$product = $order->get_product_from_item($values);
Expand Down Expand Up @@ -383,6 +392,20 @@ 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;
}
}
return $amount;
} else {
return false;
}
}

}

Expand Down

0 comments on commit 30d08cf

Please sign in to comment.