Skip to content

Commit

Permalink
Merge pull request #92 from awsmug/release/1.2.1
Browse files Browse the repository at this point in the history
Release/1.2.1
  • Loading branch information
mahype committed Jun 6, 2017
2 parents ec916c6 + 9485428 commit b7b1734
Show file tree
Hide file tree
Showing 23 changed files with 1,004 additions and 1,031 deletions.
8 changes: 7 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: mahype, awesome-ug
Tags: woocommerce, shipcloud
Requires at least: 3.0.0
Tested up to: 4.3.0
Stable tag: 1.2.0
Stable tag: 1.2.1

This plugin integrates shipcloud.io into WooCommerce.

Expand All @@ -23,6 +23,12 @@ Integrate your shipcloid.io account to your WooCommerce shop. Create shipment la

== Changelog ==

= 1.2.1 =
* Enhanced: Added missing translations
* Enhanced: Removed Woo Updatescripts
* Enhanced: Refactored Code
* Fixed: Zip code and street did not no matched between API and plugin

= 1.2.0 =
* Enhanced: Added bulk label creation
* Enhanced: Added shipment description
Expand Down
7 changes: 7 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
*** WooCommerce Shipcloud Changelog ***


2017.06.06 - version 1.2.1
* Enhanced: Added missing translations
* Enhanced: Removed Woo Updatescripts
* Enhanced: Refactored Code
* Fixed: Zip code and street did not no matched between API and plugin

2017.05.12 - version 1.2.0
* Enhanced: Added bulk label creation
* Enhanced: Added shipment description
Expand Down
14 changes: 0 additions & 14 deletions components/block/order-labels-bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,6 @@ class="inline-edit-row inline-edit-row-page inline-edit-shop_order bulk-edit-row
</tbody>
</table>

<script type="application/javascript">
jQuery(function ($) {
$('#wcsc_template').change(function () {
var data = $(':selected', this).data();
console.log(data);
for (var key in data) {
$('input[name=wcsc_' + key + ']').val(data[key]);
}

$('select[name=wcsc_carrier]').val(data['carrier']);
});
});
</script>

<script type="template/html" id="tmpl-wcsc-order-labels-bulk-items">
<div data-id="{{ data.id }}"
class="bulk-title">
Expand Down
36 changes: 36 additions & 0 deletions components/block/order-parcel-templates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php /** @var WC_Shipcloud_Order $this */ ?>
<div class="parcel-templates fifty">

<div class="parcel-template-field parcels-recommended">
<label for="parcels_recommended"><?php _e( 'Automatic determined Parcels', 'woocommerce-shipcloud' ); ?></label>
<?php if ( count( $determined_parcels ) > 0 ) : ?>
<input type="button" value="<?php _e( '&#8592; Insert', 'woocommerce-shipcloud' ); ?>" class="insert-to-form button"/>
<select name="parcel_list">
<option value="none"><?php _e( '[ Select a Parcel ]', 'woocommerce-shipcloud' ); ?></option>

<?php foreach ( $determined_parcels AS $determined_parcel ): ?>
<option value="<?php echo $determined_parcel[ 'value' ]; ?>"><?php echo $determined_parcel[ 'option' ]; ?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
<p><?php _e( 'Please add weight and parcel dimensions in your Products to use automatic calculations.', 'woocommerce-shipcloud' ); ?></p>
<?php endif; ?>
</div>

<div class="parcel-template-field parcels-templates">
<label for="parcel_templates"><?php _e( 'Your Parcel Templates', 'woocommerce-shipcloud' ); ?></label>
<?php if ( count( $parcel_templates ) > 0 ) : ?>
<input type="button" value="<?php _e( '&#8592; Insert', 'woocommerce-shipcloud' ); ?>" class="insert-to-form button"/>
<select name="parcel_list">
<option value="none"><?php _e( '[ Select a Parcel ]', 'woocommerce-shipcloud' ); ?></option>

<?php foreach ( $parcel_templates AS $parcel_template ): ?>
<option value="<?php echo $parcel_template[ 'value' ]; ?>"><?php echo $parcel_template[ 'option' ]; ?></option>
<?php endforeach; ?>
</select>
<?php else: ?>
<p><?php echo sprintf( __( 'Please <a href="%s">add parcel templates</a> if you want to use.', 'woocommerce-shipcloud' ), admin_url( 'edit.php?post_type=sc_parcel_template' ) ); ?></p>
<?php endif; ?>
</div>

</div>
210 changes: 210 additions & 0 deletions components/woo/order-bulk.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
<?php
/**
* WooCommerce shipcloud.io postboxes
* Loading postboxes
*
* @author awesome.ug <support@awesome.ug>, Sven Wagener <sven@awesome.ug>
* @package WooCommerceShipCloud/Woo
* @version 1.0.0
* @since 1.2.1
* @license GPL 2
* Copyright 2017 (support@awesome.ug)
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

/**
* Class WC_Shipcloud_Order_Bulk
*
* Bulk functionalities for Label creation
*
* @since 1.2.1
*/
class WC_Shipcloud_Order_Bulk {
/**
* WC_Shipcloud_Order_Bulk constructor.
*
* @since 1.2.1
*/
public function __construct() {
$this->init_hooks();
}

/**
* Initializing hooks and filters
*
* @since 1.2.1
*/
private function init_hooks() {
add_action( 'admin_print_footer_scripts', array( $this, 'admin_print_footer_scripts' ) );
add_action( 'load-edit.php', array( $this, 'load_edit' ) );

add_filter( 'bulk_actions-edit-shop_order', array( $this, 'add_bulk_actions' ) );
add_action( 'load-edit.php', array( $this, 'handle_wcsc_order_bulk' ) );
}

/**
* Handling Submit after bulk action
*
* @since 1.2.1
*/
public function handle_wcsc_order_bulk() {
if ( ! is_admin() || ! get_current_screen() || 'edit-shop_order' !== get_current_screen()->id ) {
// None of our business.
return;
}

$request = $_GET; // XSS: OK.

if ( 'wcsc_order_bulk_label' !== $request['action']
|| ! isset( $request['action'], $request['wcsc_carrier'] )
|| ! $request['wcsc_carrier']
) {
return;
}

$package = array(
'width' => $request['wcsc_width'],
'height' => $request['wcsc_height'],
'length' => $request['wcsc_length'],
'weight' => $request['wcsc_weight'],
);

$succeeded = 0;
foreach ( $request['post'] as $order_id ) {
$order = WC_Shipcloud_Order::create_order( $order_id );

$shipment = wcsc_api()->create_shipment_by_order(
$order,
$request['wcsc_carrier'],
$package
);

if ( is_wp_error( $shipment ) ) {
/** @var \WP_Error $shipment */
WC_Shipcloud_Shipping::log(
'Order #' . $order->get_wc_order()->get_order_number()
. ' - ' . $shipment->get_error_message()
. ' (' . wcsc_get_carrier_display_name( $request['carrier'] ) . ')'
);

WooCommerce_Shipcloud::admin_notice(
sprintf(
__( 'No label for order #%d created: %s' ),
$order->get_wc_order()->get_id(),
str_replace( "\n", ', ', $shipment->get_error_message() )
),
'error'
);

continue;
}

WC_Shipcloud_Shipping::log( 'Order #' . $order->get_wc_order()->get_order_number() . ' - Created shipment successful (' . wcsc_get_carrier_display_name( $request['carrier'] ) . ')' );

$parcel_title = wcsc_get_carrier_display_name( $request['wcsc_carrier'] )
. ' - '
. $request['wcsc_width']
. __( 'x', 'woocommerce-shipcloud' )
. $request['wcsc_height']
. __( 'x', 'woocommerce-shipcloud' )
. $request['wcsc_length']
. __( 'cm', 'woocommerce-shipcloud' )
. ' '
. $request['wcsc_weight']
. __( 'kg', 'woocommerce-shipcloud' );

$data = array(
'id' => $shipment['id'],
'carrier_tracking_no' => $shipment['carrier_tracking_no'],
'tracking_url' => $shipment['tracking_url'],
'label_url' => $shipment['label_url'],
'price' => $shipment['price'],
'parcel_id' => $shipment['id'],
'parcel_title' => $parcel_title,
'carrier' => $request['carrier'],
'width' => $request['width'],
'height' => $request['height'],
'length' => $request['length'],
'weight' => $request['weight'],
'description' => $request['description'],
'date_created' => time(),
);

$data = array_merge( $data, $order->get_sender( 'sender_' ) );
$data = array_merge( $data, $order->get_recipient( 'recipient_' ) );

add_post_meta( $order_id, 'shipcloud_shipment_ids', $data['id'] );
add_post_meta( $order_id, 'shipcloud_shipment_data', $data );

$order->get_wc_order()->add_order_note( __( 'shipcloud.io label was created.', 'woocommerce-shipcloud' ) );

$succeeded ++;
}

WooCommerce_Shipcloud::admin_notice(
sprintf( 'Created %d labels.', $succeeded ), 'updated'
);
}

/**
* Adding bulk action to dropdown
*
* @since 1.2.1
*
* @param array $actions Bulk actions
*
* @return array $actions Bulk actions with own Actions
*/
public function add_bulk_actions( $actions ) {
$actions['wcsc_order_bulk_label'] = __( 'Create shipping labels', 'woocommerce-shipcloud' );

return $actions;
}

/**
* Adding Footer Scripts
*
* @since 1.2.1
*/
public function admin_print_footer_scripts() {
require_once WCSC_FOLDER . '/includes/shipcloud/block-order-labels-bulk.php';

$block = new WooCommerce_Shipcloud_Block_Order_Labels_Bulk(
WCSC_COMPONENTFOLDER . '/block/order-labels-bulk.php',
wcsc_shipping_method()->get_allowed_carriers(),
new Woocommerce_Shipcloud_API()
);

$block->dispatch();
}

/**
* Loading Scripts
*
* @since 1.2.1
*/
public function load_edit() {
wp_register_script(
'wcsc_bulk_order_label',
WCSC_URLPATH . '/includes/js/bulk-order-label.js',
array( 'jquery' )
);

wp_enqueue_script( 'wcsc_bulk_order_label', false, array(), false, true );
}
}

$wc_shipcloud_order_bulk = new WC_Shipcloud_Order_Bulk();
Loading

0 comments on commit b7b1734

Please sign in to comment.