Skip to content

Commit

Permalink
Merge branch 'refs/heads/develop' into update/vendor-dashboard-structure
Browse files Browse the repository at this point in the history
# Conflicts:
#	composer.lock
  • Loading branch information
MdAsifHossainNadim committed Nov 29, 2024
2 parents 46bcda5 + f6b2f86 commit 16f8a1d
Show file tree
Hide file tree
Showing 53 changed files with 1,598 additions and 467 deletions.
7 changes: 6 additions & 1 deletion assets/src/js/setup-wizard/commission/AdminCommission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@
this.fixedCommission.fixed = commission.additional_fee ? Number( commission.additional_fee ) : 0;
this.fixedCommission.percentage = commission.admin_percentage ? Number( commission.admin_percentage ) : 0;
this.selectedCommission = commission.commission_type ? String(commission.commission_type) : 'fixed';
this.commission = commission.commission_category_based_values;
let commission_category_based_values = commission.commission_category_based_values;
commission_category_based_values.all = ! commission_category_based_values.all || Array.isArray( commission_category_based_values.all ) ? {} : commission_category_based_values.all;
commission_category_based_values.items = ! commission_category_based_values.items || Array.isArray( commission_category_based_values.items ) ? {} : commission_category_based_values.items;
this.commission = commission_category_based_values;
},
methods: {
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"minimum-stability": "dev",
"require": {
"php": ">=7.4",
"appsero/client": "^v2.0.2",
"appsero/client": "^v2.0.4",
"jakeasmith/http_build_url": "^1",
"appsero/updater": "^v2.3.0"
"appsero/updater": "^v2.3.1"
},
"require-dev": {
"wp-coding-standards/wpcs": "dev-develop",
Expand Down
120 changes: 60 additions & 60 deletions composer.lock

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions includes/Admin/Notices/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ private function init_hooks() {
add_filter( 'dokan_admin_notices', [ $this, 'show_permalink_setting_notice' ] );
add_filter( 'dokan_admin_notices', [ $this, 'show_admin_logo_update_notice' ] );
add_action( 'wp_ajax_dismiss_dokan_admin_logo_update_notice', [ $this, 'dismiss_dokan_admin_logo_update_notice' ] );
add_filter( 'dokan_admin_notices', [ $this, 'show_admin_plugin_update_notice' ] );
}

/**
Expand Down Expand Up @@ -189,4 +190,39 @@ private function dismiss_notice( string $option_name ) {
update_option( $option_name, 'yes' );
wp_send_json_success();
}

/**
* Show admin notice if dokan lite is updated to v3.14.0 and dokan pro is not updated to minimum v3.14.0.
*
* @since DOKAN_SINCE
*
* @param $notices
*
* @return mixed
*/
public function show_admin_plugin_update_notice( $notices ) {
if (
version_compare( DOKAN_PLUGIN_VERSION, '3.14.0', '>=' ) &&
defined( 'DOKAN_PRO_PLUGIN_VERSION' ) &&
version_compare( DOKAN_PRO_PLUGIN_VERSION, '3.14.0', '<' )
) {
$notices[] = [
'priority' => 1,
'show_close_button' => false,
'type' => 'alert',
'scope' => 'global',
'title' => __( 'Dokan Update Required', 'dokan-lite' ),
'description' => __( 'To ensure all the feature compatibility and accessibility, Dokan Pro minimum v3.14.0 is required.', 'dokan-lite' ),
'actions' => [
[
'type' => 'primary',
'text' => __( 'Update Now', 'dokan-lite' ),
'action' => admin_url( 'plugins.php' ),
],
],
];
}

return $notices;
}
}
11 changes: 6 additions & 5 deletions includes/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,13 @@ public function get_settings_fields() {
],
],
'commission_category_based_values' => [
'name' => 'commission_category_based_values',
'type' => 'category_based_commission',
'name' => 'commission_category_based_values',
'type' => 'category_based_commission',
'dokan_pro_commission' => 'yes',
'label' => __( 'Admin Commission', 'dokan-lite' ),
'desc' => __( 'Amount you will get from each sale', 'dokan-lite' ),
'show_if' => [
'label' => __( 'Admin Commission', 'dokan-lite' ),
'desc' => __( 'Amount you will get from each sale', 'dokan-lite' ),
'required' => 'yes',
'show_if' => [
'commission_type' => [
'equal' => 'category_based',
],
Expand Down
6 changes: 6 additions & 0 deletions includes/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function __construct() {
*/
public function load_dokan_admin_notices_scripts() {
wp_enqueue_script( 'dokan-promo-notice-js' );
wp_enqueue_script( 'dokan-admin-notice-js' );
$vue_localize_script = apply_filters(
'dokan_promo_notice_localize_script', [
'ajaxurl' => admin_url( 'admin-ajax.php' ),
Expand Down Expand Up @@ -541,6 +542,11 @@ public function get_scripts() {
'deps' => [ 'jquery', 'dokan-vue-vendor' ],
'version' => filemtime( $asset_path . 'js/dokan-promo-notice.js' ),
],
'dokan-admin-notice-js' => [
'src' => $asset_url . '/js/dokan-admin-notice.js',
'deps' => [ 'jquery', 'dokan-vue-vendor' ],
'version' => filemtime( $asset_path . 'js/dokan-admin-notice.js' ),
],
'dokan-reverse-withdrawal' => [
'src' => $asset_url . '/js/reverse-withdrawal.js',
'deps' => [ 'jquery', 'dokan-util-helper', 'dokan-vue-vendor', 'dokan-date-range-picker' ],
Expand Down
10 changes: 9 additions & 1 deletion includes/Commission.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,15 @@ public function get_commission( $args = [], $auto_save = false ) {
$category_id = $category_id ? $category_id : 0;
}

if ( ! empty( $product_id ) && empty( $total_amount ) ) {
/**
* If the $total_amount is empty and $order_item_id is empty then we will calculate the commission based on the product price.
* There is a case where the $total_amount is empty and $order_item_id is empty but the $product_id is not empty
* In this case, we will calculate the commission based on the product price.
* Also there is an issue when 100% coupon is applied see the below link for more details
*
* @see https://github.com/getdokan/dokan/pull/2440#issuecomment-2488159960
*/
if ( ! empty( $product_id ) && empty( $total_amount ) && empty( $order_item_id ) ) {
$product = dokan()->product->get( $product_id );

// If product price is empty the setting the price as 0
Expand Down
222 changes: 222 additions & 0 deletions includes/Commission/Upugrader/Update_Category_Commission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
<?php

namespace WeDevs\Dokan\Commission\Upugrader;

use WeDevs\Dokan\Commission\Formula\Flat;
use WeDevs\Dokan\Commission\Formula\Percentage;
use WP_Term;

class Update_Category_Commission {
/**
* The batch size for processing categories
*
* @since DOKAN_PRO_SINCE
*/
const BATCH_SIZE = 20;

/**
* The hook name for processing batches
*
* @since DOKAN_PRO_SINCE
*/
const PROCESS_BATCH_HOOK = 'process_category_batch';
const PROCESS_BATCH_HOOK_CREATOR = 'process_category_batch_creator';

/**
*
* @since DOKAN_PRO_SINCE
*/
const PROCESS_ITEM_HOOK = 'process_category_item';

/**
* Initialize the processor
*/
public function init_hooks() {
add_action( self::PROCESS_BATCH_HOOK_CREATOR, [ $this, 'process_batch_creator' ] );
add_action( self::PROCESS_BATCH_HOOK, [ $this, 'process_batch' ] );
add_action( self::PROCESS_ITEM_HOOK, [ $this, 'process_single_category' ] );
}

/**
* Start the batch processing
*
* @since DOKAN_PRO_SINCE
*
* @return void
*/
public function start_processing() {
WC()->queue()->add(
self::PROCESS_BATCH_HOOK_CREATOR,
[],
'dokan_updater_category_processing_creator'
);
}

/**
* Batch queue creator.
*
* @since DOKAN_SINCE
*
* @return void
*/
public function process_batch_creator() {
// Get total number of products
$total = $this->category_count();

if ( is_wp_error( $total ) || $total === 0 ) {
return;
}

$total = $total + 50;
$offset = 0;

do {
$this->schedule_next_batch( $offset );

// Calculate next offset
$offset = $offset + self::BATCH_SIZE;
} while ( $offset < $total );
}

/**
* Process a batch of categories
*
* @since DOKAN_PRO_SINCE
*
* @param int $page_number Current page number
*
* @return void
*/
public function process_batch( $offset ) {
// Get categories for this batch
$categories = $this->get_categories_batch( $offset );

if ( ! empty( $categories ) && ! is_wp_error( $categories ) ) {
foreach ( $categories as $category ) {
$this->schedule_cat_item( $category->term_id );
}
}
}

/**
* Schedule the next batch of categories
*
* @since DOKAN_PRO_SINCE
*
* @param int $page_number Next page number to process
*
* @return void
*/
protected function schedule_next_batch( $offset ) {
WC()->queue()->add(
self::PROCESS_BATCH_HOOK,
[ $offset ],
'dokan_updater_category_processing'
);
}

/**
* Schedule a category item for processing.
*
* @since DOKAN_SINCE
*
* @param $term
*
* @return void
*/
private function schedule_cat_item( $term ) {
WC()->queue()->add(
self::PROCESS_ITEM_HOOK,
[ $term ],
'dokan_updater_category_item_processing'
);
}

/**
* Get a batch of categories.
*
* @since DOKAN_PRO_SINCE
*
* @param int $page_number Page number to fetch
*
* @return array Array of term objects
*/
protected function get_categories_batch( $offset ) {
$args = [
'taxonomy' => 'product_cat',
'number' => self::BATCH_SIZE,
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'offset' => $offset,
];

return get_terms( $args );
}

/**
* Get the total number of categories
*
* @since DOKAN_SINCE
*
* @return int[]|string|string[]|\WP_Error|\WP_Term[]
*/
protected function category_count() {
return get_terms(
array(
'taxonomy' => 'product_cat',
'hide_empty' => false,
'fields' => 'count',
)
);
}

/**
* Process a single category.
*
* @since DOKAN_PRO_SINCE
*
* @param int $term Category term object
*
* @return void
*/
public function process_single_category( $term_id ) {
$dokan_selling = get_option( 'dokan_selling', [] );
$category_commission = dokan_get_option( 'commission_category_based_values', 'dokan_selling', [] );

$commission_type = get_term_meta( $term_id, 'per_category_admin_commission_type', true );
$admin_additional_fee = get_term_meta( $term_id, 'per_category_admin_additional_fee', true );
$commission = get_term_meta( $term_id, 'per_category_admin_commission', true );

if ( ! empty( $commission_type ) ) {
$category_commission_item = [
'flat' => $admin_additional_fee,
'percentage' => $commission,
];

if ( Flat::SOURCE === $commission_type ) {
$category_commission_item['percentage'] = 0;
$category_commission_item['flat'] = $commission;
} elseif ( Percentage::SOURCE === $commission_type ) {
$category_commission_item['percentage'] = $commission;
$category_commission_item['flat'] = 0;
}

$category_commission['items'][ $term_id ] = $category_commission_item;
}

$dokan_selling['commission_category_based_values'] = $category_commission;
update_option( 'dokan_selling', $dokan_selling );
}

/**
* Check if processing is currently running.
*
* @since DOKAN_PRO_SINCE
*
* @return bool
*/
public function is_processing() {
return WC()->queue()->get_next( self::PROCESS_BATCH_HOOK ) !== null;
}
}
Loading

0 comments on commit 16f8a1d

Please sign in to comment.