Skip to content

Commit

Permalink
Fix/get earning by order string float error (#2489)
Browse files Browse the repository at this point in the history
* Add fees class suggestion.

* Parse float values

* Update bulk edit ui
Skip reverse withdrawal and advertisement product id

* Update bulk edit ui
Skip reverse withdrawal and advertisement product id
  • Loading branch information
Aunshon authored Dec 27, 2024
1 parent 58b74f1 commit 5743350
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions dokan-class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @class WeDevs_Dokan The class that holds the entire WeDevs_Dokan plugin
*
* @property WeDevs\Dokan\Commission $commission Instance of Commission class
* @property WeDevs\Dokan\Fees $fees Instance of Fees class
* @property WeDevs\Dokan\Order\Manager $order Instance of Order Manager class
* @property WeDevs\Dokan\Product\Manager $product Instance of Order Manager class
* @property WeDevs\Dokan\Vendor\Manager $vendor Instance of Vendor Manager Class
Expand Down
12 changes: 6 additions & 6 deletions includes/Commission.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public function get_earning_by_order( $order, $context = 'seller' ) {
$saved_admin_fee = $order->get_meta( '_dokan_admin_fee', true );

if ( $saved_admin_fee !== '' ) {
$saved_fee = ( 'seller' === $context ) ? $order->get_total() - $saved_admin_fee : $saved_admin_fee;
$saved_fee = ( 'seller' === $context ) ? floatval( $order->get_total() ) - floatval( $saved_admin_fee ) : $saved_admin_fee;

return apply_filters( 'dokan_order_admin_commission', $saved_fee, $order );
}
Expand All @@ -238,11 +238,11 @@ public function get_earning_by_order( $order, $context = 'seller' ) {
$product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
$refund = $order->get_total_refunded_for_item( $item_id );

if ( dokan_is_admin_coupon_applied( $order, $vendor_id, $product_id ) ) {
if ( dokan_is_admin_coupon_applied( $order, $vendor_id, $product_id ) && dokan()->is_pro_exists() ) {
$earning_or_commission += dokan_pro()->coupon->get_earning_by_admin_coupon( $order, $item, $context, $item->get_product(), $vendor_id, $refund );
} else {
$item_price = apply_filters( 'dokan_earning_by_order_item_price', $item->get_total(), $item, $order );
$item_price = $refund ? $item_price - $refund : $item_price;
$item_price = $refund ? floatval( $item_price ) - floatval( $refund ) : $item_price;

$item_earning_or_commission = $this->get_commission(
[
Expand All @@ -255,7 +255,7 @@ public function get_earning_by_order( $order, $context = 'seller' ) {
true
);
$item_earning_or_commission = 'admin' === $context ? $item_earning_or_commission->get_admin_commission() : $item_earning_or_commission->get_vendor_earning();
$earning_or_commission += $item_earning_or_commission;
$earning_or_commission += floatval( $item_earning_or_commission );
}
}

Expand All @@ -264,11 +264,11 @@ public function get_earning_by_order( $order, $context = 'seller' ) {
}

if ( $context === dokan()->fees->get_tax_fee_recipient( $order->get_id() ) ) {
$earning_or_commission += ( ( $order->get_total_tax() - $order->get_total_tax_refunded() ) - ( $order->get_shipping_tax() - dokan()->fees->get_total_shipping_tax_refunded( $order ) ) );
$earning_or_commission += ( ( floatval( $order->get_total_tax() ) - floatval( $order->get_total_tax_refunded() ) ) - ( floatval( $order->get_shipping_tax() ) - floatval( dokan()->fees->get_total_shipping_tax_refunded( $order ) ) ) );
}

if ( $context === dokan()->fees->get_shipping_tax_fee_recipient( $order ) ) {
$earning_or_commission += ( $order->get_shipping_tax() - dokan()->fees->get_total_shipping_tax_refunded( $order ) );
$earning_or_commission += ( floatval( $order->get_shipping_tax() ) - floatval( dokan()->fees->get_total_shipping_tax_refunded( $order ) ) );
}

$earning_or_commission = apply_filters_deprecated( 'dokan_order_admin_commission', [ $earning_or_commission, $order, $context ], '2.9.21', 'dokan_get_earning_by_order' );
Expand Down

0 comments on commit 5743350

Please sign in to comment.