Skip to content

Commit

Permalink
Merge from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Nov 11, 2024
2 parents e02b60d + 94fff3d commit 26f6e29
Show file tree
Hide file tree
Showing 43 changed files with 572 additions and 106 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ composer.lock
/packages/*
!/packages/README.md
/composer.lock
.phpunit.result.cache
6 changes: 6 additions & 0 deletions assets/css/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ tbody.packaging_list {
border-radius: 3px;
display: inline-flex;
white-space: nowrap;
max-width: 100%;

&.status-draft, &.status-processing, &.status-requested, &.status-partially-shipped, &.status-partially-delivered, &.status-open, &.status-partially-returned {
background: #f8dda7;
Expand All @@ -691,6 +692,11 @@ tbody.packaging_list {
background: #f8dda7;
color: #94660c;
}

> span {
overflow: hidden;
text-overflow: ellipsis;
}
}

a.button.wc-stc-shipment-action-button {
Expand Down
3 changes: 2 additions & 1 deletion assets/js/blocks/checkout-pickup-location-select/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
import './slotfills/pickup-location-select';
import './slotfills/pickup-location-select';
import './set-payment-method';
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { registerPlugin } from "@wordpress/plugins";
import { useEffect, useState, useCallback, useRef } from '@wordpress/element';
import { useSelect } from '@wordpress/data';
import { extensionCartUpdate } from '@woocommerce/blocks-checkout';
import _ from 'lodash';
import { PAYMENT_STORE_KEY } from '@woocommerce/block-data';

const render = () => {
const {
currentPaymentMethod
} = useSelect( ( select ) => {
const paymentStore = select( PAYMENT_STORE_KEY );

return {
currentPaymentMethod: paymentStore.getActivePaymentMethod(),
}
} );

useEffect( () => {
if ( currentPaymentMethod ) {
extensionCartUpdate( {
namespace: 'woocommerce-shiptastic-set-payment-method',
data: {
'active_method': currentPaymentMethod,
},
} );
}
}, [
currentPaymentMethod
] );

return null;
};

registerPlugin( 'woocommerce-shiptastic-set-payment-method', {
render,
scope: 'woocommerce-checkout',
} );
2 changes: 0 additions & 2 deletions assets/js/static/admin-shipment.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ window.shiptastic.admin = window.shiptastic.admin || {};
};

this.onAddItemSuccess = function( data ) {
this.getShipmentContent().find( '.shipment-item-list' ).append( data.new_item );

this.refreshDom();
this.unblockItems();
};
Expand Down
2 changes: 1 addition & 1 deletion assets/js/static/admin-shipments-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ window.shiptastic.admin = window.shiptastic.admin || {};
});

if ( self.params.bulk_actions.hasOwnProperty( action ) && ids.length > 0 ) {

var actionData = self.params.bulk_actions[ action ];

$( '.bulk-action-wrapper' ).find( '.bulk-title' ).text( actionData['title'] );
Expand All @@ -63,6 +62,7 @@ window.shiptastic.admin = window.shiptastic.admin || {};
bulk_action : action,
step : step,
type : type,
referer : window.location.href,
ids : ids,
security : actionData['nonce']
},
Expand Down
3 changes: 2 additions & 1 deletion assets/js/static/admin-shipping-provider-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ window.shiptastic.admin = window.shiptastic.admin || {};
.on( 'change', 'select[id$=shipping_provider]', self.showOrHideAll )
.on( 'click', '.wc-stc-shipping-provider-method-tabs .nav-tab-wrapper a.nav-tab', self.onChangeTab )
.on( 'change', '.override-checkbox :input', self.onChangeOverride )
.on( 'change', '.wc-gzd-shipping-provider-method-tab-content :input[id]', self.onChangeInput );
.on( 'change', '.wc-stc-shipping-provider-method-tab-content :input[id]', self.onChangeInput );

$( document.body ).on( 'wc_backbone_modal_loaded', self.onShippingMethodOpen );

Expand Down Expand Up @@ -65,6 +65,7 @@ window.shiptastic.admin = window.shiptastic.admin || {};
if ( $tab.length > 0 ) {
$navTab.addClass( 'nav-tab-active' );
$tab.addClass( 'tab-content-active' );

$tab.find( ':input:visible' ).trigger( 'change' );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
?>
<tbody id="wc-stc-return-shipment-items" data-row="">
<?php
foreach ( $order_shipment->get_available_items_for_return() as $item_id => $item_data ) :
foreach ( $order_shipment->get_selectable_items_for_return() as $item_id => $item_data ) :
?>
<tr>
<td><?php echo esc_attr( $item_data['name'] ); ?></td>
Expand Down
9 changes: 7 additions & 2 deletions includes/admin/views/html-order-shipment-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,13 @@

if ( $shipment->supports_label() && ( ( $label = $shipment->get_label() ) || $shipment->needs_label() ) ) :
include 'label/html-shipment-label.php';
endif;
?>
elseif ( $shipment->get_tracking_url() ) :
?>
<div class="wc-stc-shipment-tracking wc-stc-shipment-action-wrapper column col-auto column-spaced show-if show-if-provider show-if-provider-<?php echo esc_attr( $shipment->get_shipping_provider() ); ?>" data-shipment="<?php echo esc_attr( $shipment->get_id() ); ?>">
<h4><?php echo esc_html_x( 'Track & Trace', 'shipments', 'shiptastic-for-woocommerce' ); ?></h4>
<a class="button button-secondary" aria-label="<?php echo esc_attr( $shipment->get_tracking_id() ); ?>" href="<?php echo esc_url( $shipment->get_tracking_url() ); ?>" target="_blank"><?php echo esc_html( $shipment->get_tracking_id() ); ?></a>
</div>
<?php endif; ?>
</div>
</div>
<div class="column col-6">
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/views/html-order-shipment-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<div class="panel-title panel-title-inner title-spread panel-inner panel-order-return-title <?php echo ( empty( $returns ) ? 'hide-default' : '' ); ?>">
<h2 class="order-returns-title"><?php echo esc_html_x( 'Returns', 'shipments', 'shiptastic-for-woocommerce' ); ?></h2>
<span class="order-return-status status-<?php echo esc_attr( $order_shipment->get_return_status() ); ?>"><?php echo esc_html( wc_stc_get_shipment_order_return_status_name( $order_shipment->get_return_status() ) ); ?></span>
<mark class="order-return-status status-<?php echo esc_attr( $order_shipment->get_return_status() ); ?>"><span><?php echo esc_html( wc_stc_get_shipment_order_return_status_name( $order_shipment->get_return_status() ) ); ?></span></mark>
</div>

<?php if ( ! empty( $returns ) ) : ?>
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/views/html-order-shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="shipment-header title-spread">
<div class="left">
<h3><?php printf( esc_html_x( '%1$s #%2$s', 'shipment admin title', 'shiptastic-for-woocommerce' ), esc_html( wc_stc_get_shipment_label_title( $shipment->get_type() ) ), esc_html( $shipment->get_shipment_number() ) ); ?></h3>
<span class="shipment-status shipment-type-<?php echo esc_attr( $shipment->get_type() ); ?>-status status-<?php echo esc_attr( $shipment->get_status() ); ?>"><?php echo esc_html( wc_stc_get_shipment_status_name( $shipment->get_status() ) ); ?></span>
<mark class="shipment-status shipment-type-<?php echo esc_attr( $shipment->get_type() ); ?>-status status-<?php echo esc_attr( $shipment->get_status() ); ?>"><span><?php echo esc_html( wc_stc_get_shipment_status_name( $shipment->get_status() ) ); ?></span></mark>
</div>

<div class="right">
Expand Down
2 changes: 1 addition & 1 deletion includes/admin/views/html-order-shipments.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<div class="panel-title title-spread panel-inner">
<h2 class="order-shipments-title"><?php echo esc_html_x( 'Shipments', 'shipments', 'shiptastic-for-woocommerce' ); ?></h2>
<span class="order-shipping-status status-<?php echo esc_attr( $order_shipment->get_shipping_status() ); ?>"><?php echo esc_html( wc_stc_get_shipment_order_shipping_status_name( $order_shipment->get_shipping_status() ) ); ?></span>
<mark class="order-shipping-status status-<?php echo esc_attr( $order_shipment->get_shipping_status() ); ?>"><span><?php echo esc_html( wc_stc_get_shipment_order_shipping_status_name( $order_shipment->get_shipping_status() ) ); ?></span></mark>
</div>

<div class="notice-wrapper panel-inner"></div>
Expand Down
2 changes: 1 addition & 1 deletion src/Admin/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ public static function render_order_columns( $column, $post_id ) {

if ( $shipment_order = wc_stc_get_shipment_order( $the_order ) ) {
$shipping_status = $shipment_order->get_shipping_status();
$status_html = '<span class="order-shipping-status status-' . esc_attr( $shipping_status ) . '">' . esc_html( wc_stc_get_shipment_order_shipping_status_name( $shipping_status ) ) . '</span>';
$status_html = '<mark class="order-shipping-status status-' . esc_attr( $shipping_status ) . '"><span>' . esc_html( wc_stc_get_shipment_order_shipping_status_name( $shipping_status ) ) . '</span></mark>';

if ( in_array( $shipping_status, array( 'shipped', 'partially-shipped' ), true ) && $shipment_order->get_shipments() ) {
if ( $last_shipment = $shipment_order->get_last_shipment_with_tracking() ) {
Expand Down
13 changes: 11 additions & 2 deletions src/Admin/BulkActionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,23 @@ public function set_shipment_type( $type ) {
$this->type = $type;
}

public function get_success_redirect_url() {
public function get_success_redirect_url( $referer = false ) {
$page = 'wc-shiptastic';

if ( 'simple' !== $this->get_shipment_type() ) {
$page = 'wc-stc-' . $this->get_shipment_type() . '-shipments';
}

return admin_url( 'admin.php?page=' . $page . '&bulk_action_handling=finished&current_bulk_action=' . sanitize_key( $this->get_action() ) );
$base_url = $referer ? $referer : admin_url( 'admin.php?page=' . $page );
$base_url = add_query_arg(
array(
'bulk_action_handling' => 'finished',
'current_bulk_action' => sanitize_key( $this->get_action() ),
),
$base_url
);

return esc_url_raw( $base_url );
}

public function get_step() {
Expand Down
8 changes: 5 additions & 3 deletions src/Admin/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,15 @@ protected function get_views() {
/**
* Helper to create links to edit.php with params.
*
*
* @param string[] $args Associative array of URL parameters for the link.
* @param string $label Link text.
* @param string $class_name Optional. Class attribute. Default empty string.
*
* @return string The formatted link string.
*@since 4.4.0
*
*/

protected function get_edit_link( $args, $label, $class_name = '' ) {
$url = add_query_arg( $args, $this->get_main_page() );

Expand Down Expand Up @@ -1054,7 +1056,7 @@ public function column_address( $shipment ) {
* @param Shipment $shipment The current shipment object.
*/
public function column_status( $shipment ) {
echo '<span class="shipment-status shipment-type-' . esc_attr( $shipment->get_type() ) . '-status status-' . esc_attr( $shipment->get_status() ) . '">' . esc_html( wc_stc_get_shipment_status_name( $shipment->get_status() ) ) . '</span>';
echo '<mark class="shipment-status shipment-type-' . esc_attr( $shipment->get_type() ) . '-status status-' . esc_attr( $shipment->get_status() ) . '"><span>' . esc_html( wc_stc_get_shipment_status_name( $shipment->get_status() ) ) . '</span></mark>';
}

/**
Expand Down Expand Up @@ -1166,7 +1168,7 @@ protected function get_custom_bulk_actions( $actions ) {
protected function get_hook_prefix() {
$suffix = ( 'simple' === $this->shipment_type ? '' : '_' . $this->shipment_type );

return "woocommerce_gzd{$suffix}_shipments_table_";
return "woocommerce_shiptastic{$suffix}_shipments_table_";
}

/**
Expand Down
27 changes: 15 additions & 12 deletions src/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -521,8 +521,9 @@ public static function sort_shipping_provider() {
}

public static function shipments_bulk_action_handle() {
$action = isset( $_POST['bulk_action'] ) ? wc_clean( wp_unslash( $_POST['bulk_action'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$type = isset( $_POST['type'] ) ? wc_clean( wp_unslash( $_POST['type'] ) ) : 'simple'; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$action = isset( $_POST['bulk_action'] ) ? wc_clean( wp_unslash( $_POST['bulk_action'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$type = isset( $_POST['type'] ) ? wc_clean( wp_unslash( $_POST['type'] ) ) : 'simple'; // phpcs:ignore WordPress.Security.NonceVerification.Missing
$referer = isset( $_POST['referer'] ) ? wp_sanitize_redirect( wp_unslash( $_POST['referer'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Missing

check_ajax_referer( "woocommerce_shiptastic_{$action}", 'security' );

Expand Down Expand Up @@ -573,7 +574,7 @@ public static function shipments_bulk_action_handle() {
array(
'step' => 'done',
'percentage' => 100,
'url' => $handler->get_success_redirect_url(),
'url' => $handler->get_success_redirect_url( $referer ),
'type' => $handler->get_shipment_type(),
)
);
Expand Down Expand Up @@ -1028,7 +1029,7 @@ public static function json_search_orders() {
}

private static function get_order_status_html( $order_shipment ) {
$status_html = '<span class="order-shipping-status status-' . esc_attr( $order_shipment->get_shipping_status() ) . '">' . wc_stc_get_shipment_order_shipping_status_name( $order_shipment->get_shipping_status() ) . '</span>';
$status_html = '<mark class="order-shipping-status status-' . esc_attr( $order_shipment->get_shipping_status() ) . '"><span>' . wc_stc_get_shipment_order_shipping_status_name( $order_shipment->get_shipping_status() ) . '</span></mark>';

return $status_html;
}
Expand Down Expand Up @@ -1090,7 +1091,7 @@ private static function get_global_order_status_html( $order ) {
}

private static function get_order_return_status_html( $order_shipment ) {
$status_html = '<span class="order-return-status status-' . esc_attr( $order_shipment->get_return_status() ) . '">' . wc_stc_get_shipment_order_return_status_name( $order_shipment->get_return_status() ) . '</span>';
$status_html = '<mark class="order-return-status status-' . esc_attr( $order_shipment->get_return_status() ) . '"><span>' . wc_stc_get_shipment_order_return_status_name( $order_shipment->get_return_status() ) . '</span></mark>';

return $status_html;
}
Expand Down Expand Up @@ -1287,14 +1288,14 @@ public static function add_shipment_item_load() {
$items = array();

if ( 'return' === $shipment->get_type() ) {
$items = $order_shipment->get_available_items_for_return(
$items = $order_shipment->get_selectable_items_for_return(
array(
'shipment_id' => $shipment->get_id(),
'disable_duplicates' => true,
)
);
} else {
$items = $order_shipment->get_available_items_for_shipment(
$items = $order_shipment->get_selectable_items_for_shipment(
array(
'shipment_id' => $shipment_id,
'disable_duplicates' => true,
Expand Down Expand Up @@ -1322,9 +1323,8 @@ public static function add_shipment_item_submit() {
);

$response = array(
'success' => true,
'message' => '',
'new_item' => '',
'success' => true,
'message' => '',
);

$shipment_id = absint( $_POST['reference_id'] );
Expand Down Expand Up @@ -1367,10 +1367,13 @@ public static function add_shipment_item_submit() {
}

ob_start();
include Package::get_path() . '/includes/admin/views/html-order-shipment-item.php';
$response['new_item'] = ob_get_clean();
foreach ( $shipment->get_items() as $item ) {
include Package::get_path() . '/includes/admin/views/html-order-shipment-item.php';
}
$html = ob_get_clean();

$response['fragments'] = array(
'#shipment-' . $shipment->get_id() . ' .shipment-item-list:first' => '<div class="shipment-item-list">' . $html . '</div>',
'#shipment-' . $shipment->get_id() . ' .item-count:first' => self::get_item_count_html( $shipment, $order_shipment ),
);

Expand Down
11 changes: 11 additions & 0 deletions src/Blocks/Checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,17 @@ private function register_endpoint_data() {
},
)
);

woocommerce_store_api_register_update_callback(
array(
'namespace' => 'woocommerce-shiptastic-set-payment-method',
'callback' => function ( $data ) {
$active_method = isset( $data['active_method'] ) ? wc_clean( wp_unslash( $data['active_method'] ) ) : '';

WC()->session->set( 'wc_shiptastic_blocks_chosen_payment_method', $active_method );
},
)
);
}

private function get_checkout_schema() {
Expand Down
4 changes: 2 additions & 2 deletions src/Blocks/StoreApi/RoutesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function get( $name, $version = 'v1' ) {
/**
* Register defined list of routes with WordPress.
*
* @param string $version API Version being registered..
* @param string $namespace Overrides the default route namespace.
* @param string $version API Version being registered.
* @param string $ns Overrides the default route namespace.
*/
protected function register_routes( $version = 'v1', $namespace = 'wc/store/v1' ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound
if ( ! isset( $this->routes[ $version ] ) ) {
Expand Down
Loading

0 comments on commit 26f6e29

Please sign in to comment.