Skip to content

Commit

Permalink
vesion 0.4.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dmattke committed Jan 22, 2018
1 parent 801411b commit 2328a3b
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 23 deletions.
10 changes: 5 additions & 5 deletions admin/CargonizerAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -214,9 +214,9 @@ function registerFrontendScripts(){

foreach ($styles as $s) {
echo '<link rel="stylesheet" href="'.$path .'css/'.$s.'" type="text/css" />' . "\n";
}
}
}

}


Expand Down Expand Up @@ -274,7 +274,7 @@ function registerScripts(){
wp_enqueue_script( 'tableedit-js' );

}

}


Expand Down Expand Up @@ -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 '<div class="wcc-meta-box-consignment">';

Expand Down
6 changes: 6 additions & 0 deletions include/Consignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
37 changes: 30 additions & 7 deletions include/ShopOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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, '.', ' ');
}

Expand All @@ -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;
}


Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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 ){
Expand All @@ -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{
Expand Down
8 changes: 6 additions & 2 deletions include/controllers/CargonizerCommonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ){
Expand Down
37 changes: 30 additions & 7 deletions include/controllers/ShopOrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -25,7 +46,7 @@ public static function saveServicePartner( $post_id, $post){
update_post_meta( $post_id, $index, gi($_REQUEST, $index ) );
_log('copied: '.$index);
}
}
}
}
}

Expand Down Expand Up @@ -66,26 +87,28 @@ 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;

if ( $is_future ){
$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{
Expand Down
4 changes: 2 additions & 2 deletions 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.2
Version: 0.4.5
Author: Mediebruket AS
Author URI: http://mediebruket.no
*/
Expand Down Expand Up @@ -49,4 +49,4 @@
function wcc_textdomain() {
load_plugin_textdomain( 'wc-cargonizer', false, dirname( plugin_basename(__FILE__) ) . '/languages/' );
}
add_action('plugins_loaded', 'wcc_textdomain');
add_action('plugins_loaded', 'wcc_textdomain');

0 comments on commit 2328a3b

Please sign in to comment.