Skip to content

Commit

Permalink
Merge pull request #70 from angelleye/PFWMA-176
Browse files Browse the repository at this point in the history
Changed discount logic, use item base discount instead of cart discount partitions, PFWMA-176
  • Loading branch information
kcppdevelopers authored Oct 5, 2020
2 parents a39a5de + a514e4e commit 90e3128
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew
if ($line_item['subtotal'] != $line_item['total']) {
$this->map_item_with_account[$product_id]['is_discountable'] = true;
$this->angelleye_is_discountable = $this->angelleye_is_discountable + 1;
$discount_amount = $line_item['subtotal'] - $line_item['total'];
if($discount_amount > 0) {
$this->map_item_with_account[$product_id]['discount'] = $discount_amount;
}
} else {
$this->map_item_with_account[$product_id]['is_discountable'] = false;
}
Expand Down Expand Up @@ -449,6 +453,10 @@ public function angelleye_get_account_for_ec_parallel_payments($gateways, $gatew
if ($cart_item['line_subtotal'] != $cart_item['line_total']) {
$this->map_item_with_account[$product_id]['is_discountable'] = true;
$this->angelleye_is_discountable = $this->angelleye_is_discountable + 1;
$discount_amount = $cart_item['line_subtotal'] - $cart_item['line_total'];
if($discount_amount > 0) {
$this->map_item_with_account[$product_id]['discount'] = $cart_item['line_subtotal'] - $cart_item['line_total'];
}
} else {
$this->map_item_with_account[$product_id]['is_discountable'] = false;
}
Expand Down Expand Up @@ -677,12 +685,11 @@ public function angelleye_modified_ec_parallel_parameter($request, $gateways, $o
$this->taxamt = 0;
}
$this->shippingamt = round(WC()->cart->shipping_total, $this->decimals);
$this->discount_amount = round(WC()->cart->get_cart_discount_total(), $this->decimals);
if (isset($this->shippingamt) && $this->shippingamt > 0) {
if (!empty($this->map_item_with_account)) {
$packages = WC()->shipping()->get_packages();
$chosen_shipping_methods = WC()->session->get('chosen_shipping_methods');
if(!empty($packages) && !empty($chosen_shipping_methods)) {
if(!empty($packages) && !empty($chosen_shipping_methods) && count($packages) > 1) {
foreach ( $packages as $package_key => $package ) {
if ( isset( $chosen_shipping_methods[ $package_key ], $package['rates'][ $chosen_shipping_methods[ $package_key ] ] ) ) {
$shipping_rate = $package['rates'][ $chosen_shipping_methods[ $package_key ] ];
Expand All @@ -700,6 +707,7 @@ public function angelleye_modified_ec_parallel_parameter($request, $gateways, $o
}
$this->shipping_array = $this->angelleye_get_extra_fee_array($this->shippingamt, $this->angelleye_needs_shipping, 'shipping');
}
$this->discount_amount = round(WC()->cart->get_cart_discount_total(), $this->decimals);
if (isset($this->discount_amount) && $this->discount_amount > 0) {
$this->discount_array = $this->angelleye_get_extra_fee_array($this->discount_amount, $this->angelleye_is_discountable, 'discount');
}
Expand Down Expand Up @@ -1520,7 +1528,7 @@ public function angelleye_get_extra_fee_array($amount, $divided, $type) {
break;
case "discount":
if (!empty($item_with_account['is_discountable']) && $item_with_account['is_discountable'] === true) {
$partition_array[$product_id] = $partition_array[$loop];
$partition_array[$product_id] = isset($item_with_account['discount']) ? $item_with_account['discount'] : $partition_array[$loop];
unset($partition_array[$loop]);
$loop = $loop + 1;
}
Expand Down

0 comments on commit 90e3128

Please sign in to comment.