Skip to content

Commit

Permalink
Merge pull request #70 from Billmate/issue-10
Browse files Browse the repository at this point in the history
Fixes issue #10
  • Loading branch information
NiklasHogefjord committed Nov 1, 2020
2 parents 6f17247 + fb98a11 commit 38fe8c3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions classes/requests/helpers/cart/class-bco-cart-articles-helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static function get_cart_lines( $cart_item ) {
'aprice' => self::get_article_price( $cart_item ),
'withouttax' => self::get_without_tax( $cart_item ),
'taxrate' => self::get_tax_rate( $cart_item ),
'discount' => self::get_discount( $cart_item ),
);
}

Expand Down Expand Up @@ -130,4 +131,22 @@ public static function get_tax_rate( $cart_item ) {
return round( $tax_rate );
}

/**
* Get cart item discount
*
* @param array $cart_item Cart item.
* @return int $discount Discount in %.
*/
public static function get_discount( $cart_item ) {
$article_price = wc_get_price_excluding_tax( $cart_item['data'] );
$line_total = $cart_item['line_total'];

if ( ( $article_price * $cart_item['quantity'] ) !== $line_total ) {
return round( ( 1 - ( $line_total / ( $article_price * $cart_item['quantity'] ) ) ) * 100 );
} else {
return 0;
}
return round( $item_subtotal * 100 );
}

}

0 comments on commit 38fe8c3

Please sign in to comment.