mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Check for tracking compat assets inside class itself
This commit is contained in:
parent
4747d9d224
commit
ee51504f5f
3 changed files with 41 additions and 44 deletions
|
@ -83,7 +83,8 @@ return array(
|
|||
$container->get( 'compat.module.url' ),
|
||||
$container->get( 'ppcp.asset-version' ),
|
||||
$container->get( 'compat.gzd.is_supported_plugin_version_active' ),
|
||||
$container->get( 'compat.wc_shipment_tracking.is_supported_plugin_version_active' )
|
||||
$container->get( 'compat.wc_shipment_tracking.is_supported_plugin_version_active' ),
|
||||
$container->get( 'api.bearer' )
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -9,10 +9,16 @@ declare(strict_types=1);
|
|||
|
||||
namespace WooCommerce\PayPalCommerce\Compat\Assets;
|
||||
|
||||
use WooCommerce\PayPalCommerce\ApiClient\Authentication\Bearer;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\TrackingAvailabilityTrait;
|
||||
|
||||
/**
|
||||
* Class OrderEditPageAssets
|
||||
*/
|
||||
class CompatAssets {
|
||||
|
||||
use TrackingAvailabilityTrait;
|
||||
|
||||
/**
|
||||
* The URL to the module.
|
||||
*
|
||||
|
@ -41,6 +47,13 @@ class CompatAssets {
|
|||
*/
|
||||
protected $is_wc_shipment_active;
|
||||
|
||||
/**
|
||||
* The bearer.
|
||||
*
|
||||
* @var Bearer
|
||||
*/
|
||||
protected $bearer;
|
||||
|
||||
/**
|
||||
* Compat module assets constructor.
|
||||
*
|
||||
|
@ -48,18 +61,21 @@ class CompatAssets {
|
|||
* @param string $version The assets version.
|
||||
* @param bool $is_gzd_active Whether Germanized plugin is active.
|
||||
* @param bool $is_wc_shipment_active Whether WC Shipments plugin is active.
|
||||
* @param Bearer $bearer The bearer.
|
||||
*/
|
||||
public function __construct(
|
||||
string $module_url,
|
||||
string $version,
|
||||
bool $is_gzd_active,
|
||||
bool $is_wc_shipment_active
|
||||
bool $is_wc_shipment_active,
|
||||
Bearer $bearer
|
||||
) {
|
||||
|
||||
$this->module_url = $module_url;
|
||||
$this->version = $version;
|
||||
$this->is_gzd_active = $is_gzd_active;
|
||||
$this->is_wc_shipment_active = $is_wc_shipment_active;
|
||||
$this->bearer = $bearer;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,22 +84,24 @@ class CompatAssets {
|
|||
* @return void
|
||||
*/
|
||||
public function register(): void {
|
||||
wp_register_script(
|
||||
'ppcp-tracking-compat',
|
||||
untrailingslashit( $this->module_url ) . '/assets/js/tracking-compat.js',
|
||||
array( 'jquery' ),
|
||||
$this->version,
|
||||
true
|
||||
);
|
||||
if ( $this->is_tracking_enabled( $this->bearer ) ) {
|
||||
wp_register_script(
|
||||
'ppcp-tracking-compat',
|
||||
untrailingslashit( $this->module_url ) . '/assets/js/tracking-compat.js',
|
||||
array( 'jquery' ),
|
||||
$this->version,
|
||||
true
|
||||
);
|
||||
|
||||
wp_localize_script(
|
||||
'ppcp-tracking-compat',
|
||||
'PayPalCommerceGatewayOrderTrackingCompat',
|
||||
array(
|
||||
'gzd_sync_enabled' => apply_filters( 'woocommerce_paypal_payments_sync_gzd_tracking', true ) && $this->is_gzd_active,
|
||||
'wc_shipment_sync_enabled' => apply_filters( 'woocommerce_paypal_payments_sync_wc_shipment_tracking', true ) && $this->is_wc_shipment_active,
|
||||
)
|
||||
);
|
||||
wp_localize_script(
|
||||
'ppcp-tracking-compat',
|
||||
'PayPalCommerceGatewayOrderTrackingCompat',
|
||||
array(
|
||||
'gzd_sync_enabled' => apply_filters( 'woocommerce_paypal_payments_sync_gzd_tracking', true ) && $this->is_gzd_active,
|
||||
'wc_shipment_sync_enabled' => apply_filters( 'woocommerce_paypal_payments_sync_wc_shipment_tracking', true ) && $this->is_wc_shipment_active,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,6 +110,8 @@ class CompatAssets {
|
|||
* @return void
|
||||
*/
|
||||
public function enqueue(): void {
|
||||
wp_enqueue_script( 'ppcp-tracking-compat' );
|
||||
if ( $this->is_tracking_enabled( $this->bearer ) ) {
|
||||
wp_enqueue_script( 'ppcp-tracking-compat' );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ namespace WooCommerce\PayPalCommerce\Compat;
|
|||
|
||||
use Vendidero\Germanized\Shipments\ShipmentItem;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\Shipment\ShipmentFactoryInterface;
|
||||
use WooCommerce\PayPalCommerce\OrderTracking\TrackingAvailabilityTrait;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Container\ServiceProvider;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Dhii\Modular\Module\ModuleInterface;
|
||||
use Exception;
|
||||
|
@ -31,9 +30,6 @@ use WP_REST_Response;
|
|||
* Class CompatModule
|
||||
*/
|
||||
class CompatModule implements ModuleInterface {
|
||||
|
||||
use TrackingAvailabilityTrait;
|
||||
|
||||
/**
|
||||
* Setup the compatibility module.
|
||||
*
|
||||
|
@ -60,28 +56,8 @@ class CompatModule implements ModuleInterface {
|
|||
$asset_loader = $c->get( 'compat.assets' );
|
||||
assert( $asset_loader instanceof CompatAssets );
|
||||
|
||||
$bearer = $c->get( 'api.bearer' );
|
||||
|
||||
add_action(
|
||||
'init',
|
||||
function() use ( $asset_loader, $bearer ) {
|
||||
if ( ! $this->is_tracking_enabled( $bearer ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$asset_loader->register();
|
||||
}
|
||||
);
|
||||
add_action(
|
||||
'init',
|
||||
function() use ( $asset_loader, $bearer ) {
|
||||
if ( ! $this->is_tracking_enabled( $bearer ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$asset_loader->enqueue();
|
||||
}
|
||||
);
|
||||
add_action( 'init', array( $asset_loader, 'register' ) );
|
||||
add_action( 'admin_enqueue_scripts', array( $asset_loader, 'enqueue' ) );
|
||||
|
||||
$this->migrate_pay_later_settings( $c );
|
||||
$this->migrate_smart_button_settings( $c );
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue