From 2a3a16a2f08e25500b04344e99766ba14201d18b Mon Sep 17 00:00:00 2001 From: Aunshon Date: Thu, 19 Sep 2024 15:24:24 +0600 Subject: [PATCH 1/2] =?UTF-8?q?Fix=20calculation=20when=20divided=20by=20z?= =?UTF-8?q?ero.=20If=20anywhere,=20any=20value=20is=20divid=E2=80=A6=20(#2?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix calculation when divided by zero. If anywhere, any value is divided by zero, there can be a fatal. * Fix brand name and github url --- dokan-migrator.php | 6 +++--- includes/Helpers/MigrationHelper.php | 5 +++-- includes/Integrations/WcVendors/OrderMigrator.php | 4 +++- includes/Integrations/Wcfm/OrderMigrator.php | 11 +++++++---- includes/Migrator/Manager.php | 4 +++- readme.txt | 2 +- 6 files changed, 20 insertions(+), 12 deletions(-) diff --git a/dokan-migrator.php b/dokan-migrator.php index 8764dbd..a1d7e81 100644 --- a/dokan-migrator.php +++ b/dokan-migrator.php @@ -1,11 +1,11 @@ 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(); diff --git a/includes/Integrations/WcVendors/OrderMigrator.php b/includes/Integrations/WcVendors/OrderMigrator.php index 806c972..087c75b 100644 --- a/includes/Integrations/WcVendors/OrderMigrator.php +++ b/includes/Integrations/WcVendors/OrderMigrator.php @@ -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; diff --git a/includes/Integrations/Wcfm/OrderMigrator.php b/includes/Integrations/Wcfm/OrderMigrator.php index e5190ef..b75877f 100644 --- a/includes/Integrations/Wcfm/OrderMigrator.php +++ b/includes/Integrations/Wcfm/OrderMigrator.php @@ -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; @@ -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(); @@ -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(); diff --git a/includes/Migrator/Manager.php b/includes/Migrator/Manager.php index a61282a..e21e4d5 100644 --- a/includes/Migrator/Manager.php +++ b/includes/Migrator/Manager.php @@ -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 ); diff --git a/readme.txt b/readme.txt index fb11423..a08bcae 100644 --- a/readme.txt +++ b/readme.txt @@ -68,7 +68,7 @@ Note: Ensure you click the “Activate Dokan Vendor Dashboard” button. It wil **CONTACT US** - Get free help from us [here](https://wedevs.com/contact/) -- Report a bug or request a feature through [GitHub](https://github.com/weDevsOfficial/dokan). +- Report a bug or request a feature through [GitHub](https://github.com/getdokan/dokan-migrator/issues). - Check out all functions of Dokan. == Installation == From 43841ca13227fa7a0ed0553928c864fc107e06a0 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Thu, 19 Sep 2024 15:41:12 +0600 Subject: [PATCH 2/2] chore: bump version to 1.1.2 --- README.md | 4 ++-- dokan-migrator.php | 4 ++-- languages/dokan-migrator.pot | 16 ++++++++-------- package.json | 2 +- readme.txt | 10 ++++++++-- 5 files changed, 21 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index ae05474..a200be6 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ **Requires at least:** 5.8 **Tested up to:** 6.4.2 **WC tested up to:** 8.4.0 -**Requires PHP:** 7.3 -**Stable tag:** 1.1.0 +**Requires PHP:** 7.4 +**Stable tag:** 1.1.2 **License:** GPLv2 or later **License URI:** http://www.gnu.org/licenses/gpl-2.0.html diff --git a/dokan-migrator.php b/dokan-migrator.php index a1d7e81..5097c89 100644 --- a/dokan-migrator.php +++ b/dokan-migrator.php @@ -3,7 +3,7 @@ * Plugin Name: Dokan Migrator * Plugin URI: https://dokan.co/wordpress/ * Description: An e-commerce marketplace migration plugin for WordPress. Powered by WooCommerce and WeDevs. - * Version: 1.1.1 + * Version: 1.1.2 * Author: weDevs * Author URI: https://dokan.co/ * Domain Path: /languages/ @@ -56,7 +56,7 @@ final class Dokan_Migrator { * * @var string */ - public $version = '1.1.1'; + public $version = '1.1.2'; /** * Instance of self diff --git a/languages/dokan-migrator.pot b/languages/dokan-migrator.pot index a65a615..b7e5841 100644 --- a/languages/dokan-migrator.pot +++ b/languages/dokan-migrator.pot @@ -1,16 +1,16 @@ -# Copyright (c) 2023 weDevs Pte. Ltd. All Rights Reserved. +# Copyright (c) 2024 weDevs Pte. Ltd. All Rights Reserved. msgid "" msgstr "" -"Project-Id-Version: Dokan Migrator 1.1.1\n" +"Project-Id-Version: Dokan Migrator 1.1.2\n" "Report-Msgid-Bugs-To: https://github.com/weDevsOfficial/dokan-migrator/issues\n" "Last-Translator: support@wedevs.com\n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2023-12-15T04:54:27+00:00\n" +"POT-Creation-Date: 2024-09-19T09:37:59+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"X-Generator: WP-CLI 2.8.1\n" +"X-Generator: WP-CLI 2.9.0\n" "X-Domain: dokan-migrator\n" #. Plugin Name of the plugin @@ -20,7 +20,7 @@ msgid "Dokan Migrator" msgstr "" #. Plugin URI of the plugin -msgid "http://WeDevs.com/" +msgid "https://dokan.co/wordpress/" msgstr "" #. Description of the plugin @@ -28,11 +28,11 @@ msgid "An e-commerce marketplace migration plugin for WordPress. Powered by WooC msgstr "" #. Author of the plugin -msgid "WeDevs" +msgid "weDevs" msgstr "" #. Author URI of the plugin -msgid "https://WeDevs.com/" +msgid "https://dokan.co/" msgstr "" #: includes/Helpers/MigrationHelper.php:70 @@ -63,7 +63,7 @@ msgstr "" msgid "Nonce verification failed!" msgstr "" -#: includes/Migrator/Manager.php:232 +#: includes/Migrator/Manager.php:234 msgid "Invalid import type" msgstr "" diff --git a/package.json b/package.json index 8270eb6..f5be47a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dokan-migrator", - "version": "1.1.1", + "version": "1.1.2", "description": "An e-commerce marketplace migration plugin for WordPress.", "author": "WeDevs", "license": "GPL", diff --git a/readme.txt b/readme.txt index a08bcae..d5f53ec 100644 --- a/readme.txt +++ b/readme.txt @@ -5,8 +5,8 @@ Tags: dokan, dokan migrator, multivendor marketplace Requires at least: 5.8 Tested up to: 6.4.2 WC tested up to: 8.4.0 -Stable tag: 1.1.1 -Requires PHP: 7.3 +Stable tag: 1.1.2 +Requires PHP: 7.4 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html @@ -83,6 +83,12 @@ Extract the zip file and just drop the contents in the wp-content/plugins/ direc == Changelog == += v1.1.2 ( Sep 19, 2024 ) = + +- **update:** Revised contact information in the readme for reporting bugs and feature requests. +- **fix:** Safeguards implemented to ensure accurate financial calculations. +- **fix:** Fixed calculations for vendor commission rates and shipping amounts to prevent division by zero errors. + = v1.1.1 ( Dec 15, 2023 ) = - **fix:** Vendor folder was missing from the build process