From b34f0c2bea35b1d9abcd1b9eeca9a4b0403865c2 Mon Sep 17 00:00:00 2001 From: aunshon Date: Mon, 18 Apr 2022 12:48:01 +0600 Subject: [PATCH 01/25] YITH multivendor to dokan --- includes/Handlers/OrderMigrationHandler.php | 5 + includes/Handlers/VendorMigrationHandler.php | 16 + .../Handlers/WithdrawMigrationHandler.php | 27 +- includes/Helpers/MigrationHelper.php | 104 +++++- .../YithMultiVendor/OrderMigrator.php | 239 +++++++++++++ .../YithMultiVendor/VendorMigrator.php | 338 ++++++++++++++++++ .../YithMultiVendor/WithdrawMigrator.php | 170 +++++++++ 7 files changed, 894 insertions(+), 5 deletions(-) create mode 100644 includes/Integrations/YithMultiVendor/OrderMigrator.php create mode 100644 includes/Integrations/YithMultiVendor/VendorMigrator.php create mode 100644 includes/Integrations/YithMultiVendor/WithdrawMigrator.php diff --git a/includes/Handlers/OrderMigrationHandler.php b/includes/Handlers/OrderMigrationHandler.php index 18a2b7a..482a8ba 100644 --- a/includes/Handlers/OrderMigrationHandler.php +++ b/includes/Handlers/OrderMigrationHandler.php @@ -4,6 +4,7 @@ use Wedevs\DokanMigrator\Abstracts\Handler; use Wedevs\DokanMigrator\Integrations\Wcfm\OrderMigrator as WcfmOrderMigrator; +use Wedevs\DokanMigrator\Integrations\YithMultiVendor\OrderMigrator as YithMultiVendorOrderMigrator; class OrderMigrationHandler extends Handler { @@ -59,6 +60,10 @@ function get_migration_class($plugin){ return new WcfmOrderMigrator(); break; + case 'yithvendors': + return new YithMultiVendorOrderMigrator(); + break; + default: break; } diff --git a/includes/Handlers/VendorMigrationHandler.php b/includes/Handlers/VendorMigrationHandler.php index c22902d..7983651 100644 --- a/includes/Handlers/VendorMigrationHandler.php +++ b/includes/Handlers/VendorMigrationHandler.php @@ -6,6 +6,7 @@ use Wedevs\DokanMigrator\Abstracts\Handler; use Wedevs\DokanMigrator\Integrations\Wcfm\VendorMigrator as WcfmVendorMigrator; +use Wedevs\DokanMigrator\Integrations\YithMultiVendor\VendorMigrator as YithMultiVendorVendorMigrator; class VendorMigrationHandler extends Handler { @@ -26,6 +27,13 @@ public function get_total( $plugin ) { $total_count = count( get_users( array( 'role' => 'wcfm_vendor' ) ) ); break; + case 'yithvendors': + return count( get_terms( [ + 'taxonomy' => 'yith_shop_vendor', + 'hide_empty' => false, + ] ) ); + break; + default: break; } @@ -52,6 +60,10 @@ function get_items( $plugin, $number, $offset ) { $args['role'] = 'wcfm_vendor'; break; + case 'yithvendors': + $args['role'] = 'yith_vendor'; + break; + default: return []; break; @@ -75,6 +87,10 @@ function get_migration_class($plugin){ return new WcfmVendorMigrator(); break; + case 'yithvendors': + return new YithMultiVendorVendorMigrator(); + break; + default: break; } diff --git a/includes/Handlers/WithdrawMigrationHandler.php b/includes/Handlers/WithdrawMigrationHandler.php index 0bca68b..99e63f1 100644 --- a/includes/Handlers/WithdrawMigrationHandler.php +++ b/includes/Handlers/WithdrawMigrationHandler.php @@ -5,6 +5,7 @@ use Wedevs\DokanMigrator\Abstracts\Handler; use Wedevs\DokanMigrator\Integrations\Wcfm\WithdrawMigrator as WcfmWithdrawMigrator; +use Wedevs\DokanMigrator\Integrations\YithMultiVendor\WithdrawMigrator as YithMultiVendorWithdrawMigrator; class WithdrawMigrationHandler extends Handler { @@ -20,17 +21,24 @@ class WithdrawMigrationHandler extends Handler { public function get_total( $plugin ) { $total_count = 0; global $wpdb; + $sql = ''; switch ($plugin) { case 'wcfmmarketplace': - $sql = $wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->prefix}wcfm_marketplace_withdraw_request"); - $total_count = (int) $wpdb->get_var( $sql ); + $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}wcfm_marketplace_withdraw_request"; + break; + + case 'yithvendors': + $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product'"; break; default: break; } + $sql_prepared = $wpdb->prepare( $sql ); + $total_count = (int) $wpdb->get_var( $sql_prepared ); + return $total_count; } @@ -43,17 +51,24 @@ public function get_total( $plugin ) { */ function get_items( $plugin, $number, $offset ) { global $wpdb; + $sql = ''; switch ($plugin) { case 'wcfmmarketplace': - $sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wcfm_marketplace_withdraw_request ORDER BY ID LIMIT %d OFFSET %d", $number, $offset ); - return $wpdb->get_results( $sql ); + $sql = "SELECT * FROM {$wpdb->prefix}wcfm_marketplace_withdraw_request ORDER BY ID LIMIT %d OFFSET %d"; + break; + + case 'yithvendors': + $sql = "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product' ORDER BY id LIMIT %d OFFSET %d"; break; default: return []; break; } + + $prepared_sql = $wpdb->prepare( $sql, $number, $offset ); + return $wpdb->get_results( $prepared_sql ); } /** @@ -69,6 +84,10 @@ function get_migration_class($plugin){ return new WcfmWithdrawMigrator();; break; + case 'yithvendors': + return new YithMultiVendorWithdrawMigrator(); + break; + default: break; } diff --git a/includes/Helpers/MigrationHelper.php b/includes/Helpers/MigrationHelper.php index bf194da..7634aee 100644 --- a/includes/Helpers/MigrationHelper.php +++ b/includes/Helpers/MigrationHelper.php @@ -45,11 +45,104 @@ public static function active_vendor_dashboard() { $all_plugins_to_deactivate[] = WP_PLUGIN_DIR . '/wc-multivendor-marketplace/wc-multivendor-marketplace.php'; $all_plugins_to_deactivate[] = WP_PLUGIN_DIR . '/wc-multivendor-membership/wc-multivendor-membership.php'; + // Yith multi vendor plugins + $all_plugins_to_deactivate[] = WP_PLUGIN_DIR . '/yith-frontend-manager-for-woocommerce-premium/init.php'; + $all_plugins_to_deactivate[] = WP_PLUGIN_DIR . '/yith-woocommerce-multi-vendor-premium/init.php'; + deactivate_plugins( $all_plugins_to_deactivate ); + self::reset_dokan_pages(); + delete_option( 'dokan_migration_completed' ); - wp_send_json_success( __( 'Dokan vendor dashboard activated.', 'dokan-migrator' ) ); + wp_send_json_success( __( 'Dokan vendor dashboard activated.', 'dokan-migrator', ) ); + } + + /** + * Remove and create some pages that can override dokan pages. + * + * @since 1.0.0 + * + * @return void + */ + public static function reset_dokan_pages() { + $args = [ + 'name' => __( 'Page Installation', 'dokan-migrator' ), + 'desc' => __( 'Triggering fron dokan migrator', 'dokan-migrator' ), + 'button' => __( 'Install Dokan Pages', 'dokan-migrator' ), + 'action' => 'create_pages', + ]; + + $pages_to_delete = [ 'vendor_dashboard', 'vendors', 'shop_settings', 'dashboard', 'store-listing' ]; + + foreach ( $pages_to_delete as $page ) { + $page_obj = self::get_post_by_name( $page ); + + $page_obj !== null ? wp_delete_post( $page_obj->ID ) : ''; + } + + self::create_dokan_pages(); + } + + /** + * Create dokan pages. + * + * @since 1.0.0 + * + * @return void + */ + public static function create_dokan_pages() { + if ( ! current_user_can( 'manage_woocommerce' ) ) { + return; + } + $pages = array( + array( + 'post_title' => __( 'Dashboard', 'dokan-migrator' ), + 'slug' => 'dashboard', + 'page_id' => 'dashboard', + 'content' => '[dokan-dashboard]', + ), + array( + 'post_title' => __( 'Store List', 'dokan-migrator' ), + 'slug' => 'store-listing', + 'page_id' => 'store_listing', + 'content' => '[dokan-stores]', + ), + // array( + // 'post_title' => __( 'My Orders', 'dokan-migrator' ), + // 'slug' => 'my-orders', + // 'page_id' => 'my_orders', + // 'content' => '[dokan-my-orders]', + // ), + ); + + $dokan_pages = array(); + + $old_pages = get_option( 'dokan_pages', [] ); + + foreach ( $pages as $page ) { + if ( in_array( $page['page_id'], array_keys( $old_pages ), true ) ) { + $dokan_pages[ $page['page_id'] ] = $old_pages[ $page['page_id'] ]; + continue; + } + + $page_id = wp_insert_post( + array( + 'post_title' => $page['post_title'], + 'post_name' => $page['slug'], + 'post_content' => $page['content'], + 'post_status' => 'publish', + 'post_type' => 'page', + 'comment_status' => 'closed', + ) + ); + $dokan_pages[ $page['page_id'] ] = $page_id; + } + + update_option( 'dokan_pages', $dokan_pages ); + flush_rewrite_rules(); + + update_option( 'dokan_pages_created', 1 ); } /** @@ -88,6 +181,10 @@ public static function get_migration_title( $plugin ) { $title = __( 'Migrate Wcfm To Dokan.', 'dokan-migrator' ); break; + case 'yithvendors': + $title = __( 'Migrate YITH WooCommerce Multi Vendor To Dokan.', 'dokan-migrator' ); + break; + default: break; } @@ -111,6 +208,11 @@ public static function get_migratable_plugin() { // WCfM Multivendor Marketplace Check $is_marketplace = ( in_array( 'wc-multivendor-marketplace/wc-multivendor-marketplace.php', $active_plugins ) || array_key_exists( 'wc-multivendor-marketplace/wc-multivendor-marketplace.php', $active_plugins ) || class_exists( 'WCFMmp' ) ) ? 'wcfmmarketplace' : false; + // YITH multi vendor marketplace Check + if( !$is_marketplace ) { + $is_marketplace = ( in_array( 'yith-woocommerce-multi-vendor-premium/init.php', $active_plugins ) || array_key_exists( 'yith-woocommerce-multi-vendor-premium/init.php', $active_plugins ) || class_exists( 'YITH_Vendors' ) ) ? 'yithvendors' : false; + } + return $is_marketplace; } } diff --git a/includes/Integrations/YithMultiVendor/OrderMigrator.php b/includes/Integrations/YithMultiVendor/OrderMigrator.php new file mode 100644 index 0000000..ea69d09 --- /dev/null +++ b/includes/Integrations/YithMultiVendor/OrderMigrator.php @@ -0,0 +1,239 @@ + -1, + 'order' => 'DESC', + 'post_parent' => $parent_order_id, + 'post_type' => 'shop_order', + ); + + $sub_orders = get_children( $args, ARRAY_A ); + + $current_order = $parent_order_id; + + + foreach ( $sub_orders as $id => $sub_order ) { + if ( absint( $sub_order['post_author'] ) == $seller_id ) { + $current_order = $id; + } + } + + $child_order = wc_get_order($current_order); + $parent_order = wc_get_order($parent_order_id); + + $this->add_splited_shipping( $child_order, $parent_order ); + + return $child_order; + } + + /** + * Spliting shipping amount and saving. + * + * @since 1.0.0 + * + * @param \Wc_Order $child_order + * @param \Wc_Order $parent_order + * + * @return void + */ + public function add_splited_shipping( $order, $parent_order ){ + $parent_order->get_shipping_methods(); + + $shipping_methods = $parent_order->get_shipping_methods(); + $shipping_method = ''; + if ( $shipping_methods ) { + foreach ( $shipping_methods as $method_item_id => $shipping_object ) { + $shipping_method = $shipping_object; + break; + } + } + + // bail out if no shipping methods found + if ( ! $shipping_method ) { + return; + } + + if ( is_a( $shipping_method, 'WC_Order_Item_Shipping' ) ) { + $item = new \WC_Order_Item_Shipping(); + $vendors = dokan_get_sellers_by( $parent_order->get_id() ); + $vendors = count( $vendors ); + + $taxes = $shipping_method->get_taxes(); + $total = $shipping_method->get_total()/$vendors; + + foreach ( $taxes['total'] as $index => $tax ) { + $taxes['total'][$index] = $tax / $vendors; + } + + $item->set_props( + array( + 'method_title' => $shipping_method->get_name(), + 'method_id' => $shipping_method->get_method_id(), + 'total' => $total, + 'taxes' => $taxes, + ) + ); + + $metadata = $shipping_method->get_meta_data(); + + + + if ( $metadata ) { + foreach ( $metadata as $meta ) { + $item->add_meta_data( $meta->key, $meta->value ); + } + } + + $order->add_item( $item ); + $order->set_shipping_total( $total ); + $order->calculate_totals(); + + $order->save(); + } + } + + /** + * Delete sub orders of needed. + * + * @since 1.0.0 + * + * @return void + */ + public function reset_sub_orders_if_needed() { + return; + } + + /** + * Gets order data from wcfm order table for dokan. + * + * @since 1.0.0 + * + * @param int $parent_order_id + * @param int $seller_id + * + * @return array + */ + public function get_dokan_order_data( $parent_order_id, $seller_id ) { + global $wpdb; + $wc_order = wc_get_order($parent_order_id); + + $net_amount = 0; + $order_total = $wc_order->get_total(); + $commissions = []; + $admin_commission = 0; + + if ( $wc_order->get_total_refunded() ) { + $order_total = $order_total - $wc_order->get_total_refunded(); + } + + $args = array( + 'posts_per_page' => -1, + 'order' => 'DESC', + 'post_parent' => $parent_order_id, + 'post_type' => 'shop_order' + ); + + $sub_orders = get_children( $args,ARRAY_A ); + + foreach ( $sub_orders as $id => $sub_order ) { + $prepared_sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE user_id = '%d' AND order_id='%d'", $seller_id, $id ); + $orders = $wpdb->get_results( $prepared_sql ); + + foreach ( $orders as $order ) { + $net_amount += $order->amount - abs( $order->amount_refunded ); + + $res_commission = [ + 'type' => 'percent', + 'fixed' => '', + 'percentage' => '', + 'item_id' => '', + 'admin_commission' => 0, + 'product_id' => $order->line_item_id, + 'created' => $order->last_edit_gmt, + ]; + + $unit_commissin_rate_admin = 100 - ( $order->rate * 100 ); + $new_admin_commissin = ( $wc_order->get_subtotal() * $unit_commissin_rate_admin ) / 100; + + $res_commission['percentage'] = $unit_commissin_rate_admin; + $res_commission['admin_commission'] = $new_admin_commissin; + + array_push( $commissions, $res_commission ); + } + } + + + + if ( count( $sub_orders ) == 1 ) { + // update post type + $sub_order = reset( $sub_orders ); + set_post_type( $sub_order['ID'], 'dep_yith_order' ); + } + + foreach ( $commissions as $com ) { + $admin_commission += $com['admin_commission']; + } + + $dokan_order_data = [ + 'commission_data' => $commissions, + 'order_total' => $order_total, + 'net_sale' => $net_amount, + 'admin_commission_amount' => $admin_commission, + ]; + + return $dokan_order_data; + } + + /** + * Process refund for a child order. + * + * @since 1.0.0 + * + * @param \Wc_Order $child_order + * @param integer $seller_id + * @param boolean $from_suborder + * + * @return void + */ + public function process_refund( $child_order, $seller_id, $from_suborder = true ) { + global $wpdb; + $order = wc_get_order( $child_order->get_id() ); + $new_total_amount = $order->get_total() - $order->get_total_refunded(); + + // insert on dokan sync table + + $res = $wpdb->update( $wpdb->prefix . 'dokan_orders', + array( + 'order_total' => $new_total_amount, + ), + array( + 'order_id' => $child_order->get_id() + ), + array( + '%f', + ) + ); + } +} \ No newline at end of file diff --git a/includes/Integrations/YithMultiVendor/VendorMigrator.php b/includes/Integrations/YithMultiVendor/VendorMigrator.php new file mode 100644 index 0000000..c4f882b --- /dev/null +++ b/includes/Integrations/YithMultiVendor/VendorMigrator.php @@ -0,0 +1,338 @@ +get_val( 'yith_product_vendor_owner' ), $key, true ); + } + + /** + * Returns store name + * + * @since 1.0.0 + * + * @return string + */ + public function get_store_name() { + $store_name = $this->get_val( 'nickname' ); + empty( $store_name ) ? $store_name = $this->vendor->user_nicename : ''; + return $store_name; + } + + /** + * Returns store description + * + * @since 1.0.0 + * + * @return string + */ + public function get_store_biography() { + return term_description( $this->get_val( 'yith_product_vendor_owner' ) ); + } + + /** + * Returns is vendor has selling capability. + * + * @since 1.0.0 + * + * @return string + */ + public function get_enable_selling() { + return $this->get_vendor_data_from_terms_table('enable_selling'); + } + + /** + * Returns geo location address + * + * @since 1.0.0 + * + * @return string + */ + public function get_geo_address() { + return $this->get_vendor_data_from_terms_table('location'); + } + + /** + * Returns vendor location latitude. + * + * @since 1.0.0 + * + * @return string + */ + public function get_geo_lat() { + return ''; + } + + /** + * Returns vendor location longitude. + * + * @since 1.0.0 + * + * @return string + */ + public function get_geo_long() { + return ''; + } + + /** + * Returns vendor social data. + * + * @since 1.0.0 + * + * @return array + */ + public function get_social($default) { + return $this->get_vendor_data_from_terms_table('socials'); + } + + /** + * Returns vendor payment data. + * + * @since 1.0.0 + * + * @return array + */ + public function get_payment($default) { + return [ + 'paypal' => [ + 'email' => $this->get_vendor_data_from_terms_table('paypal_email') + ], + 'bank' => [ + 'ac_name' => '', + 'ac_number' => '', + 'bank_name' => '', + 'bank_addr' => '', + 'routing_number' => '', + 'iban' => $this->get_vendor_data_from_terms_table('bank_account'), + 'swift' => '', + ], + ]; + } + + /** + * Returns vendor phone number. + * + * @since 1.0.0 + * + * @param string $default + * + * @return string + */ + public function get_phone($default) { + return $this->get_vendor_data_from_terms_table('telephone'); + } + + /** + * Returns if email show in store or not. + * + * @since 1.0.0 + * + * @param string $default + * + * @return string + */ + public function get_is_show_email($default) { + return 'no'; + } + + /** + * Returns vendor address. + * + * @since 1.0.0 + * + * @param string $default + * + * @return array + */ + public function get_address($default) { + $address = [ + 'street1' => $this->get_vendor_data_from_terms_table('location'), + 'street2' => '', + 'city' => '', + 'zip' => '', + 'country' => '', + 'state' => '', + ]; + + return $address; + } + + /** + * Returns vendor location. + * + * @since 1.0.0 + * + * @param string $default + * + * @return string + */ + public function get_location($default) { + return []; + } + + /** + * Returns banner id. + * + * @since 1.0.0 + * + * @param int $default + * + * @return int + */ + public function get_banner($default) { + return $this->get_vendor_data_from_terms_table('header_image'); + } + + + /** + * Returns applied commission in an vendor. + * + * @since 1.0.0 + * + * @param string $default + * + * @return int + */ + public function get_icon($default) { + return ''; + } + + /** + * Returns vendor gravatar. + * + * @since 1.0.0 + * + * @param string $default + * + * @return int + */ + public function get_gravatar($default) { + return $this->get_vendor_data_from_terms_table('avatar'); + } + + /** + * Returns if show more p tab. + * + * @since 1.0.0 + * + * @param mixed $default + * + * @return string + */ + public function get_show_more_ptab($default) { + return 'yes'; + } + + /** + * Returns store product per page. + * + * @since 1.0.0 + * + * @param int $default + * + * @return int + */ + public function get_sore_ppp($default) { + return 10; + } + + /** + * Returns applied commission in an vendor. + * + * @since 1.0.0 + * + * @param string $default + * + * @return string + */ + public function get_is_enabled_tnc($default) { + return 'off'; + } + + /** + * Returns terms and comdition. + * + * @since 1.0.0 + * + * @param string $default + * + * @return string + */ + public function get_store_tnc($default) { + return wp_strip_all_tags( $this->get_vendor_data_from_terms_table('avatar') ); + } + + /** + * Returns if min discount. + * + * @since 1.0.0 + * + * @param string $default + * + * @return string + */ + public function get_show_min_order_discount($default) { + return 'no'; + } + + /** + * Returns store seo. + * + * @since 1.0.0 + * + * @param array $default + * + * @return array + */ + public function get_store_seo($default) { + $dokan_store_soe = [ + 'dokan-seo-meta-title' => '', + 'dokan-seo-meta-desc' => '', + 'dokan-seo-meta-keywords' => '', + 'dokan-seo-og-title' => '', + 'dokan-seo-og-desc' => '', + 'dokan-seo-og-image' => '', + 'dokan-seo-twitter-title' => '', + 'dokan-seo-twitter-desc' => '', + 'dokan-seo-twitter-image' => '', + 'dokan-seo-fb-image' => '', + 'dokan-seo-fb-image' => '', + 'dokan-seo-fb-image' => '', + ]; + + return $dokan_store_soe; + } + + /** + * Returns commission for specific vendor. + * + * @return void + */ + public function get_commission() { + $dokan_commission = [ + 'dokan_admin_percentage' => $this->get_vendor_data_from_terms_table('commission'), + 'dokan_admin_percentage_type' => 'percentage', + 'dokan_admin_additional_fee' => $this->get_vendor_data_from_terms_table('commission'), + ]; + + return $dokan_commission; + } +} \ No newline at end of file diff --git a/includes/Integrations/YithMultiVendor/WithdrawMigrator.php b/includes/Integrations/YithMultiVendor/WithdrawMigrator.php new file mode 100644 index 0000000..f95645f --- /dev/null +++ b/includes/Integrations/YithMultiVendor/WithdrawMigrator.php @@ -0,0 +1,170 @@ +withdraw = $withdraw_data; + $this->withdraw_id = $withdraw_data->ID; + + $this->meta_data = $this->get_withdraw_meta_data(); + } + + /** + * Returns vendor id. + * + * @since 1.0.0 + * + * @return int + */ + public function get_vendor_id() { + return ! empty( $this->withdraw->user_id ) ? $this->withdraw->user_id : ''; + } + + /** + * Returns withdraw amount. + * + * @since 1.0.0 + * + * @return int|float + */ + public function get_withdraw_amount() { + return $this->withdraw->amount - abs( $this->withdraw->amount_refunded ); + } + + /** + * Returns withdraw created date. + * + * @since 1.0.0 + * + * @return string + */ + public function get_withdraw_created_date() { + return ! empty( $this->withdraw->last_edit_gmt ) ? $this->withdraw->last_edit_gmt : ''; + } + + /** + * Returns withdraw status. + * + * @since 1.0.0 + * + * @return string + */ + public function get_withdraw_status() { + return 1; + } + + /** + * Returns withdraw payment method. + * + * @since 1.0.0 + * + * @return string + */ + public function get_withdraw_payment_method() { + return ''; + } + + /** + * Returns withdraw note + * + * @since 1.0.0 + * + * @return string + */ + public function get_withdraw_note() { + return 'Made by dokan migrator.'; + } + + /** + * Returns withdraw details. + * + * @since 1.0.0 + * + * @return string + */ + public function get_withdraw_details() { + $order_ids = ! empty( $this->withdraw->order_ids ) ? $this->withdraw->order_ids : ''; + $commission_ids = ! empty( $this->withdraw->commission_ids ) ? $this->withdraw->commission_ids : ''; + $withdraw_charges = ! empty( $this->withdraw->withdraw_charges ) ? $this->withdraw->withdraw_charges : ''; + $withdraw_mode = ! empty( $this->withdraw->withdraw_mode ) ? $this->withdraw->withdraw_mode : ''; + $is_auto_withdrawal = ! empty( $this->withdraw->is_auto_withdrawal ) ? $this->withdraw->is_auto_withdrawal: ''; + $withdraw_paid_date = ! empty( $this->withdraw->time ) ? $this->withdraw->time : ''; + + $vendor_id = ! empty( $this->withdraw->user_id ) ? $this->withdraw->user_id : ''; + $product_id = ! empty( $this->withdraw->line_item_id ) ? $this->withdraw->line_item_id: ''; + $qty = ! empty( $this->withdraw->qty ) ? $this->withdraw->qty : ''; + $rate = ! empty( $this->withdraw->rate ) ? ( $this->withdraw->rate * 100 ) : ''; + + $dokan_details = $this->meta_data; + $dokan_details['email'] = get_userdata( $this->get_vendor_id() )->user_email; + $dokan_details['order_ids'] = $order_ids; + $dokan_details['commission_ids'] = $commission_ids; + $dokan_details['withdraw_charges'] = $withdraw_charges; + $dokan_details['withdraw_mode'] = $withdraw_mode; + $dokan_details['is_auto_withdrawal'] = $is_auto_withdrawal; + $dokan_details['withdraw_paid_date'] = $withdraw_paid_date; + $dokan_details['vendor_id'] = $vendor_id; + $dokan_details['product_id'] = $product_id; + $dokan_details['qty'] = $qty; + $dokan_details['rate'] = $rate; + + return maybe_serialize( $dokan_details ); + } + + /** + * Returns withdraw ip. + * + * @since 1.0.0 + * + * @return string + */ + public function get_withdraw_ip() { + return ''; + } + + /** + * Gets the withdraw meta data. + * + * @since 1.0.0 + * + * @return array + */ + public function get_withdraw_meta_data() { + return []; + } +} \ No newline at end of file From 5486f8aef6cbc3460d9b8302810adc46e96d61db Mon Sep 17 00:00:00 2001 From: Aunshon Date: Tue, 24 May 2022 11:28:15 +0600 Subject: [PATCH 02/25] php cs fix --- includes/Handlers/VendorMigrationHandler.php | 1 - .../YithMultiVendor/OrderMigrator.php | 45 ++++++-------- .../YithMultiVendor/VendorMigrator.php | 62 +++++++++---------- .../YithMultiVendor/WithdrawMigrator.php | 20 +++--- 4 files changed, 60 insertions(+), 68 deletions(-) diff --git a/includes/Handlers/VendorMigrationHandler.php b/includes/Handlers/VendorMigrationHandler.php index a024138..881ad85 100644 --- a/includes/Handlers/VendorMigrationHandler.php +++ b/includes/Handlers/VendorMigrationHandler.php @@ -82,7 +82,6 @@ public function get_migration_class( $plugin ) { case 'yithvendors': return new YithMultiVendorVendorMigrator(); - break; default: break; diff --git a/includes/Integrations/YithMultiVendor/OrderMigrator.php b/includes/Integrations/YithMultiVendor/OrderMigrator.php index ea69d09..5df2372 100644 --- a/includes/Integrations/YithMultiVendor/OrderMigrator.php +++ b/includes/Integrations/YithMultiVendor/OrderMigrator.php @@ -27,21 +27,20 @@ public function create_sub_order_if_needed( $seller_id, $seller_products, $paren 'order' => 'DESC', 'post_parent' => $parent_order_id, 'post_type' => 'shop_order', - ); + ); $sub_orders = get_children( $args, ARRAY_A ); $current_order = $parent_order_id; - foreach ( $sub_orders as $id => $sub_order ) { - if ( absint( $sub_order['post_author'] ) == $seller_id ) { - $current_order = $id; + if ( absint( $sub_order['post_author'] ) === $seller_id ) { + $current_order = $id; } } - $child_order = wc_get_order($current_order); - $parent_order = wc_get_order($parent_order_id); + $child_order = wc_get_order( $current_order ); + $parent_order = wc_get_order( $parent_order_id ); $this->add_splited_shipping( $child_order, $parent_order ); @@ -58,11 +57,11 @@ public function create_sub_order_if_needed( $seller_id, $seller_products, $paren * * @return void */ - public function add_splited_shipping( $order, $parent_order ){ + public function add_splited_shipping( $order, $parent_order ) { $parent_order->get_shipping_methods(); $shipping_methods = $parent_order->get_shipping_methods(); - $shipping_method = ''; + $shipping_method = ''; if ( $shipping_methods ) { foreach ( $shipping_methods as $method_item_id => $shipping_object ) { $shipping_method = $shipping_object; @@ -81,10 +80,10 @@ public function add_splited_shipping( $order, $parent_order ){ $vendors = count( $vendors ); $taxes = $shipping_method->get_taxes(); - $total = $shipping_method->get_total()/$vendors; + $total = $shipping_method->get_total() / $vendors; foreach ( $taxes['total'] as $index => $tax ) { - $taxes['total'][$index] = $tax / $vendors; + $taxes['total'][ $index ] = $tax / $vendors; } $item->set_props( @@ -98,8 +97,6 @@ public function add_splited_shipping( $order, $parent_order ){ $metadata = $shipping_method->get_meta_data(); - - if ( $metadata ) { foreach ( $metadata as $meta ) { $item->add_meta_data( $meta->key, $meta->value ); @@ -122,7 +119,7 @@ public function add_splited_shipping( $order, $parent_order ){ * @return void */ public function reset_sub_orders_if_needed() { - return; + return ''; } /** @@ -137,7 +134,7 @@ public function reset_sub_orders_if_needed() { */ public function get_dokan_order_data( $parent_order_id, $seller_id ) { global $wpdb; - $wc_order = wc_get_order($parent_order_id); + $wc_order = wc_get_order( $parent_order_id ); $net_amount = 0; $order_total = $wc_order->get_total(); @@ -152,14 +149,13 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) { 'posts_per_page' => -1, 'order' => 'DESC', 'post_parent' => $parent_order_id, - 'post_type' => 'shop_order' - ); + 'post_type' => 'shop_order', + ); - $sub_orders = get_children( $args,ARRAY_A ); + $sub_orders = get_children( $args, ARRAY_A ); foreach ( $sub_orders as $id => $sub_order ) { - $prepared_sql = $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE user_id = '%d' AND order_id='%d'", $seller_id, $id ); - $orders = $wpdb->get_results( $prepared_sql ); + $orders = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE user_id = %d AND order_id=%d", $seller_id, $id ) ); foreach ( $orders as $order ) { $net_amount += $order->amount - abs( $order->amount_refunded ); @@ -184,9 +180,7 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) { } } - - - if ( count( $sub_orders ) == 1 ) { + if ( count( $sub_orders ) === 1 ) { // update post type $sub_order = reset( $sub_orders ); set_post_type( $sub_order['ID'], 'dep_yith_order' ); @@ -224,16 +218,17 @@ public function process_refund( $child_order, $seller_id, $from_suborder = true // insert on dokan sync table - $res = $wpdb->update( $wpdb->prefix . 'dokan_orders', + $res = $wpdb->update( + $wpdb->prefix . 'dokan_orders', array( 'order_total' => $new_total_amount, ), array( - 'order_id' => $child_order->get_id() + 'order_id' => $child_order->get_id(), ), array( '%f', ) ); } -} \ No newline at end of file +} diff --git a/includes/Integrations/YithMultiVendor/VendorMigrator.php b/includes/Integrations/YithMultiVendor/VendorMigrator.php index c4f882b..3ca6593 100644 --- a/includes/Integrations/YithMultiVendor/VendorMigrator.php +++ b/includes/Integrations/YithMultiVendor/VendorMigrator.php @@ -56,7 +56,7 @@ public function get_store_biography() { * @return string */ public function get_enable_selling() { - return $this->get_vendor_data_from_terms_table('enable_selling'); + return $this->get_vendor_data_from_terms_table( 'enable_selling' ); } /** @@ -67,7 +67,7 @@ public function get_enable_selling() { * @return string */ public function get_geo_address() { - return $this->get_vendor_data_from_terms_table('location'); + return $this->get_vendor_data_from_terms_table( 'location' ); } /** @@ -99,8 +99,8 @@ public function get_geo_long() { * * @return array */ - public function get_social($default) { - return $this->get_vendor_data_from_terms_table('socials'); + public function get_social( $default ) { + return $this->get_vendor_data_from_terms_table( 'socials' ); } /** @@ -110,10 +110,10 @@ public function get_social($default) { * * @return array */ - public function get_payment($default) { + public function get_payment( $default ) { return [ 'paypal' => [ - 'email' => $this->get_vendor_data_from_terms_table('paypal_email') + 'email' => $this->get_vendor_data_from_terms_table( 'paypal_email' ), ], 'bank' => [ 'ac_name' => '', @@ -121,7 +121,7 @@ public function get_payment($default) { 'bank_name' => '', 'bank_addr' => '', 'routing_number' => '', - 'iban' => $this->get_vendor_data_from_terms_table('bank_account'), + 'iban' => $this->get_vendor_data_from_terms_table( 'bank_account' ), 'swift' => '', ], ]; @@ -136,8 +136,8 @@ public function get_payment($default) { * * @return string */ - public function get_phone($default) { - return $this->get_vendor_data_from_terms_table('telephone'); + public function get_phone( $default ) { + return $this->get_vendor_data_from_terms_table( 'telephone' ); } /** @@ -149,7 +149,7 @@ public function get_phone($default) { * * @return string */ - public function get_is_show_email($default) { + public function get_is_show_email( $default ) { return 'no'; } @@ -162,9 +162,9 @@ public function get_is_show_email($default) { * * @return array */ - public function get_address($default) { + public function get_address( $default ) { $address = [ - 'street1' => $this->get_vendor_data_from_terms_table('location'), + 'street1' => $this->get_vendor_data_from_terms_table( 'location' ), 'street2' => '', 'city' => '', 'zip' => '', @@ -184,7 +184,7 @@ public function get_address($default) { * * @return string */ - public function get_location($default) { + public function get_location( $default ) { return []; } @@ -197,8 +197,8 @@ public function get_location($default) { * * @return int */ - public function get_banner($default) { - return $this->get_vendor_data_from_terms_table('header_image'); + public function get_banner( $default ) { + return $this->get_vendor_data_from_terms_table( 'header_image' ); } @@ -211,7 +211,7 @@ public function get_banner($default) { * * @return int */ - public function get_icon($default) { + public function get_icon( $default ) { return ''; } @@ -224,8 +224,8 @@ public function get_icon($default) { * * @return int */ - public function get_gravatar($default) { - return $this->get_vendor_data_from_terms_table('avatar'); + public function get_gravatar( $default ) { + return $this->get_vendor_data_from_terms_table( 'avatar' ); } /** @@ -237,7 +237,7 @@ public function get_gravatar($default) { * * @return string */ - public function get_show_more_ptab($default) { + public function get_show_more_ptab( $default ) { return 'yes'; } @@ -250,7 +250,7 @@ public function get_show_more_ptab($default) { * * @return int */ - public function get_sore_ppp($default) { + public function get_sore_ppp( $default ) { return 10; } @@ -263,7 +263,7 @@ public function get_sore_ppp($default) { * * @return string */ - public function get_is_enabled_tnc($default) { + public function get_is_enabled_tnc( $default ) { return 'off'; } @@ -276,8 +276,8 @@ public function get_is_enabled_tnc($default) { * * @return string */ - public function get_store_tnc($default) { - return wp_strip_all_tags( $this->get_vendor_data_from_terms_table('avatar') ); + public function get_store_tnc( $default ) { + return wp_strip_all_tags( $this->get_vendor_data_from_terms_table( 'avatar' ) ); } /** @@ -289,7 +289,7 @@ public function get_store_tnc($default) { * * @return string */ - public function get_show_min_order_discount($default) { + public function get_show_min_order_discount( $default ) { return 'no'; } @@ -302,7 +302,7 @@ public function get_show_min_order_discount($default) { * * @return array */ - public function get_store_seo($default) { + public function get_store_seo( $default ) { $dokan_store_soe = [ 'dokan-seo-meta-title' => '', 'dokan-seo-meta-desc' => '', @@ -327,12 +327,10 @@ public function get_store_seo($default) { * @return void */ public function get_commission() { - $dokan_commission = [ - 'dokan_admin_percentage' => $this->get_vendor_data_from_terms_table('commission'), + return array( + 'dokan_admin_percentage' => $this->get_vendor_data_from_terms_table( 'commission' ), 'dokan_admin_percentage_type' => 'percentage', - 'dokan_admin_additional_fee' => $this->get_vendor_data_from_terms_table('commission'), - ]; - - return $dokan_commission; + 'dokan_admin_additional_fee' => $this->get_vendor_data_from_terms_table( 'commission' ), + ); } -} \ No newline at end of file +} diff --git a/includes/Integrations/YithMultiVendor/WithdrawMigrator.php b/includes/Integrations/YithMultiVendor/WithdrawMigrator.php index f95645f..82ddbd9 100644 --- a/includes/Integrations/YithMultiVendor/WithdrawMigrator.php +++ b/includes/Integrations/YithMultiVendor/WithdrawMigrator.php @@ -118,17 +118,17 @@ public function get_withdraw_note() { * @return string */ public function get_withdraw_details() { - $order_ids = ! empty( $this->withdraw->order_ids ) ? $this->withdraw->order_ids : ''; - $commission_ids = ! empty( $this->withdraw->commission_ids ) ? $this->withdraw->commission_ids : ''; - $withdraw_charges = ! empty( $this->withdraw->withdraw_charges ) ? $this->withdraw->withdraw_charges : ''; - $withdraw_mode = ! empty( $this->withdraw->withdraw_mode ) ? $this->withdraw->withdraw_mode : ''; - $is_auto_withdrawal = ! empty( $this->withdraw->is_auto_withdrawal ) ? $this->withdraw->is_auto_withdrawal: ''; + $order_ids = ! empty( $this->withdraw->order_ids ) ? $this->withdraw->order_ids : ''; + $commission_ids = ! empty( $this->withdraw->commission_ids ) ? $this->withdraw->commission_ids : ''; + $withdraw_charges = ! empty( $this->withdraw->withdraw_charges ) ? $this->withdraw->withdraw_charges : ''; + $withdraw_mode = ! empty( $this->withdraw->withdraw_mode ) ? $this->withdraw->withdraw_mode : ''; + $is_auto_withdrawal = ! empty( $this->withdraw->is_auto_withdrawal ) ? $this->withdraw->is_auto_withdrawal : ''; $withdraw_paid_date = ! empty( $this->withdraw->time ) ? $this->withdraw->time : ''; - $vendor_id = ! empty( $this->withdraw->user_id ) ? $this->withdraw->user_id : ''; - $product_id = ! empty( $this->withdraw->line_item_id ) ? $this->withdraw->line_item_id: ''; - $qty = ! empty( $this->withdraw->qty ) ? $this->withdraw->qty : ''; - $rate = ! empty( $this->withdraw->rate ) ? ( $this->withdraw->rate * 100 ) : ''; + $vendor_id = ! empty( $this->withdraw->user_id ) ? $this->withdraw->user_id : ''; + $product_id = ! empty( $this->withdraw->line_item_id ) ? $this->withdraw->line_item_id : ''; + $qty = ! empty( $this->withdraw->qty ) ? $this->withdraw->qty : ''; + $rate = ! empty( $this->withdraw->rate ) ? ( $this->withdraw->rate * 100 ) : ''; $dokan_details = $this->meta_data; $dokan_details['email'] = get_userdata( $this->get_vendor_id() )->user_email; @@ -167,4 +167,4 @@ public function get_withdraw_ip() { public function get_withdraw_meta_data() { return []; } -} \ No newline at end of file +} From dfa2325e6ac568d03c46aedc8ddf6e0505040db3 Mon Sep 17 00:00:00 2001 From: Aunshon Date: Tue, 24 May 2022 11:35:24 +0600 Subject: [PATCH 03/25] phpcs fix --- includes/Handlers/OrderMigrationHandler.php | 1 - includes/Handlers/VendorMigrationHandler.php | 13 ++++++++----- includes/Helpers/MigrationHelper.php | 13 ++++--------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/includes/Handlers/OrderMigrationHandler.php b/includes/Handlers/OrderMigrationHandler.php index 927425e..13a891a 100644 --- a/includes/Handlers/OrderMigrationHandler.php +++ b/includes/Handlers/OrderMigrationHandler.php @@ -57,7 +57,6 @@ public function get_migration_class( $plugin ) { case 'yithvendors': return new YithMultiVendorOrderMigrator(); - break; default: break; diff --git a/includes/Handlers/VendorMigrationHandler.php b/includes/Handlers/VendorMigrationHandler.php index 881ad85..3908fe0 100644 --- a/includes/Handlers/VendorMigrationHandler.php +++ b/includes/Handlers/VendorMigrationHandler.php @@ -25,11 +25,14 @@ public function get_total( $plugin ) { return count( get_users( array( 'role' => 'wcfm_vendor' ) ) ); case 'yithvendors': - return count( get_terms( [ - 'taxonomy' => 'yith_shop_vendor', - 'hide_empty' => false, - ] ) ); - break; + return count( + get_terms( + array( + 'taxonomy' => 'yith_shop_vendor', + 'hide_empty' => false, + ) + ) + ); default: return 0; diff --git a/includes/Helpers/MigrationHelper.php b/includes/Helpers/MigrationHelper.php index b001574..a7db28c 100644 --- a/includes/Helpers/MigrationHelper.php +++ b/includes/Helpers/MigrationHelper.php @@ -57,7 +57,7 @@ public static function active_vendor_dashboard() { delete_option( 'dokan_migration_completed' ); - wp_send_json_success( __( 'Dokan vendor dashboard activated.', 'dokan-migrator', ) ); + wp_send_json_success( __( 'Dokan vendor dashboard activated.', 'dokan-migrator' ) ); } /** @@ -110,12 +110,6 @@ public static function create_dokan_pages() { 'page_id' => 'store_listing', 'content' => '[dokan-stores]', ), - // array( - // 'post_title' => __( 'My Orders', 'dokan-migrator' ), - // 'slug' => 'my-orders', - // 'page_id' => 'my_orders', - // 'content' => '[dokan-my-orders]', - // ), ); $dokan_pages = array(); @@ -205,6 +199,7 @@ public static function get_migration_title( $plugin ) { */ public static function get_migratable_plugin() { $active_plugins = (array) get_option( 'active_plugins', array() ); + if ( is_multisite() ) { $active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) ); } @@ -213,8 +208,8 @@ public static function get_migratable_plugin() { $is_marketplace = ( in_array( 'wc-multivendor-marketplace/wc-multivendor-marketplace.php', $active_plugins, true ) || array_key_exists( 'wc-multivendor-marketplace/wc-multivendor-marketplace.php', $active_plugins ) || class_exists( 'WCFMmp' ) ) ? 'wcfmmarketplace' : false; // YITH multi vendor marketplace Check - if( !$is_marketplace ) { - $is_marketplace = ( in_array( 'yith-woocommerce-multi-vendor-premium/init.php', $active_plugins ) || array_key_exists( 'yith-woocommerce-multi-vendor-premium/init.php', $active_plugins ) || class_exists( 'YITH_Vendors' ) ) ? 'yithvendors' : false; + if ( ! $is_marketplace ) { + $is_marketplace = ( in_array( 'yith-woocommerce-multi-vendor-premium/init.php', $active_plugins, true ) || array_key_exists( 'yith-woocommerce-multi-vendor-premium/init.php', $active_plugins ) || class_exists( 'YITH_Vendors' ) ) ? 'yithvendors' : false; } return $is_marketplace; From bde3e08b86e9a8e6e2de7825fb7338ed35f8ba17 Mon Sep 17 00:00:00 2001 From: Aunshon Date: Tue, 24 May 2022 16:22:18 +0600 Subject: [PATCH 04/25] allignment fix --- includes/Integrations/YithMultiVendor/OrderMigrator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/Integrations/YithMultiVendor/OrderMigrator.php b/includes/Integrations/YithMultiVendor/OrderMigrator.php index 5df2372..8d1b5bf 100644 --- a/includes/Integrations/YithMultiVendor/OrderMigrator.php +++ b/includes/Integrations/YithMultiVendor/OrderMigrator.php @@ -88,10 +88,10 @@ public function add_splited_shipping( $order, $parent_order ) { $item->set_props( array( - 'method_title' => $shipping_method->get_name(), - 'method_id' => $shipping_method->get_method_id(), - 'total' => $total, - 'taxes' => $taxes, +'method_title' => $shipping_method->get_name(), +'method_id' => $shipping_method->get_method_id(), +'total' => $total, +'taxes' => $taxes, ) ); From 5a3afad3192d9a0bf8f98a1a9e1c0e4e6a8c4e9d Mon Sep 17 00:00:00 2001 From: Aunshon Date: Tue, 24 May 2022 16:22:38 +0600 Subject: [PATCH 05/25] Allignment fix --- includes/Integrations/YithMultiVendor/OrderMigrator.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/Integrations/YithMultiVendor/OrderMigrator.php b/includes/Integrations/YithMultiVendor/OrderMigrator.php index 8d1b5bf..cdce245 100644 --- a/includes/Integrations/YithMultiVendor/OrderMigrator.php +++ b/includes/Integrations/YithMultiVendor/OrderMigrator.php @@ -88,10 +88,10 @@ public function add_splited_shipping( $order, $parent_order ) { $item->set_props( array( -'method_title' => $shipping_method->get_name(), -'method_id' => $shipping_method->get_method_id(), -'total' => $total, -'taxes' => $taxes, + 'method_title' => $shipping_method->get_name(), + 'method_id' => $shipping_method->get_method_id(), + 'total' => $total, + 'taxes' => $taxes, ) ); From 781f5d40dca0420521f9efcb6650f4454fae76b1 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 17 Jul 2023 15:12:44 +0600 Subject: [PATCH 06/25] Fix: wcvendors withdraw plugin select switch case --- includes/Integrations/Wcfm/OrderMigrator.php | 2 +- includes/Processors/Order.php | 34 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/includes/Integrations/Wcfm/OrderMigrator.php b/includes/Integrations/Wcfm/OrderMigrator.php index faab6b0..4e25fcd 100644 --- a/includes/Integrations/Wcfm/OrderMigrator.php +++ b/includes/Integrations/Wcfm/OrderMigrator.php @@ -24,7 +24,7 @@ class OrderMigrator extends OrderMigration { * * @since DOKAN_PRO_SINCE * - * @param \WP_Post $order + * @param \WP_Post|\stdClass $order */ public function __construct( \WP_Post $order ) { $this->order_id = $order->ID; diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 8e98f5d..dca1768 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -29,7 +29,18 @@ class Order extends Processor { public static function get_total( $plugin ) { global $wpdb; - return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}posts WHERE post_type='shop_order' AND post_parent=0" ); + switch ( $plugin ) { + case 'wcfmmarketplace': + return (int) $wpdb->get_var( + "SELECT COUNT(DISTINCT p.ID) + FROM wp_posts p + INNER JOIN {$wpdb->prefix}wcfm_marketplace_orders ON p.ID = {$wpdb->prefix}wcfm_marketplace_orders.order_id + " + ); + + default: + return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}posts WHERE post_type='shop_order' AND post_parent=0" ); + } } /** @@ -41,16 +52,33 @@ public static function get_total( $plugin ) { * @throws \Exception */ public static function get_items( $plugin, $number, $offset ) { + global $wpdb; $args = array( 'post_type' => 'shop_order', - 'orderby' => 'ASC', + 'orderby' => 'ID', + 'order' => 'DESC', 'post_status' => 'any', 'offset' => $offset, 'posts_per_page' => $number, 'post_parent' => 0, ); - $orders = get_posts( $args ); + switch ( $plugin ) { + case 'wcfmmarketplace': + $orders = $wpdb->get_results( + "SELECT p.* + FROM wp_posts p + INNER JOIN {$wpdb->prefix}wcfm_marketplace_orders ON p.ID = {$wpdb->prefix}wcfm_marketplace_orders.order_id + ORDER BY p.ID DESC + LIMIT 3 + OFFSET 0 + " + ); + break; + + default: + $orders = get_posts( $args ); + } if ( empty( $orders ) ) { self::throw_error(); From a8ba56de2cf779e72d54ccbed6a00b4184c430b5 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 17 Jul 2023 17:00:47 +0600 Subject: [PATCH 07/25] Fix: wcvendors withdraw plugin select switch case --- includes/Integrations/Wcfm/OrderMigrator.php | 2 +- includes/Migrator/Manager.php | 4 ++-- includes/Processors/Order.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/Integrations/Wcfm/OrderMigrator.php b/includes/Integrations/Wcfm/OrderMigrator.php index 4e25fcd..120ca8c 100644 --- a/includes/Integrations/Wcfm/OrderMigrator.php +++ b/includes/Integrations/Wcfm/OrderMigrator.php @@ -26,7 +26,7 @@ class OrderMigrator extends OrderMigration { * * @param \WP_Post|\stdClass $order */ - public function __construct( \WP_Post $order ) { + public function __construct( $order ) { $this->order_id = $order->ID; $this->order = wc_get_order( $this->order_id ); diff --git a/includes/Migrator/Manager.php b/includes/Migrator/Manager.php index 3a67d07..3f32d9e 100644 --- a/includes/Migrator/Manager.php +++ b/includes/Migrator/Manager.php @@ -183,8 +183,8 @@ public function migrate( $import_type, $plugin, $data ) { $args = [ 'migrated' => count( $data ), - 'next' => count( $data ) + $this->offset, - 'total_migrated' => count( $data ) + $this->total_migrated, + 'next' => count( $data ) + (int) $this->offset, + 'total_migrated' => count( $data ) + (int) $this->total_migrated, ]; $progress = ( $args['total_migrated'] * 100 ) / $this->total_count; diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index dca1768..ce869df 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -70,8 +70,8 @@ public static function get_items( $plugin, $number, $offset ) { FROM wp_posts p INNER JOIN {$wpdb->prefix}wcfm_marketplace_orders ON p.ID = {$wpdb->prefix}wcfm_marketplace_orders.order_id ORDER BY p.ID DESC - LIMIT 3 - OFFSET 0 + LIMIT {$number} + OFFSET {$offset} " ); break; From 65412c0f38463d1d24a8173ae518622232b35423 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 17 Jul 2023 17:04:01 +0600 Subject: [PATCH 08/25] Fix: wcvendors withdraw plugin select switch case --- includes/Processors/Order.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index ce869df..2bdffff 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -65,6 +65,7 @@ public static function get_items( $plugin, $number, $offset ) { switch ( $plugin ) { case 'wcfmmarketplace': + // phpcs:disable $orders = $wpdb->get_results( "SELECT p.* FROM wp_posts p @@ -74,7 +75,8 @@ public static function get_items( $plugin, $number, $offset ) { OFFSET {$offset} " ); - break; + // phpcs:enable + break; default: $orders = get_posts( $args ); From 3b0e76157fe4a13fc79b9ce8095c411f82fca8e6 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Tue, 18 Jul 2023 16:50:59 +0600 Subject: [PATCH 09/25] Refactor: YITH multivendor to dokan codes. --- includes/Handlers/OrderMigrationHandler.php | 65 ------------- includes/Handlers/VendorMigrationHandler.php | 93 ------------------- .../Handlers/WithdrawMigrationHandler.php | 78 ---------------- .../YithMultiVendor/OrderMigrator.php | 16 +++- .../YithMultiVendor/VendorMigrator.php | 17 +++- .../YithMultiVendor/WithdrawMigrator.php | 15 ++- includes/Migrator/Ajax.php | 2 +- includes/Migrator/Manager.php | 8 +- includes/Processors/Order.php | 4 + includes/Processors/Vendor.php | 18 ++++ includes/Processors/Withdraw.php | 11 +++ 11 files changed, 83 insertions(+), 244 deletions(-) delete mode 100644 includes/Handlers/OrderMigrationHandler.php delete mode 100644 includes/Handlers/VendorMigrationHandler.php delete mode 100644 includes/Handlers/WithdrawMigrationHandler.php diff --git a/includes/Handlers/OrderMigrationHandler.php b/includes/Handlers/OrderMigrationHandler.php deleted file mode 100644 index 13a891a..0000000 --- a/includes/Handlers/OrderMigrationHandler.php +++ /dev/null @@ -1,65 +0,0 @@ -get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}posts WHERE post_type='shop_order' AND post_parent=0" ); - } - - /** - * Returns array of items vendor. - * - * @since 1.0.0 - * - * @return array - */ - public function get_items( $plugin, $number, $offset ) { - $args = array( - 'post_type' => 'shop_order', - 'orderby' => 'ASC', - 'post_status' => 'any', - 'offset' => $offset, - 'posts_per_page' => $number, - 'post_parent' => 0, - ); - - return get_posts( $args ); - } - - /** - * Return class to handle migration. - * - * @since 1.0.0 - * - * @return Class - */ - public function get_migration_class( $plugin ) { - switch ( $plugin ) { - case 'wcfmmarketplace': - return new WcfmOrderMigrator(); - - case 'yithvendors': - return new YithMultiVendorOrderMigrator(); - - default: - break; - } - } -} diff --git a/includes/Handlers/VendorMigrationHandler.php b/includes/Handlers/VendorMigrationHandler.php deleted file mode 100644 index 3908fe0..0000000 --- a/includes/Handlers/VendorMigrationHandler.php +++ /dev/null @@ -1,93 +0,0 @@ - 'wcfm_vendor' ) ) ); - - case 'yithvendors': - return count( - get_terms( - array( - 'taxonomy' => 'yith_shop_vendor', - 'hide_empty' => false, - ) - ) - ); - - default: - return 0; - } - } - - /** - * Returns array of items vendor. - * - * @since 1.0.0 - * - * @return array - */ - public function get_items( $plugin, $number, $offset ) { - $args = [ - 'number' => $number, - 'offset' => $offset, - 'order' => 'ASC', - ]; - - switch ( $plugin ) { - case 'wcfmmarketplace': - $args['role'] = 'wcfm_vendor'; - break; - - case 'yithvendors': - $args['role'] = 'yith_vendor'; - break; - - default: - return []; - } - - $user_query = new WP_User_Query( $args ); - - return $user_query->get_results(); - } - - /** - * Return class to handle migration. - * - * @since 1.0.0 - * - * @return Class - */ - public function get_migration_class( $plugin ) { - switch ( $plugin ) { - case 'wcfmmarketplace': - return new WcfmVendorMigrator(); - - case 'yithvendors': - return new YithMultiVendorVendorMigrator(); - - default: - break; - } - } -} diff --git a/includes/Handlers/WithdrawMigrationHandler.php b/includes/Handlers/WithdrawMigrationHandler.php deleted file mode 100644 index ced0f40..0000000 --- a/includes/Handlers/WithdrawMigrationHandler.php +++ /dev/null @@ -1,78 +0,0 @@ -get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wcfm_marketplace_withdraw_request" ); - - case 'yithvendors': - return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product'" ); - - default: - return 0; - } - } - - /** - * Returns array of items vendor. - * - * @since 1.0.0 - * - * @return array - */ - public function get_items( $plugin, $number, $offset ) { - global $wpdb; - - switch ( $plugin ) { - case 'wcfmmarketplace': - return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}wcfm_marketplace_withdraw_request ORDER BY ID LIMIT %d OFFSET %d", $number, $offset ) ); - - case 'yithvendors': - return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product' ORDER BY id LIMIT %d OFFSET %d", $number, $offset ) ); - - default: - return []; - } - } - - /** - * Return class to handle migration. - * - * @since 1.0.0 - * - * @return Class - */ - public function get_migration_class( $plugin ) { - switch ( $plugin ) { - case 'wcfmmarketplace': - return new WcfmWithdrawMigrator(); - - case 'yithvendors': - return new YithMultiVendorWithdrawMigrator(); - break; - - default: - break; - } - } -} diff --git a/includes/Integrations/YithMultiVendor/OrderMigrator.php b/includes/Integrations/YithMultiVendor/OrderMigrator.php index cdce245..7df2cd6 100644 --- a/includes/Integrations/YithMultiVendor/OrderMigrator.php +++ b/includes/Integrations/YithMultiVendor/OrderMigrator.php @@ -1,8 +1,8 @@ order_id = $order->ID; + $this->order = wc_get_order( $this->order_id ); + } + /** * Create sub order if needed * diff --git a/includes/Integrations/YithMultiVendor/VendorMigrator.php b/includes/Integrations/YithMultiVendor/VendorMigrator.php index 3ca6593..dd24f4e 100644 --- a/includes/Integrations/YithMultiVendor/VendorMigrator.php +++ b/includes/Integrations/YithMultiVendor/VendorMigrator.php @@ -1,8 +1,8 @@ vendor = $vendor; + $this->meta_data = get_user_meta( $vendor->ID ); + $this->vendor_id = $vendor->ID; + } + /** * Returns vendor data from term, term taxonomy and term meta table. * diff --git a/includes/Integrations/YithMultiVendor/WithdrawMigrator.php b/includes/Integrations/YithMultiVendor/WithdrawMigrator.php index 82ddbd9..37bfe8a 100644 --- a/includes/Integrations/YithMultiVendor/WithdrawMigrator.php +++ b/includes/Integrations/YithMultiVendor/WithdrawMigrator.php @@ -1,8 +1,8 @@ set_withdraw_data( $withdraw ); + } + /** * Sets single withdraw item data. * diff --git a/includes/Migrator/Ajax.php b/includes/Migrator/Ajax.php index 6f1f528..af438c5 100644 --- a/includes/Migrator/Ajax.php +++ b/includes/Migrator/Ajax.php @@ -49,7 +49,7 @@ public function count() { $this->verify_nonce(); $import = ! empty( $_POST['import'] ) ? sanitize_text_field( wp_unslash( $_POST['import'] ) ) : 'vendor'; // phpcs:ignore WordPress.Security.NonceVerification - $migratable = ! empty( $_POST['migratable'] ) ? boolval( wp_unslash( $_POST['migratable'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification + $migratable = ! empty( $_POST['migratable'] ) ? sanitize_text_field( wp_unslash( $_POST['migratable'] ) ) : false; // phpcs:ignore WordPress.Security.NonceVerification try { $data = dokan_migrator()->migrator->get_total( $import, $migratable ); diff --git a/includes/Migrator/Manager.php b/includes/Migrator/Manager.php index 3a67d07..228d179 100644 --- a/includes/Migrator/Manager.php +++ b/includes/Migrator/Manager.php @@ -139,7 +139,7 @@ protected function set_data( $data ) { * * @param string $import_type Import type- `vendor` or `order` or `withdraw`. * - * @return void + * @return array */ public function get_total( $import_type, $migratable ) { $total_count = 0; @@ -172,11 +172,17 @@ public function migrate( $import_type, $plugin, $data ) { $this->set_data( $data ); $this->prevent_email_notification(); + /** + * @var $processor \WeDevs\DokanMigrator\Processors\Order|\WeDevs\DokanMigrator\Processors\Vendor|\WeDevs\DokanMigrator\Processors\Withdraw + */ $processor = $this->processor_class( $import_type ); $data = call_user_func( [ $processor, 'get_items' ], $plugin, $this->number, $this->offset ); foreach ( $data as $value ) { + /** + * @var $migrator \WeDevs\DokanMigrator\Abstracts\VendorMigration|\WeDevs\DokanMigrator\Abstracts\OrderMigration|\WeDevs\DokanMigrator\Abstracts\WithdrawMigration + */ $migrator = call_user_func( [ $processor, 'get_migration_class' ], $plugin, $value ); $migrator->process_migration(); } diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 8e98f5d..c26b580 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -9,6 +9,7 @@ use WeDevs\DokanMigrator\Abstracts\Processor; use WeDevs\DokanMigrator\Integrations\Wcfm\OrderMigrator as WcfmOrderMigrator; +use WeDevs\DokanMigrator\Integrations\YithMultiVendor\OrderMigrator as YithMultiVendorOrderMigrator; /** * Vendor migration handler class. @@ -74,6 +75,9 @@ public static function get_migration_class( $plugin, $payload ) { switch ( $plugin ) { case 'wcfmmarketplace': return new WcfmOrderMigrator( $payload ); + + case 'yithvendors': + return new YithMultiVendorOrderMigrator( $payload ); } throw new \Exception( __( 'Migrator class not found', 'dokan-migrator' ) ); diff --git a/includes/Processors/Vendor.php b/includes/Processors/Vendor.php index be43b55..34c4d5d 100644 --- a/includes/Processors/Vendor.php +++ b/includes/Processors/Vendor.php @@ -10,6 +10,7 @@ use \WP_User_Query; use WeDevs\DokanMigrator\Abstracts\Processor; use WeDevs\DokanMigrator\Integrations\Wcfm\VendorMigrator as WcfmVendorMigrator; +use WeDevs\DokanMigrator\Integrations\YithMultiVendor\VendorMigrator as YithMultiVendorVendorMigrator; /** * Vendor migration handler class. @@ -32,6 +33,16 @@ public static function get_total( $plugin ) { case 'wcfmmarketplace': return count( get_users( array( 'role' => 'wcfm_vendor' ) ) ); + case 'yithvendors': + return count( + get_terms( + array( + 'taxonomy' => 'yith_shop_vendor', + 'hide_empty' => false, + ) + ) + ); + default: return 0; } @@ -57,6 +68,10 @@ public static function get_items( $plugin, $number, $offset ) { $args['role'] = 'wcfm_vendor'; break; + case 'yithvendors': + $args['role'] = 'yith_vendor'; + break; + default: self::throw_error(); } @@ -86,6 +101,9 @@ public static function get_migration_class( $plugin, $payload ) { switch ( $plugin ) { case 'wcfmmarketplace': return new WcfmVendorMigrator( $payload ); + + case 'yithvendors': + return new YithMultiVendorVendorMigrator( $payload ); } throw new \Exception( __( 'Migrator class not found', 'dokan-migrator' ) ); diff --git a/includes/Processors/Withdraw.php b/includes/Processors/Withdraw.php index a5ffd7e..32574bf 100644 --- a/includes/Processors/Withdraw.php +++ b/includes/Processors/Withdraw.php @@ -9,6 +9,7 @@ use WeDevs\DokanMigrator\Abstracts\Processor; use WeDevs\DokanMigrator\Integrations\Wcfm\WithdrawMigrator as WcfmWithdrawMigrator; +use WeDevs\DokanMigrator\Integrations\YithMultiVendor\WithdrawMigrator as YithMultiVendorWithdrawMigrator; /** * Withdraw migration handler class. @@ -33,6 +34,9 @@ public static function get_total( $plugin ) { case 'wcfmmarketplace': return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}wcfm_marketplace_withdraw_request WHERE withdraw_status!='requested'" ); + case 'yithvendors': + return (int) $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product'" ); + default: return 0; } @@ -68,6 +72,10 @@ public static function get_items( $plugin, $number, $offset ) { $offset ) ); + break; + + case 'yithvendors': + return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product' ORDER BY id LIMIT %d OFFSET %d", $number, $offset ) ); } if ( empty( $withdraws ) ) { @@ -92,6 +100,9 @@ public static function get_migration_class( $plugin, $payload ) { switch ( $plugin ) { case 'wcfmmarketplace': return new WcfmWithdrawMigrator( $payload ); + + case 'yithvendors': + return new YithMultiVendorWithdrawMigrator( $payload ); } throw new \Exception( __( 'Migrator class not found', 'dokan-migrator' ) ); From 62828643fa35455d68b94853ca48e72484ebabdc Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Wed, 19 Jul 2023 10:58:44 +0600 Subject: [PATCH 10/25] Fix: version --- .../YithMultiVendor/OrderMigrator.php | 12 ++--- .../YithMultiVendor/VendorMigrator.php | 48 +++++++++---------- .../YithMultiVendor/WithdrawMigrator.php | 28 ++++++----- 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/includes/Integrations/YithMultiVendor/OrderMigrator.php b/includes/Integrations/YithMultiVendor/OrderMigrator.php index 7df2cd6..6734d9b 100644 --- a/includes/Integrations/YithMultiVendor/OrderMigrator.php +++ b/includes/Integrations/YithMultiVendor/OrderMigrator.php @@ -7,7 +7,7 @@ /** * Order migration class. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE */ class OrderMigrator extends OrderMigration { @@ -26,7 +26,7 @@ public function __construct( \WP_Post $order ) { /** * Create sub order if needed * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param int $seller_id * @param array $seller_products @@ -62,7 +62,7 @@ public function create_sub_order_if_needed( $seller_id, $seller_products, $paren /** * Spliting shipping amount and saving. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param \Wc_Order $child_order * @param \Wc_Order $parent_order @@ -126,7 +126,7 @@ public function add_splited_shipping( $order, $parent_order ) { /** * Delete sub orders of needed. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return void */ @@ -137,7 +137,7 @@ public function reset_sub_orders_if_needed() { /** * Gets order data from wcfm order table for dokan. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param int $parent_order_id * @param int $seller_id @@ -215,7 +215,7 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) { /** * Process refund for a child order. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param \Wc_Order $child_order * @param integer $seller_id diff --git a/includes/Integrations/YithMultiVendor/VendorMigrator.php b/includes/Integrations/YithMultiVendor/VendorMigrator.php index dd24f4e..21d58d3 100644 --- a/includes/Integrations/YithMultiVendor/VendorMigrator.php +++ b/includes/Integrations/YithMultiVendor/VendorMigrator.php @@ -7,14 +7,14 @@ /** * Formats vendor data for migration to Dokan. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE */ class VendorMigrator extends VendorMigration { /** * Class constructor * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param \WP_User $vendor */ @@ -27,7 +27,7 @@ public function __construct( \WP_User $vendor ) { /** * Returns vendor data from term, term taxonomy and term meta table. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $key * @@ -40,7 +40,7 @@ public function get_vendor_data_from_terms_table( $key ) { /** * Returns store name * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -53,7 +53,7 @@ public function get_store_name() { /** * Returns store description * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -64,7 +64,7 @@ public function get_store_biography() { /** * Returns is vendor has selling capability. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -75,7 +75,7 @@ public function get_enable_selling() { /** * Returns geo location address * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -86,7 +86,7 @@ public function get_geo_address() { /** * Returns vendor location latitude. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -97,7 +97,7 @@ public function get_geo_lat() { /** * Returns vendor location longitude. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -108,7 +108,7 @@ public function get_geo_long() { /** * Returns vendor social data. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return array */ @@ -119,7 +119,7 @@ public function get_social( $default ) { /** * Returns vendor payment data. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return array */ @@ -143,7 +143,7 @@ public function get_payment( $default ) { /** * Returns vendor phone number. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $default * @@ -156,7 +156,7 @@ public function get_phone( $default ) { /** * Returns if email show in store or not. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $default * @@ -169,7 +169,7 @@ public function get_is_show_email( $default ) { /** * Returns vendor address. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $default * @@ -191,7 +191,7 @@ public function get_address( $default ) { /** * Returns vendor location. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $default * @@ -204,7 +204,7 @@ public function get_location( $default ) { /** * Returns banner id. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param int $default * @@ -218,7 +218,7 @@ public function get_banner( $default ) { /** * Returns applied commission in an vendor. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $default * @@ -231,7 +231,7 @@ public function get_icon( $default ) { /** * Returns vendor gravatar. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $default * @@ -244,7 +244,7 @@ public function get_gravatar( $default ) { /** * Returns if show more p tab. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param mixed $default * @@ -257,7 +257,7 @@ public function get_show_more_ptab( $default ) { /** * Returns store product per page. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param int $default * @@ -270,7 +270,7 @@ public function get_sore_ppp( $default ) { /** * Returns applied commission in an vendor. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $default * @@ -283,7 +283,7 @@ public function get_is_enabled_tnc( $default ) { /** * Returns terms and comdition. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $default * @@ -296,7 +296,7 @@ public function get_store_tnc( $default ) { /** * Returns if min discount. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param string $default * @@ -309,7 +309,7 @@ public function get_show_min_order_discount( $default ) { /** * Returns store seo. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @param array $default * diff --git a/includes/Integrations/YithMultiVendor/WithdrawMigrator.php b/includes/Integrations/YithMultiVendor/WithdrawMigrator.php index 37bfe8a..8414bf6 100644 --- a/includes/Integrations/YithMultiVendor/WithdrawMigrator.php +++ b/includes/Integrations/YithMultiVendor/WithdrawMigrator.php @@ -7,13 +7,15 @@ /** * Formats vendor data for migration to Dokan. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE */ class WithdrawMigrator extends WithdrawMigration { /** * Current withdraw data. * + * @since DOKAN_MIG_SINCE + * * @var object */ private $withdraw = ''; @@ -21,6 +23,8 @@ class WithdrawMigrator extends WithdrawMigration { /** * Current withdraw metadata. * + * @since DOKAN_MIG_SINCE + * * @var array */ private $meta_data = ''; @@ -28,6 +32,8 @@ class WithdrawMigrator extends WithdrawMigration { /** * Current withdraw id. * + * @since DOKAN_MIG_SINCE + * * @var int */ private $withdraw_id = ''; @@ -46,7 +52,7 @@ public function __construct( $withdraw ) { /** * Sets single withdraw item data. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE */ public function set_withdraw_data( $withdraw_data ) { $this->withdraw = $withdraw_data; @@ -58,7 +64,7 @@ public function set_withdraw_data( $withdraw_data ) { /** * Returns vendor id. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return int */ @@ -69,7 +75,7 @@ public function get_vendor_id() { /** * Returns withdraw amount. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return int|float */ @@ -80,7 +86,7 @@ public function get_withdraw_amount() { /** * Returns withdraw created date. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -91,7 +97,7 @@ public function get_withdraw_created_date() { /** * Returns withdraw status. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -102,7 +108,7 @@ public function get_withdraw_status() { /** * Returns withdraw payment method. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -113,7 +119,7 @@ public function get_withdraw_payment_method() { /** * Returns withdraw note * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -124,7 +130,7 @@ public function get_withdraw_note() { /** * Returns withdraw details. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -160,7 +166,7 @@ public function get_withdraw_details() { /** * Returns withdraw ip. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return string */ @@ -171,7 +177,7 @@ public function get_withdraw_ip() { /** * Gets the withdraw meta data. * - * @since 1.0.0 + * @since DOKAN_MIG_SINCE * * @return array */ From 8c2be8c87bd3fa5256a8f3a3cfbcec6120827296 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Wed, 19 Jul 2023 11:58:11 +0600 Subject: [PATCH 11/25] Fix: throw error when withdraw finish --- includes/Processors/Withdraw.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/includes/Processors/Withdraw.php b/includes/Processors/Withdraw.php index 32574bf..7527be7 100644 --- a/includes/Processors/Withdraw.php +++ b/includes/Processors/Withdraw.php @@ -75,7 +75,9 @@ public static function get_items( $plugin, $number, $offset ) { break; case 'yithvendors': - return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product' ORDER BY id LIMIT %d OFFSET %d", $number, $offset ) ); + $withdraws = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product' ORDER BY id LIMIT %d OFFSET %d", $number, $offset ) ); + break; + // Items for wcfm. } if ( empty( $withdraws ) ) { From fe86af61ea6764e702cefea30827f9f5f0356e63 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Wed, 19 Jul 2023 11:59:37 +0600 Subject: [PATCH 12/25] Fix: throw error when withdraw finish --- includes/Processors/Withdraw.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Processors/Withdraw.php b/includes/Processors/Withdraw.php index 7527be7..c84e18e 100644 --- a/includes/Processors/Withdraw.php +++ b/includes/Processors/Withdraw.php @@ -75,7 +75,7 @@ public static function get_items( $plugin, $number, $offset ) { break; case 'yithvendors': - $withdraws = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product' ORDER BY id LIMIT %d OFFSET %d", $number, $offset ) ); + $withdraws = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE status='paid' AND type='product' ORDER BY id LIMIT %d OFFSET %d", $number, $offset ) ); break; // Items for wcfm. } From d3c984c5f95597991fda45e4e8c23d9dce0cc150 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:22:00 +0600 Subject: [PATCH 13/25] =?UTF-8?q?=E2=9A=A1=EF=B8=8FFix:=20exclude=20dokan?= =?UTF-8?q?=20orders,=20migrate=20wcfm=20orders=20only.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Processors/Order.php | 51 +++++++++++------------------------ 1 file changed, 16 insertions(+), 35 deletions(-) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 5d7dc28..bc768ea 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -29,18 +29,16 @@ class Order extends Processor { public static function get_total( $plugin ) { global $wpdb; - switch ( $plugin ) { + switch ( $plugin ) { case 'wcfmmarketplace': - return (int) $wpdb->get_var( - "SELECT COUNT(DISTINCT p.ID) - FROM wp_posts p - INNER JOIN {$wpdb->prefix}wcfm_marketplace_orders ON p.ID = {$wpdb->prefix}wcfm_marketplace_orders.order_id - " - ); + $total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT order_id ) FROM {$wpdb->prefix}wcfm_marketplace_orders" ); + break; default: - return (int) dokan()->order->all( [ 'return' => 'count' ] ); + $total = 0; } + + return $total; } /** @@ -53,41 +51,24 @@ public static function get_total( $plugin ) { * @throws \Exception */ public static function get_items( $plugin, $number, $offset ) { - global $wpdb; + global $wpdb; $args = array( - 'post_type' => 'shop_order', - 'orderby' => 'ID', - 'order' => 'DESC', - 'post_status' => 'any', - 'offset' => $offset, - 'posts_per_page' => $number, - 'post_parent' => 0, + 'order' => 'ASC', + 'paged' => $offset + 1, + 'limit' => $number, + 'parent' => 0, ); switch ( $plugin ) { case 'wcfmmarketplace': - // phpcs:disable - $orders = $wpdb->get_results( - "SELECT p.* - FROM wp_posts p - INNER JOIN {$wpdb->prefix}wcfm_marketplace_orders ON p.ID = {$wpdb->prefix}wcfm_marketplace_orders.order_id - ORDER BY p.ID DESC - LIMIT {$number} - OFFSET {$offset} - " - ); - // phpcs:enable + $wcfm_orders = $wpdb->get_results( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT {$number} OFFSET {$offset}", ARRAY_A ); + $wcfm_orders = array_map( function( $item ) { return $item['order_id']; }, $wcfm_orders ); + + $orders = dokan()->order->all( [ 'include' => $wcfm_orders ] ); break; default: - $args = array( - 'order' => 'ASC', - 'paged' => $offset + 1, - 'limit' => $number, - 'parent' => 0, - ); - - $orders = dokan()->order->all( $args ); + $orders = []; } if ( empty( $orders ) ) { From d97198410cd54b7ce7a5025004107220924dd501 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:31:19 +0600 Subject: [PATCH 14/25] =?UTF-8?q?=E2=9A=A1=EF=B8=8FFix:=20exclude=20dokan?= =?UTF-8?q?=20orders,=20migrate=20wcfm=20orders=20only.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Processors/Order.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index bc768ea..511f14e 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -31,7 +31,7 @@ public static function get_total( $plugin ) { switch ( $plugin ) { case 'wcfmmarketplace': - $total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT order_id ) FROM {$wpdb->prefix}wcfm_marketplace_orders" ); + $total = ( int ) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( DISTINCT order_id ) FROM {$wpdb->prefix}wcfm_marketplace_orders" ) ); break; default: @@ -61,7 +61,7 @@ public static function get_items( $plugin, $number, $offset ) { switch ( $plugin ) { case 'wcfmmarketplace': - $wcfm_orders = $wpdb->get_results( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT {$number} OFFSET {$offset}", ARRAY_A ); + $wcfm_orders = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT %d OFFSET {$offset}", $number ), ARRAY_A ); $wcfm_orders = array_map( function( $item ) { return $item['order_id']; }, $wcfm_orders ); $orders = dokan()->order->all( [ 'include' => $wcfm_orders ] ); From f915005975da67684ebc94716accdaf7a8e1a6b2 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:35:14 +0600 Subject: [PATCH 15/25] =?UTF-8?q?=E2=9A=A1=EF=B8=8FFix:=20exclude=20dokan?= =?UTF-8?q?=20orders,=20migrate=20wcfm=20orders=20only.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Processors/Order.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 511f14e..841c094 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -31,7 +31,7 @@ public static function get_total( $plugin ) { switch ( $plugin ) { case 'wcfmmarketplace': - $total = ( int ) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT( DISTINCT order_id ) FROM {$wpdb->prefix}wcfm_marketplace_orders" ) ); + $total = (int) $wpdb->get_var( "SELECT COUNT( DISTINCT order_id ) FROM {$wpdb->prefix}wcfm_marketplace_orders" ); break; default: @@ -62,7 +62,9 @@ public static function get_items( $plugin, $number, $offset ) { switch ( $plugin ) { case 'wcfmmarketplace': $wcfm_orders = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT %d OFFSET {$offset}", $number ), ARRAY_A ); - $wcfm_orders = array_map( function( $item ) { return $item['order_id']; }, $wcfm_orders ); + $wcfm_orders = array_map( function ( $item ) { + return $item['order_id']; + }, $wcfm_orders ); $orders = dokan()->order->all( [ 'include' => $wcfm_orders ] ); break; From 9ef1651badff9d73ba9f85ca24b447bf5d2bc779 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:36:00 +0600 Subject: [PATCH 16/25] =?UTF-8?q?=E2=9A=A1=EF=B8=8FFix:=20exclude=20dokan?= =?UTF-8?q?=20orders,=20migrate=20wcfm=20orders=20only.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Processors/Order.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 841c094..f936f92 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -59,19 +59,19 @@ public static function get_items( $plugin, $number, $offset ) { 'parent' => 0, ); - switch ( $plugin ) { - case 'wcfmmarketplace': + switch ( $plugin ) { + case 'wcfmmarketplace': $wcfm_orders = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT %d OFFSET {$offset}", $number ), ARRAY_A ); $wcfm_orders = array_map( function ( $item ) { return $item['order_id']; }, $wcfm_orders ); $orders = dokan()->order->all( [ 'include' => $wcfm_orders ] ); - break; + break; - default: + default: $orders = []; - } + } if ( empty( $orders ) ) { self::throw_error(); From ca6fcd29a3f44a4fd435ad7d8538c793239f353a Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:44:49 +0600 Subject: [PATCH 17/25] =?UTF-8?q?=E2=9A=A1=EF=B8=8FFix:=20exclude=20dokan?= =?UTF-8?q?=20orders,=20migrate=20wcfm=20orders=20only.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Processors/Order.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index f936f92..27f8ba7 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -61,12 +61,19 @@ public static function get_items( $plugin, $number, $offset ) { switch ( $plugin ) { case 'wcfmmarketplace': - $wcfm_orders = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT %d OFFSET {$offset}", $number ), ARRAY_A ); - $wcfm_orders = array_map( function ( $item ) { - return $item['order_id']; - }, $wcfm_orders ); - - $orders = dokan()->order->all( [ 'include' => $wcfm_orders ] ); + $wcfm_orders = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT %d OFFSET %d", $number, $offset ), ARRAY_A ); + $wcfm_orders = array_map( + function ( $item ) { + return $item['order_id']; + }, + $wcfm_orders + ); + + $orders = dokan()->order->all( + [ + 'include' => $wcfm_orders + ] + ); break; default: From f467977b868185f8d3bbbe6eaf6a9ce03e458fb6 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:46:08 +0600 Subject: [PATCH 18/25] =?UTF-8?q?=E2=9A=A1=EF=B8=8FFix:=20exclude=20dokan?= =?UTF-8?q?=20orders,=20migrate=20wcfm=20orders=20only.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Processors/Order.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 27f8ba7..0fb2233 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -71,7 +71,7 @@ function ( $item ) { $orders = dokan()->order->all( [ - 'include' => $wcfm_orders + 'include' => $wcfm_orders, ] ); break; From 9e16525ba8bb2b4675ac8a84604a9a463e661487 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 28 Aug 2023 13:55:02 +0600 Subject: [PATCH 19/25] =?UTF-8?q?=E2=9A=A1=EF=B8=8FHPOS=20support?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- includes/Processors/Order.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 0fb2233..9197a80 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -61,6 +61,7 @@ public static function get_items( $plugin, $number, $offset ) { switch ( $plugin ) { case 'wcfmmarketplace': + $orders = []; $wcfm_orders = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT order_id FROM {$wpdb->prefix}wcfm_marketplace_orders LIMIT %d OFFSET %d", $number, $offset ), ARRAY_A ); $wcfm_orders = array_map( function ( $item ) { @@ -69,11 +70,13 @@ function ( $item ) { $wcfm_orders ); - $orders = dokan()->order->all( - [ - 'include' => $wcfm_orders, - ] - ); + if ( ! empty( $wcfm_orders ) ) { + $orders = dokan()->order->all( + [ + 'include' => $wcfm_orders, + ] + ); + } break; default: From 2ac6d32c6f21d6dfe75c4a0e7108bf028fb3e2ef Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 28 Aug 2023 15:21:13 +0600 Subject: [PATCH 20/25] Fix yith multivendor order support --- includes/Processors/Order.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 27e5fd7..60f47e7 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -42,6 +42,7 @@ public static function get_total( $plugin ) { 'parent' => 0, ] ); + break; default: $total = 0; @@ -88,6 +89,10 @@ function ( $item ) { } break; + case 'yithvendors': + $orders = dokan()->order->all( $args ); + break; + default: $orders = []; } From a676b138d6623500c9941ed68314c2dc1002faef Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Tue, 29 Aug 2023 12:46:04 +0600 Subject: [PATCH 21/25] Hpos support and order vendor id fix --- .../YithMultiVendor/OrderMigrator.php | 73 +++++++++++-------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/includes/Integrations/YithMultiVendor/OrderMigrator.php b/includes/Integrations/YithMultiVendor/OrderMigrator.php index 6734d9b..698578b 100644 --- a/includes/Integrations/YithMultiVendor/OrderMigrator.php +++ b/includes/Integrations/YithMultiVendor/OrderMigrator.php @@ -16,11 +16,11 @@ class OrderMigrator extends OrderMigration { * * @since DOKAN_MIG_SINCE * - * @param \WP_Post $order + * @param \WC_Order $order */ - public function __construct( \WP_Post $order ) { + public function __construct( \WC_Order $order ) { $this->order_id = $order->ID; - $this->order = wc_get_order( $this->order_id ); + $this->order = $order; } /** @@ -34,26 +34,24 @@ public function __construct( \WP_Post $order ) { * @return \WC_Order */ public function create_sub_order_if_needed( $seller_id, $seller_products, $parent_order_id ) { - $args = array( - 'posts_per_page' => -1, - 'order' => 'DESC', - 'post_parent' => $parent_order_id, - 'post_type' => 'shop_order', - ); + $orders = dokan()->order->get_child_orders( $parent_order_id ); + $parent_order = dokan()->order->get( $parent_order_id ); - $sub_orders = get_children( $args, ARRAY_A ); + $child_order = null; - $current_order = $parent_order_id; + foreach ( $orders as $order ) { + $order_items = $order->get_items(); + foreach ( $order_items as $product_item ) { + $post = get_post( $product_item->get_product_id(), ARRAY_A ); + $author = $post['post_author']; - foreach ( $sub_orders as $id => $sub_order ) { - if ( absint( $sub_order['post_author'] ) === $seller_id ) { - $current_order = $id; + if ( absint( $author ) === absint( $seller_id ) ) { + $child_order = $order; + break; + } } } - $child_order = wc_get_order( $current_order ); - $parent_order = wc_get_order( $parent_order_id ); - $this->add_splited_shipping( $child_order, $parent_order ); return $child_order; @@ -135,7 +133,7 @@ public function reset_sub_orders_if_needed() { } /** - * Gets order data from wcfm order table for dokan. + * Gets order data from yith order table for dokan. * * @since DOKAN_MIG_SINCE * @@ -146,7 +144,7 @@ public function reset_sub_orders_if_needed() { */ public function get_dokan_order_data( $parent_order_id, $seller_id ) { global $wpdb; - $wc_order = wc_get_order( $parent_order_id ); + $wc_order = dokan()->order->get( $parent_order_id ); $net_amount = 0; $order_total = $wc_order->get_total(); @@ -157,17 +155,10 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) { $order_total = $order_total - $wc_order->get_total_refunded(); } - $args = array( - 'posts_per_page' => -1, - 'order' => 'DESC', - 'post_parent' => $parent_order_id, - 'post_type' => 'shop_order', - ); - - $sub_orders = get_children( $args, ARRAY_A ); + $sub_orders = dokan()->order->get_child_orders( $parent_order_id ); - foreach ( $sub_orders as $id => $sub_order ) { - $orders = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE user_id = %d AND order_id=%d", $seller_id, $id ) ); + foreach ( $sub_orders as $sub_order ) { + $orders = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE user_id = %d AND order_id=%d", $seller_id, $sub_order->get_id() ) ); foreach ( $orders as $order ) { $net_amount += $order->amount - abs( $order->amount_refunded ); @@ -195,7 +186,27 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) { if ( count( $sub_orders ) === 1 ) { // update post type $sub_order = reset( $sub_orders ); - set_post_type( $sub_order['ID'], 'dep_yith_order' ); + set_post_type( $sub_order->get_id(), 'dep_yith_order' ); + + // If HPOS enabled + if ( class_exists( \Automattic\WooCommerce\Utilities\OrderUtil::class ) && \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() ) { + global $wpdb; + + $wpdb->update( + $wpdb->prefix . 'wc_orders', + [ 'type' => 'dep_yith_order' ], + [ 'id' => $sub_order->get_id() ] + ); + } + + $wc_order->update_meta_data( 'has_sub_order', 0 ); + $wc_order->save(); + } else { + foreach ( $sub_orders as $sub_order ) { + $sub_order_seller_id = dokan_get_seller_id_by_order( $sub_order->get_id() ); + $sub_order->update_meta_data( '_dokan_vendor_id', $sub_order_seller_id ); + $sub_order->save(); + } } foreach ( $commissions as $com ) { @@ -225,7 +236,7 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) { */ public function process_refund( $child_order, $seller_id, $from_suborder = true ) { global $wpdb; - $order = wc_get_order( $child_order->get_id() ); + $order = dokan()->order->get( $child_order->get_id() ); $new_total_amount = $order->get_total() - $order->get_total_refunded(); // insert on dokan sync table From 2c6e726f72f559a9479fcc46874416cf0a6664ad Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Thu, 21 Sep 2023 15:35:56 +0600 Subject: [PATCH 22/25] Add paged key support in api --- includes/Abstracts/Processor.php | 7 +++++-- includes/Migrator/Ajax.php | 1 + includes/Migrator/Manager.php | 13 ++++++++++++- includes/Processors/Order.php | 5 +++-- includes/Processors/Vendor.php | 2 +- includes/Processors/Withdraw.php | 4 ++-- src/components/DokanMigrator.js | 8 +++++--- 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/includes/Abstracts/Processor.php b/includes/Abstracts/Processor.php index 5ab7f9e..4c2de27 100644 --- a/includes/Abstracts/Processor.php +++ b/includes/Abstracts/Processor.php @@ -30,11 +30,14 @@ abstract public static function get_total( $plugin ); * * @since 1.0.0 * - * @param string $plugin + * @param string $plugin + * @param integer $number + * @param integer $offset + * @param integer $paged * * @return array */ - abstract public static function get_items( $plugin, $number, $offset ); + abstract public static function get_items( $plugin, $number, $offset, $paged ); /** * Return class to handle migration. diff --git a/includes/Migrator/Ajax.php b/includes/Migrator/Ajax.php index 6f1f528..386f09e 100644 --- a/includes/Migrator/Ajax.php +++ b/includes/Migrator/Ajax.php @@ -82,6 +82,7 @@ public function import() { $args = [ 'number' => ! empty( $_REQUEST['number'] ) ? absint( $_REQUEST['number'] ) : 10, // phpcs:ignore WordPress.Security.NonceVerification 'offset' => ! empty( $_REQUEST['offset'] ) ? absint( $_REQUEST['offset'] ) : 0, // phpcs:ignore WordPress.Security.NonceVerification + 'paged' => ! empty( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0, // phpcs:ignore WordPress.Security.NonceVerification 'total_count' => ! empty( $_REQUEST['total_count'] ) ? absint( $_REQUEST['total_count'] ) : 0, // phpcs:ignore WordPress.Security.NonceVerification 'total_migrated' => ! empty( $_REQUEST['total_migrated'] ) ? absint( $_REQUEST['total_migrated'] ) : 0, // phpcs:ignore WordPress.Security.NonceVerification ]; diff --git a/includes/Migrator/Manager.php b/includes/Migrator/Manager.php index 4e48169..fdddb8b 100644 --- a/includes/Migrator/Manager.php +++ b/includes/Migrator/Manager.php @@ -39,6 +39,15 @@ class Manager { */ private $offset = 0; + /** + * Get data page id + * + * @since DOKAN_MIG_SINCE + * + * @var integer + */ + private $paged = 1; + /** * Number of vendors to be migrated. * @@ -133,6 +142,7 @@ protected function set_import_type( $import_type ) { protected function set_data( $data ) { $this->number = ! empty( $data['number'] ) ? intval( $data['number'] ) : $this->number; $this->offset = ! empty( $data['offset'] ) ? intval( $data['offset'] ) : $this->offset; + $this->paged = ! empty( $data['paged'] ) ? intval( $data['paged'] ) : $this->paged; $this->total_count = ! empty( $data['total_count'] ) ? intval( $data['total_count'] ) : $this->total_count; $this->total_migrated = ! empty( $data['total_migrated'] ) ? intval( $data['total_migrated'] ) : $this->total_migrated; } @@ -177,7 +187,7 @@ public function migrate( $import_type, $plugin, $data ) { $processor = $this->processor_class( $import_type ); - $data_to_migrate = call_user_func( [ $processor, 'get_items' ], $plugin, $this->number, $this->offset ); + $data_to_migrate = call_user_func( [ $processor, 'get_items' ], $plugin, $this->number, $this->offset, $this->paged ); foreach ( $data_to_migrate as $value ) { /** @@ -191,6 +201,7 @@ public function migrate( $import_type, $plugin, $data ) { 'migrated' => count( $data_to_migrate ), 'next' => count( $data_to_migrate ) + $this->offset, 'total_migrated' => count( $data_to_migrate ) + $this->total_migrated, + 'paged' => $this->paged, ]; $progress = ( $args['total_migrated'] * 100 ) / $this->total_count; diff --git a/includes/Processors/Order.php b/includes/Processors/Order.php index 66327c1..21d9978 100644 --- a/includes/Processors/Order.php +++ b/includes/Processors/Order.php @@ -39,10 +39,11 @@ public static function get_total( $plugin ) { * * @throws \Exception */ - public static function get_items( $plugin, $number, $offset ) { + public static function get_items( $plugin, $number, $offset, $paged ) { + global $wpdb; $args = array( 'order' => 'ASC', - 'paged' => $offset + 1, + 'paged' => $paged, 'limit' => $number, 'parent' => 0, ); diff --git a/includes/Processors/Vendor.php b/includes/Processors/Vendor.php index be43b55..1161d28 100644 --- a/includes/Processors/Vendor.php +++ b/includes/Processors/Vendor.php @@ -45,7 +45,7 @@ public static function get_total( $plugin ) { * @return array * @throws \Exception */ - public static function get_items( $plugin, $number, $offset ) { + public static function get_items( $plugin, $number, $offset, $paged ) { $args = [ 'number' => $number, 'offset' => $offset, diff --git a/includes/Processors/Withdraw.php b/includes/Processors/Withdraw.php index a5ffd7e..2530da6 100644 --- a/includes/Processors/Withdraw.php +++ b/includes/Processors/Withdraw.php @@ -46,8 +46,8 @@ public static function get_total( $plugin ) { * @return array * @throws \Exception */ - public static function get_items( $plugin, $number, $offset ) { - global $wpdb; + public static function get_items( $plugin, $number, $offset, $paged ) { + global $wpdb; $withdraws = []; if ( 0 === (int) $offset ) { diff --git a/src/components/DokanMigrator.js b/src/components/DokanMigrator.js index 19dd5df..941b245 100644 --- a/src/components/DokanMigrator.js +++ b/src/components/DokanMigrator.js @@ -38,7 +38,7 @@ const DokanMigrator = (props) => { },[isLoading]); // Functions. - const migrateVendorsHandler = ( from = offset, totalItem = totalCount, getMigrated = totalMigrated ) => { + const migrationHandler = ( from = offset, totalItem = totalCount, getMigrated = totalMigrated, pageNum = 1 ) => { setIsLoading(true); sendRequest( { @@ -47,6 +47,7 @@ const DokanMigrator = (props) => { import: importType, number: number, offset: from, + paged: pageNum, total_count: totalItem, total_migrated: getMigrated } @@ -56,7 +57,8 @@ const DokanMigrator = (props) => { setTotalMigrated(resp.data.process.total_migrated); if ( resp.data.process && resp.data.process.migrated != 0 ) { setOffset(resp.data.process.next); - migrateVendorsHandler( resp.data.process.next, totalItem, resp.data.process.total_migrated ); + + migrationHandler( resp.data.process.next, totalItem, resp.data.process.total_migrated, pageNum + 1 ); } } else { setIsLoading(false); @@ -96,7 +98,7 @@ const DokanMigrator = (props) => { props.lastCompleted ? setTotalMigrated( resp.data.migrate.total_count ) : setTotalMigrated(respTotalMigrated); ! startMigration ? setIsLoading(false) : ''; - startMigration ? migrateVendorsHandler( respNext, resp.data.migrate.total_count, respTotalMigrated ) : ''; + startMigration ? migrationHandler( respNext, resp.data.migrate.total_count, respTotalMigrated, 1 ) : ''; } else { console.error(resp.data.message); From 3cab81fe8f8423945b3249cc4da86cf6d78db441 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 25 Sep 2023 13:52:47 +0600 Subject: [PATCH 23/25] Fix order migtration fatal --- .../YithMultiVendor/OrderMigrator.php | 36 ++++++++----- languages/dokan-migrator.pot | 54 +++++++++++++------ 2 files changed, 61 insertions(+), 29 deletions(-) diff --git a/includes/Integrations/YithMultiVendor/OrderMigrator.php b/includes/Integrations/YithMultiVendor/OrderMigrator.php index 698578b..7163ec0 100644 --- a/includes/Integrations/YithMultiVendor/OrderMigrator.php +++ b/includes/Integrations/YithMultiVendor/OrderMigrator.php @@ -11,17 +11,17 @@ */ class OrderMigrator extends OrderMigration { - /** - * Class constructor. - * - * @since DOKAN_MIG_SINCE - * - * @param \WC_Order $order - */ - public function __construct( \WC_Order $order ) { - $this->order_id = $order->ID; - $this->order = $order; - } + /** + * Class constructor. + * + * @since DOKAN_MIG_SINCE + * + * @param \WC_Order $order + */ + public function __construct( \WC_Order $order ) { + $this->order_id = $order->get_id(); + $this->order = $order; + } /** * Create sub order if needed @@ -75,7 +75,7 @@ public function add_splited_shipping( $order, $parent_order ) { if ( $shipping_methods ) { foreach ( $shipping_methods as $method_item_id => $shipping_object ) { $shipping_method = $shipping_object; - break; + break; } } @@ -161,7 +161,10 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) { $orders = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}yith_vendors_commissions WHERE user_id = %d AND order_id=%d", $seller_id, $sub_order->get_id() ) ); foreach ( $orders as $order ) { - $net_amount += $order->amount - abs( $order->amount_refunded ); + $refunded_amount = isset( $order->amount_refunded ) ? $order->amount_refunded : 0; + + $current_net_amount = isset( $order->amount ) ? $order->amount : 0; + $net_amount += $current_net_amount - $refunded_amount; $res_commission = [ 'type' => 'percent', @@ -174,7 +177,12 @@ public function get_dokan_order_data( $parent_order_id, $seller_id ) { ]; $unit_commissin_rate_admin = 100 - ( $order->rate * 100 ); - $new_admin_commissin = ( $wc_order->get_subtotal() * $unit_commissin_rate_admin ) / 100; + + if ( $current_net_amount ) { + $new_admin_commissin = $sub_order->get_subtotal() - $current_net_amount; + } else { + $new_admin_commissin = ( $sub_order->get_subtotal() * $unit_commissin_rate_admin ) / 100; + } $res_commission['percentage'] = $unit_commissin_rate_admin; $res_commission['admin_commission'] = $new_admin_commissin; diff --git a/languages/dokan-migrator.pot b/languages/dokan-migrator.pot index cbffa57..614652e 100644 --- a/languages/dokan-migrator.pot +++ b/languages/dokan-migrator.pot @@ -1,4 +1,4 @@ -# Copyright (c) 2022 weDevs Pte. Ltd. All Rights Reserved. +# Copyright (c) 2023 weDevs Pte. Ltd. All Rights Reserved. msgid "" msgstr "" "Project-Id-Version: Dokan Migrator 1.0.0\n" @@ -8,9 +8,9 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"POT-Creation-Date: 2022-10-18T06:15:22+00:00\n" +"POT-Creation-Date: 2023-09-25T06:00:19+00:00\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" -"X-Generator: WP-CLI 2.6.0\n" +"X-Generator: WP-CLI 2.7.1\n" "X-Domain: dokan-migrator\n" #. Plugin Name of the plugin @@ -35,49 +35,73 @@ msgstr "" msgid "https://WeDevs.com/" msgstr "" -#: includes/Helpers/MigrationHelper.php:57 +#: includes/Helpers/MigrationHelper.php:63 msgid "Dokan vendor dashboard activated." msgstr "" -#: includes/Helpers/MigrationHelper.php:91 +#: includes/Helpers/MigrationHelper.php:75 +msgid "Page Installation" +msgstr "" + +#: includes/Helpers/MigrationHelper.php:76 +msgid "Triggering fron dokan migrator" +msgstr "" + +#: includes/Helpers/MigrationHelper.php:77 +msgid "Install Dokan Pages" +msgstr "" + +#: includes/Helpers/MigrationHelper.php:105 +msgid "Dashboard" +msgstr "" + +#: includes/Helpers/MigrationHelper.php:111 +msgid "Store List" +msgstr "" + +#: includes/Helpers/MigrationHelper.php:178 msgid "Migrate to dokan" msgstr "" -#: includes/Helpers/MigrationHelper.php:95 +#: includes/Helpers/MigrationHelper.php:182 msgid "Migrate Wcfm To Dokan" msgstr "" +#: includes/Helpers/MigrationHelper.php:186 +msgid "Migrate YITH WooCommerce Multi Vendor To Dokan." +msgstr "" + #: includes/Migrator/Ajax.php:59 msgid "Item count successfull." msgstr "" -#: includes/Migrator/Ajax.php:93 +#: includes/Migrator/Ajax.php:94 msgid "Import successfull." msgstr "" -#: includes/Migrator/Ajax.php:117 +#: includes/Migrator/Ajax.php:118 msgid "Nonce verification failed!" msgstr "" -#: includes/Migrator/Manager.php:215 +#: includes/Migrator/Manager.php:235 msgid "Invalid import type" msgstr "" -#: includes/Processors/Order.php:79 -#: includes/Processors/Vendor.php:91 -#: includes/Processors/Withdraw.php:96 +#: includes/Processors/Order.php:127 +#: includes/Processors/Vendor.php:109 +#: includes/Processors/Withdraw.php:110 msgid "Migrator class not found" msgstr "" -#: includes/Processors/Order.php:94 +#: includes/Processors/Order.php:142 msgid "No orders found to migrate to dokan." msgstr "" -#: includes/Processors/Vendor.php:104 +#: includes/Processors/Vendor.php:122 msgid "No vendors found to migrate to dokan." msgstr "" -#: includes/Processors/Withdraw.php:124 +#: includes/Processors/Withdraw.php:138 msgid "No withdraws found to migrate to dokan." msgstr "" From dc2fa061464f49449cef78db0a34a0749ea5cb33 Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Mon, 25 Sep 2023 14:00:33 +0600 Subject: [PATCH 24/25] Add get seller by order abstract method --- includes/Abstracts/OrderMigration.php | 11 ++++++++++- includes/Integrations/Wcfm/OrderMigrator.php | 13 ++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/includes/Abstracts/OrderMigration.php b/includes/Abstracts/OrderMigration.php index 4c27de8..8f26658 100644 --- a/includes/Abstracts/OrderMigration.php +++ b/includes/Abstracts/OrderMigration.php @@ -76,6 +76,15 @@ abstract public function create_sub_order_if_needed( $seller_id, $seller_product */ abstract public function reset_sub_orders_if_needed(); + /** + * Get seller by order/order id + * + * @since DOKAN_MIG_SINCE + * + * @return void + */ + abstract public function get_seller_by_order( $order_id ); + /** * Returns true if the order has sub orders. * @@ -243,7 +252,7 @@ public function sync_dokan_order_table( $dokan_order_data, $sub_order_id, $selle * @return void */ public function process_migration() { - $vendors = dokan_get_sellers_by( $this->order_id ); + $vendors = $this->get_seller_by_order( $this->order_id ); $this->reset_sub_orders_if_needed(); diff --git a/includes/Integrations/Wcfm/OrderMigrator.php b/includes/Integrations/Wcfm/OrderMigrator.php index 02b5b44..538ece9 100644 --- a/includes/Integrations/Wcfm/OrderMigrator.php +++ b/includes/Integrations/Wcfm/OrderMigrator.php @@ -442,7 +442,7 @@ public function split_parent_order_shipping( $applied_shipping_method, $order_id } $applied_shipping_method = reset( $parent_order->get_shipping_methods() ); - $vendors = dokan_get_sellers_by( $parent_order->get_id() ); + $vendors = $this->get_seller_by_order( $parent_order->get_id() ); // Here we are dividing the shipping and shipping-tax amount of parent order into the vendors suborders. $shipping_tax_amount = [ @@ -482,4 +482,15 @@ public function split_parent_order_shipping( $applied_shipping_method, $order_id return $item; } + + /** + * Returns all sellers of an order. + * + * @param int $order_id + * + * @return array + */ + public function get_seller_by_order( $order_id ) { + return dokan_get_sellers_by( $order_id ); + } } From b098454efe92d2e6aca54dda3a488991c0a928fb Mon Sep 17 00:00:00 2001 From: Aunshon <32583103+Aunshon@users.noreply.github.com> Date: Tue, 26 Sep 2023 11:06:39 +0600 Subject: [PATCH 25/25] Yith order commission amount and fix vendor product owner id --- includes/Integrations/Wcfm/OrderMigrator.php | 2 + .../YithMultiVendor/OrderMigrator.php | 53 ++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/includes/Integrations/Wcfm/OrderMigrator.php b/includes/Integrations/Wcfm/OrderMigrator.php index 538ece9..f861ddc 100644 --- a/includes/Integrations/Wcfm/OrderMigrator.php +++ b/includes/Integrations/Wcfm/OrderMigrator.php @@ -486,6 +486,8 @@ public function split_parent_order_shipping( $applied_shipping_method, $order_id /** * Returns all sellers of an order. * + * @since DOKAN_MIG_SINCE + * * @param int $order_id * * @return array diff --git a/includes/Integrations/YithMultiVendor/OrderMigrator.php b/includes/Integrations/YithMultiVendor/OrderMigrator.php index 7163ec0..5beaf5f 100644 --- a/includes/Integrations/YithMultiVendor/OrderMigrator.php +++ b/includes/Integrations/YithMultiVendor/OrderMigrator.php @@ -86,7 +86,7 @@ public function add_splited_shipping( $order, $parent_order ) { if ( is_a( $shipping_method, 'WC_Order_Item_Shipping' ) ) { $item = new \WC_Order_Item_Shipping(); - $vendors = dokan_get_sellers_by( $parent_order->get_id() ); + $vendors = $this->get_seller_by_order( $parent_order->get_id() ); $vendors = count( $vendors ); $taxes = $shipping_method->get_taxes(); @@ -262,4 +262,55 @@ public function process_refund( $child_order, $seller_id, $from_suborder = true ) ); } + + /** + * Returns all sellers of an order. + * + * @since DOKAN_MIG_SINCE + * + * @param int $order_id + * + * @return array + */ + public function get_seller_by_order( $order_id ) { + global $wpdb; + $taxonomy = 'yith_shop_vendor'; + if ( function_exists( 'YITH_Vendors' ) && method_exists( YITH_Vendors::class, 'get_taxonomy_name' ) ) { + $taxonomy = YITH_Vendors ()->get_taxonomy_name(); + } + + $user_taxonomy = 'yith_product_vendor'; + if ( function_exists( 'YITH_Vendors' ) && method_exists( YITH_Vendors::class, 'get_user_meta_key' ) ) { + $user_taxonomy = YITH_Vendors ()->get_user_meta_key(); + } + + $order = dokan()->order->get( $this->order_id ); + + foreach ( $order->get_items() as $order_item ) { + $terms = wp_get_post_terms ( $order_item->get_product_id(), $taxonomy ); + + if ( empty( $terms ) || is_wp_error( $terms ) ) { + continue; + } + + /** + * @var \WP_Term $vendor_term + */ + $vendor_term = array_shift ( $terms ); + // phpcs:ignore + $user_meta = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}usermeta WHERE meta_key='{$user_taxonomy}' AND meta_value='%s'", $vendor_term->term_id ) ); + + if ( ! isset( $user_meta->user_id ) ) { + continue; + } + + $arg = array( + 'ID' => $order_item->get_product_id(), + 'post_author' => $user_meta->user_id, + ); + wp_update_post( $arg ); + } + + return dokan_get_sellers_by( $order_id ); + } }