mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Create services for GZD compat layer
This commit is contained in:
parent
92bdb977f9
commit
561974c3b5
1 changed files with 65 additions and 4 deletions
|
@ -10,6 +10,8 @@ declare(strict_types=1);
|
||||||
namespace WooCommerce\PayPalCommerce\Compat;
|
namespace WooCommerce\PayPalCommerce\Compat;
|
||||||
|
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
|
use WooCommerce\PayPalCommerce\Compat\Assets\CompatAssets;
|
||||||
|
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
|
|
||||||
|
@ -50,4 +52,63 @@ return array(
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'compat.gzd.is_supported_plugin_version_active' => function (): bool {
|
||||||
|
return function_exists( 'wc_gzd_get_shipments_by_order' ); // 3.0+
|
||||||
|
},
|
||||||
|
|
||||||
|
'compat.gzd.tracking_statuses_map' => function ( ContainerInterface $container ): array {
|
||||||
|
$gzd_statuses = wc_gzd_get_shipment_statuses() ?? array();
|
||||||
|
$status_map = array();
|
||||||
|
|
||||||
|
foreach ( $gzd_statuses as $gzd_status ) {
|
||||||
|
$gzd_status = strtolower( $gzd_status );
|
||||||
|
switch ( $gzd_status ) {
|
||||||
|
case 'draft':
|
||||||
|
$status_map[ $gzd_status ] = 'ON_HOLD';
|
||||||
|
break;
|
||||||
|
case 'processing':
|
||||||
|
case 'shipped':
|
||||||
|
$status_map[ $gzd_status ] = 'SHIPPED';
|
||||||
|
break;
|
||||||
|
case 'delivered':
|
||||||
|
$status_map[ $gzd_status ] = 'DELIVERED';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $status_map;
|
||||||
|
},
|
||||||
|
|
||||||
|
'compat.module.url' => static function ( ContainerInterface $container ): string {
|
||||||
|
/**
|
||||||
|
* The path cannot be false.
|
||||||
|
*
|
||||||
|
* @psalm-suppress PossiblyFalseArgument
|
||||||
|
*/
|
||||||
|
return plugins_url(
|
||||||
|
'/modules/ppcp-compat/',
|
||||||
|
dirname( realpath( __FILE__ ), 3 ) . '/woocommerce-paypal-payments.php'
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
'compat.assets' => function( ContainerInterface $container ) : CompatAssets {
|
||||||
|
return new CompatAssets(
|
||||||
|
$container->get( 'compat.module.url' ),
|
||||||
|
$container->get( 'ppcp.asset-version' ),
|
||||||
|
$container->get( 'compat.should-initialize-gzd-compat-layer' )
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
'compat.should-initialize-gzd-compat-layer' => function( ContainerInterface $container ) : bool {
|
||||||
|
$settings = $container->get( 'wcgateway.settings' );
|
||||||
|
assert( $settings instanceof Settings );
|
||||||
|
|
||||||
|
$tracking_enabled = $settings->has( 'tracking_enabled' ) && $settings->get( 'tracking_enabled' );
|
||||||
|
$is_gzd_active = $container->get( 'compat.gzd.is_supported_plugin_version_active' );
|
||||||
|
$should_sync_shipment = apply_filters( 'woocommerce_paypal_payments_sync_gzd_tracking', true );
|
||||||
|
$is_paypal_order_edit_page = $container->get( 'order-tracking.is-paypal-order-edit-page' );
|
||||||
|
|
||||||
|
return $tracking_enabled && $is_gzd_active && $should_sync_shipment && $is_paypal_order_edit_page;
|
||||||
|
},
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue