Skip to content

Commit

Permalink
feat: add vendor bulk product delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohaiminulislam1989 committed Jul 20, 2018
1 parent 685f930 commit b688690
Show file tree
Hide file tree
Showing 4 changed files with 355 additions and 209 deletions.
47 changes: 47 additions & 0 deletions assets/js/dokan.js
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,53 @@ jQuery(function($) {

});


/**
* Change bulk order status in vendor dashboard
*/
var change_bulk_product_status = {
init: function() {
selected_products = [];

$( '#cb-select-all' ).on( 'change', function( e ) {
var self = $(this);

var product_id = $( '.cb-select-product' );

if ( self.is( ':checked' ) ) {
product_id.each( function ( key, value ) {
var product = $( value );

product.prop( 'checked', 'checked' );

selected_products.push( product.data( 'product_id' ) );
} );
} else {
product_id.each( function ( key, value ) {
$( value ).prop( 'checked', '' );
selected_products.pop();
} );
}
} );

$( '.cb-select-product' ).on( 'change', function( e ) {
var self = $(this);

if ( self.is( ':checked' ) ) {
selected_products.push( self.data( 'product_id' ) );
} else {
var index = selected_products.indexOf( self.data( 'product_id' ) );

if ( index !== -1) {
selected_products.splice( index, 1 );
}
}
} );
}
};

change_bulk_product_status.init();

})(jQuery);

jQuery(function($) {
Expand Down
47 changes: 47 additions & 0 deletions assets/src/js/product-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,4 +912,51 @@

});


/**
* Change bulk order status in vendor dashboard
*/
var change_bulk_product_status = {
init: function() {
selected_products = [];

$( '#cb-select-all' ).on( 'change', function( e ) {
var self = $(this);

var product_id = $( '.cb-select-product' );

if ( self.is( ':checked' ) ) {
product_id.each( function ( key, value ) {
var product = $( value );

product.prop( 'checked', 'checked' );

selected_products.push( product.data( 'product_id' ) );
} );
} else {
product_id.each( function ( key, value ) {
$( value ).prop( 'checked', '' );
selected_products.pop();
} );
}
} );

$( '.cb-select-product' ).on( 'change', function( e ) {
var self = $(this);

if ( self.is( ':checked' ) ) {
selected_products.push( self.data( 'product_id' ) );
} else {
var index = selected_products.indexOf( self.data( 'product_id' ) );

if ( index !== -1) {
selected_products.splice( index, 1 );
}
}
} );
}
};

change_bulk_product_status.init();

})(jQuery);
42 changes: 29 additions & 13 deletions includes/product-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,20 +489,36 @@ function dokan_product_get_row_action( $post ) {
return implode( ' | ', $row_action_html );
}

/**
* Change bulk product status in vendor dashboard
*
* @since 2.9.0
*
* @return string
*/
function dokan_bulk_product_status_change() {
if ( ! current_user_can( 'dokan_delete_product' ) ) {
return;
}
if ( ! isset( $_POST['security'] ) || ! wp_verify_nonce( $_POST['security'], 'bulk_product_status_change' ) ) {
return;
}
if ( ! isset( $_POST['status'] ) || ! isset( $_POST['bulk_products'] ) ) {
return;
}

$status = $_POST['status'];
$products = $_POST['bulk_products'];

// -1 means bluk action option value
if ( $status === '-1' ) {
return;
}

foreach ( $products as $product ) {
wp_delete_post( $product );
}
$_POST['delete'] = 'delete';
}














add_action( 'template_redirect', 'dokan_bulk_product_status_change' );
Loading

0 comments on commit b688690

Please sign in to comment.