From 2328a3b0425483f3752e6a56ce6a0f12198d6089 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 22 Jan 2018 08:00:22 +0100 Subject: [PATCH] vesion 0.4.5 --- admin/CargonizerAdmin.php | 10 ++--- include/Consignment.php | 6 +++ include/ShopOrder.php | 37 +++++++++++++++---- .../CargonizerCommonController.php | 8 +++- include/controllers/ShopOrderController.php | 37 +++++++++++++++---- woocommerce-cargonizer.php | 4 +- 6 files changed, 79 insertions(+), 23 deletions(-) diff --git a/admin/CargonizerAdmin.php b/admin/CargonizerAdmin.php index 9458592..e7e5d13 100644 --- a/admin/CargonizerAdmin.php +++ b/admin/CargonizerAdmin.php @@ -199,7 +199,7 @@ function registerFrontendScripts(){ if ( is_checkout() && get_option('cargonizer-use-service-partners') ){ $plugin_path = str_replace('admin/', null, plugin_dir_url(__FILE__) ); $path = $plugin_path.'assets/'; - + //wp_deregister_script('jquery'); wp_register_script( 'wcc-jquery', 'https://code.jquery.com/jquery-2.2.4.min.js', false, '2.2.5' ); wp_enqueue_script('wcc-jquery'); @@ -214,9 +214,9 @@ function registerFrontendScripts(){ foreach ($styles as $s) { echo '' . "\n"; - } + } } - + } @@ -274,7 +274,7 @@ function registerScripts(){ wp_enqueue_script( 'tableedit-js' ); } - + } @@ -491,7 +491,7 @@ public static function _fillCustomColumns( $column, $post_id ) { public static function addCargonizerActions( $post ){ - if ( is_object($post) && $post->post_type == 'consignment' ){ + if ( is_object($post) && $post->post_type == 'consignment' ){ $Consignment = new Consignment($post->ID); echo '
'; diff --git a/include/Consignment.php b/include/Consignment.php index e49e5d5..c5d2032 100644 --- a/include/Consignment.php +++ b/include/Consignment.php @@ -1069,11 +1069,17 @@ public static function _setShippingCosts($rates, $package){ $weight = $WC_P->get_weight(); $volume = 0; + if ( $width && $height && $length ){ $volume = $width * $height * $length / 1000; } $parcel['volume'] += $volume * $qty; + + if ( get_option('woocommerce_weight_unit') == 'g' ){ + $weight_unit /= 1000; + } + $parcel['weight'] += ($weight * $qty); } diff --git a/include/ShopOrder.php b/include/ShopOrder.php index ad30d4f..fed66dd 100644 --- a/include/ShopOrder.php +++ b/include/ShopOrder.php @@ -159,7 +159,7 @@ function getDefaultPackage(){ 'id' => 1, 'parcel_amount' => 1, 'parcel_description' => '', - 'parcel_weight' => $this->getTotalWeight(), + 'parcel_weight' => $this->getTotalWeight(), 'parcel_height' => get_option('cargonizer-parcel-height'), 'parcel_length' => get_option('cargonizer-parcel-length'), 'parcel_width' => get_option('cargonizer-parcel-width') @@ -182,7 +182,12 @@ function getTotalWeight(){ } } - if ( $weight ){ + + if ( $weight && get_option( 'woocommerce_weight_unit', 'kg' ) == 'g' ){ + $weight /= 1000; + } + + if ( $weight ){ $weight = number_format($weight, 2, '.', ' '); } @@ -206,12 +211,23 @@ function getPrintOnExport(){ function getCarrierId(){ - return gi($this->Meta, 'parcel_carrier_id'); + $carrier_id = gi($this->Meta, 'parcel_carrier_id'); + if( !$carrier_id ){ + $carrier_id = get_option( 'cargonizer-carrier-id' ); + } + + return $carrier_id; } function getCarrierProduct(){ - return gi($this->Meta, 'parcel_carrier_product'); + $carrier_product = gi($this->Meta, 'parcel_carrier_product'); + + if ( !$carrier_product ){ + $carrier_product = get_option( 'cargonizer-default-carrier-product' ); + } + + return $carrier_product; } @@ -373,7 +389,14 @@ function hasFutureShippingDate(){ function getParcelType(){ - return gi($this->Meta, 'parcel_carrier_product_type'); + $product_type = gi($this->Meta, 'parcel_carrier_product_type'); + + if (!$product_type){ + $product_type = get_option( 'cargonizer-default-product-type' ); + } + + + return $product_type; //_log($this->Printer); } @@ -488,7 +511,7 @@ function reset(){ function isReady( $force = false ){ - _log('ShopOrder::isReady()'); + _log('ShopOrder::isReady('.$force.')'); $is_ready = false; // if parcel is not exported / cargonized if ( !gi($this->Meta, 'is_cargonized') or $force ){ @@ -508,7 +531,7 @@ function isReady( $force = false ){ if ( $this->CarrierId && $this->CarrierProduct && $this->ParcelPackages ){ // checkbox create_consignment is on - if ( gi($_POST, 'parcel_create_consignment_now') ){ + if ( gi($_POST, 'parcel_create_consignment_now') or $force ){ $is_ready = true; } else{ diff --git a/include/controllers/CargonizerCommonController.php b/include/controllers/CargonizerCommonController.php index 6c405ea..bda7b91 100644 --- a/include/controllers/CargonizerCommonController.php +++ b/include/controllers/CargonizerCommonController.php @@ -47,8 +47,12 @@ function setCustomProvider($args){ } - function isOrder( $object=true ){ - global $post; + function isOrder( $post_id, $object=true ){ + // global $post; + $post = new StdClass(); + if ( is_numeric($post_id) ){ + $post = get_post($post_id); + } if ( isset($post->post_type) && $post->post_type == 'shop_order' ){ if ( $object ){ diff --git a/include/controllers/ShopOrderController.php b/include/controllers/ShopOrderController.php index 324f3de..407eea2 100644 --- a/include/controllers/ShopOrderController.php +++ b/include/controllers/ShopOrderController.php @@ -13,6 +13,27 @@ 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' ) ); + } + + + 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 filterBulkActions($actions){ + $actions['create_consignment'] = __('Create consignment', 'wc-cargonizer'); + + return $actions; } @@ -25,7 +46,7 @@ public static function saveServicePartner( $post_id, $post){ update_post_meta( $post_id, $index, gi($_REQUEST, $index ) ); _log('copied: '.$index); } - } + } } } @@ -66,13 +87,13 @@ function saveConsignmentSettgings( $post_id ){ } - function saveConsignment( $post_id ){ + function saveConsignment( $post_id, $force=false, $create=true ){ if ( !isset($_REQUEST['post_ID']) or $_REQUEST['post_ID'] != $post_id ){ return false; } - if ( $Order = $this->isOrder( $return_object=true ) ){ - _log('ShopOrderController::saveConsignment()'); + if ( $Order = $this->isOrder( $post_id, $return_object=true ) ){ + // _log('ShopOrderController::saveConsignment()'); $consignment_post_id = null; $is_future = ($Order->hasFutureShippingDate()) ? true : false; @@ -80,12 +101,14 @@ function saveConsignment( $post_id ){ $consignment_post_id = Consignment::createOrUpdate( $Order, $recurring=false ); } - if ( $Order->isReady($force=false) && !$is_future ){ + if ( $Order->isReady($force) && !$is_future ){ _log('... is ready'); if ( $cid = Consignment::createOrUpdate( $Order, $recurring=false ) ){ _log('consignment created/updated: '.$cid); - _log('create consignment now'); - $result = ConsignmentController::createConsignment($cid); + if ( $create ){ + _log('create consignment now'); + $result = ConsignmentController::createConsignment($cid); + } } } else{ diff --git a/woocommerce-cargonizer.php b/woocommerce-cargonizer.php index 44c1bd6..fdfc8c0 100644 --- a/woocommerce-cargonizer.php +++ b/woocommerce-cargonizer.php @@ -2,7 +2,7 @@ /*woo Plugin Name: Woocommerce Cargonizer Description: -Version: 0.4.2 +Version: 0.4.5 Author: Mediebruket AS Author URI: http://mediebruket.no */ @@ -49,4 +49,4 @@ function wcc_textdomain() { load_plugin_textdomain( 'wc-cargonizer', false, dirname( plugin_basename(__FILE__) ) . '/languages/' ); } -add_action('plugins_loaded', 'wcc_textdomain'); \ No newline at end of file +add_action('plugins_loaded', 'wcc_textdomain');