Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calculation when divided by zero. If anywhere, any value is divid… #23

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions includes/Helpers/MigrationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,12 +203,13 @@ public static function split_parent_order_shipping( $applied_shipping_method, $o

$applied_shipping_method = reset( $parent_order->get_shipping_methods() );
$vendors = dokan_get_sellers_by( $parent_order->get_id() );
$vendors_count = empty( count( $vendors ) ) ? 1 : count( $vendors );

// Here we are dividing the shipping and shipping-tax amount of parent order into the vendors suborders.
$shipping_tax_amount = [
'total' => [ $applied_shipping_method->get_total_tax() / count( $vendors ) ],
'total' => [ $applied_shipping_method->get_total_tax() / $vendors_count ],
];
$shipping_amount = $applied_shipping_method->get_total() / count( $vendors );
$shipping_amount = $applied_shipping_method->get_total() / $vendors_count;

// Generating the shipping for vendor.
$item = new WC_Order_Item_Shipping();
Expand Down
4 changes: 3 additions & 1 deletion includes/Integrations/WcVendors/OrderMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) {
'created' => $order->time,
];

$unit_commissin_rate_vendor = ( $order->total_due / $wc_order->get_subtotal() ) * 100;
$non_zero_sub_total_amount = empty( $wc_order->get_subtotal() ) || $wc_order->get_subtotal() < 1 ? 1 : $wc_order->get_subtotal();

$unit_commissin_rate_vendor = ( $order->total_due / $non_zero_sub_total_amount ) * 100;
$unit_commissin_rate_admin = 100 - $unit_commissin_rate_vendor;
$new_admin_commissin = ( $wc_order->get_subtotal() * $unit_commissin_rate_admin ) / 100;

Expand Down
11 changes: 7 additions & 4 deletions includes/Integrations/Wcfm/OrderMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) {
'created' => $order->created,
];

$unit_commissin_rate_vendor = ( $order->commission_amount / $order->item_sub_total ) * 100;
$non_zero_item_sub_total_amount = empty( $order->item_sub_total ) || $order->item_sub_total < 1 ? 1 : $order->item_sub_total;

$unit_commissin_rate_vendor = ( $order->commission_amount / $non_zero_item_sub_total_amount ) * 100;
$unit_commissin_rate_admin = 100 - $unit_commissin_rate_vendor;
$new_admin_commissin = ( $order->item_sub_total * $unit_commissin_rate_admin ) / 100;

Expand Down Expand Up @@ -217,7 +219,7 @@ public function process_refund( $child_order, $seller_id, $from_suborder = true
$shipping_item_id = $vendor_shipping[ $vendor_id ]['shipping_item_id'];
$package_qty = absint( $vendor_shipping[ $vendor_id ]['package_qty'] );

! $package_qty ? $package_qty = $line_item->get_quantity() : '';
! $package_qty ? $package_qty = $line_item->get_quantity() : 1;

$shipping_item = new \WC_Order_Item_Shipping( $shipping_item_id );
$refund_shipping_tax = $shipping_item->get_taxes();
Expand Down Expand Up @@ -410,12 +412,13 @@ public function split_parent_order_shipping( $applied_shipping_method, $order_id

$applied_shipping_method = reset( $parent_order->get_shipping_methods() );
$vendors = $this->get_seller_by_order( $parent_order->get_id() );
$vendors_count = empty( count( $vendors ) ) ? 1 : count( $vendors );

// Here we are dividing the shipping and shipping-tax amount of parent order into the vendors suborders.
$shipping_tax_amount = [
'total' => [ $applied_shipping_method->get_total_tax() / count( $vendors ) ],
'total' => [ $applied_shipping_method->get_total_tax() / $vendors_count ],
];
$shipping_amount = $applied_shipping_method->get_total() / count( $vendors );
$shipping_amount = $applied_shipping_method->get_total() / $vendors_count;

// Generating the shipping for vendor.
$item = new WC_Order_Item_Shipping();
Expand Down
4 changes: 3 additions & 1 deletion includes/Migrator/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,9 @@ public function migrate( $import_type, $plugin, $data ) {
'paged' => $this->paged,
];

$progress = ( $args['total_migrated'] * 100 ) / $this->total_count;
$total_count = empty( $this->total_count ) ? 1 : $this->total_count;

$progress = ( $args['total_migrated'] * 100 ) / $total_count;

if ( $progress < 100 ) {
$this->update_migration_status( $args, $import_type );
Expand Down
Loading