Skip to content

Commit

Permalink
Version 0.5.0: optimized bulk create consignments
Browse files Browse the repository at this point in the history
  • Loading branch information
dmattke committed Mar 7, 2018
1 parent 5e5f329 commit e43dc67
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
43 changes: 34 additions & 9 deletions include/controllers/ShopOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,43 @@ function __construct( ){
add_action( 'save_post', array($this, 'saveConsignmentSettgings'), 10, 1 );
add_action( 'save_post', array($this, 'saveConsignment'), 20, 1 );
add_action( 'init', array($this, 'resetConsignment') , 10, 2 );
add_filter( 'bulk_actions-edit-shop_order', array($this, 'filterBulkActions' ) );
add_action( 'init', array($this, 'bulkCreateConsigments' ) );
add_filter( 'bulk_actions-edit-shop_order', array($this, 'filterBulkActions') );
add_action( 'handle_bulk_actions-edit-shop_order', array($this, 'bulkCreateConsigments' ), 10, 3 );
add_action( 'admin_notices', array($this, 'setBulkAdminNotice') );
}


function bulkCreateConsigments(){
if ( _is($_REQUEST, 'action') == 'create_consignment' ){
if ( isset($_REQUEST['post']) && is_array($_REQUEST['post']) && !empty($_REQUEST['post']) ) {
foreach ($_REQUEST['post'] as $key => $order_id) {
$_REQUEST['post_ID'] = $order_id;
$this->saveConsignment($order_id, $force=true, $create=false);
}
function setBulkAdminNotice() {
// _log('ShopOrderController::setBulkAdminNotice()');
if ( isset($_REQUEST['bulk_created_consignments']) && is_numeric($_REQUEST['bulk_created_consignments']) ) {
printf( '<div id="message" class="updated">%s %s</div>', $_REQUEST['bulk_created_consignments'], __('consignments created', 'wc-cargonizer') );
}
}


function bulkCreateConsigments( $redirect_to, $doaction, $post_ids ){
_log('ShopOrderController::bulkCreateConsigments()');
_log($doaction);
_log($post_ids);

if ( $doaction !== 'create_consignment' ) {
return $redirect_to;
}

if ( is_array($post_ids) && !empty($post_ids) ) {
foreach ($post_ids as $key => $order_id) {
$_REQUEST['post_ID'] = $order_id;
$this->saveConsignment($order_id, $force=true, $create=false);
}
}
else{
_log('no post ids checked');
}

$redirect_to = add_query_arg( 'bulk_created_consignments', count( $post_ids ), $redirect_to );


return $redirect_to;
}


Expand Down Expand Up @@ -88,6 +111,7 @@ function saveConsignmentSettgings( $post_id ){


function saveConsignment( $post_id, $force=false, $create=true ){

if ( !isset($_REQUEST['post_ID']) or $_REQUEST['post_ID'] != $post_id ){
return false;
}
Expand All @@ -105,6 +129,7 @@ function saveConsignment( $post_id, $force=false, $create=true ){
_log('... is ready');
if ( $cid = Consignment::createOrUpdate( $Order, $recurring=false ) ){
_log('consignment created/updated: '.$cid);

if ( $create ){
_log('create consignment now');
$result = ConsignmentController::createConsignment($cid);
Expand Down
2 changes: 1 addition & 1 deletion woocommerce-cargonizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*woo
Plugin Name: Woocommerce Cargonizer
Description:
Version: 0.4.9
Version: 0.5.0
Author: Mediebruket AS
Author URI: http://mediebruket.no
*/
Expand Down

0 comments on commit e43dc67

Please sign in to comment.