bigcommerce-for-wordpress
                                
                                
                                
                                    bigcommerce-for-wordpress copied to clipboard
                            
                            
                            
                        Negative tax value on cart page when we have discounted product in the cart.
Expected behavior
Taxes should not show negative value
Actual behavior
Taxes showed as negative value
Steps to reproduce behavior
- Add product to cart which have a discount for customer groups created in promotions.
 - Go to cart there will be negative value for tax
 
Screenshot/Video (if applicable)


Workaround or possible solution
On Cart_Mapper.php we have method calculate_total_tax, where tax calculation is happening.
private function calculate_total_tax( $cart_amount, $discount_amount, $coupons_discount_amount, $items ) {
  $item_sum = array_sum( array_map( function ( $item ) {
	  return isset( $item[ 'total_list_price' ][ 'raw' ] ) ? $item[ 'total_list_price' ][ 'raw' ] : 0;
  }, $items ) );
  
  return $cart_amount + $discount_amount + $coupons_discount_amount - $item_sum;
}
In my case I had such values in the cart (product price 360 with 10% discount = 324) $cart_amount = 324 $discount_amount = 0 $coupon_discount_amoun = 0 $item_sum (total_list_price) = 360 Which lead to negative tax value of -36
As possible solution to resolve that issue we can to use total_sale_price, not total_list_price in calculations like this ->
private function calculate_total_tax( $cart_amount, $discount_amount, $coupons_discount_amount, $items ) {
  $item_sum = array_sum( array_map( function ( $item ) {
	  return isset( $item[ 'total_sale_price' ][ 'raw' ] ) ? $item[ 'total_sale_price' ][ 'raw' ] : 0;
  }, $items ) );
  
  return $cart_amount + $discount_amount + $coupons_discount_amount - $item_sum;
}