mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
Merge pull request #1050 from woocommerce/PCP-1015-sync-GZD-tracking-only-if-status-is-shipped
Sync GZD shipment only if status is changed to "shipped"
This commit is contained in:
commit
b9fdd7535b
2 changed files with 6 additions and 20 deletions
|
@ -56,15 +56,6 @@ return array(
|
|||
return function_exists( 'wc_gzd_get_shipments_by_order' ); // 3.0+
|
||||
},
|
||||
|
||||
'compat.gzd.tracking_statuses_map' => function ( ContainerInterface $container ): array {
|
||||
return array(
|
||||
'draft' => 'ON_HOLD',
|
||||
'processing' => 'SHIPPED',
|
||||
'shipped' => 'SHIPPED',
|
||||
'delivered' => 'DELIVERED',
|
||||
);
|
||||
},
|
||||
|
||||
'compat.module.url' => static function ( ContainerInterface $container ): string {
|
||||
/**
|
||||
* The path cannot be false.
|
||||
|
|
|
@ -130,20 +130,13 @@ class CompatModule implements ModuleInterface {
|
|||
$logger = $c->get( 'woocommerce.logger.woocommerce' );
|
||||
assert( $logger instanceof LoggerInterface );
|
||||
|
||||
$status_map = $c->get( 'compat.gzd.tracking_statuses_map' );
|
||||
|
||||
add_action(
|
||||
'woocommerce_gzd_shipment_after_save',
|
||||
static function( Shipment $shipment ) use ( $endpoint, $logger, $status_map ) {
|
||||
'woocommerce_gzd_shipment_status_shipped',
|
||||
static function( int $shipment_id, Shipment $shipment ) use ( $endpoint, $logger ) {
|
||||
if ( ! apply_filters( 'woocommerce_paypal_payments_sync_gzd_tracking', true ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$gzd_shipment_status = $shipment->get_status();
|
||||
if ( ! array_key_exists( $gzd_shipment_status, $status_map ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$wc_order = $shipment->get_order();
|
||||
if ( ! is_a( $wc_order, WC_Order::class ) ) {
|
||||
return;
|
||||
|
@ -156,7 +149,7 @@ class CompatModule implements ModuleInterface {
|
|||
|
||||
$tracking_data = array(
|
||||
'transaction_id' => $transaction_id,
|
||||
'status' => (string) $status_map[ $gzd_shipment_status ],
|
||||
'status' => 'SHIPPED',
|
||||
);
|
||||
|
||||
$provider = $shipment->get_shipping_provider();
|
||||
|
@ -177,7 +170,9 @@ class CompatModule implements ModuleInterface {
|
|||
} catch ( Exception $exception ) {
|
||||
$logger->error( "Couldn't sync tracking information: " . $exception->getMessage() );
|
||||
}
|
||||
}
|
||||
},
|
||||
500,
|
||||
2
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue