Auto-enable tracking if is PUI ready for German merchants

This commit is contained in:
Narek Zakarian 2022-08-15 14:57:53 +04:00
parent 10da1f8067
commit 1242a45f8f
2 changed files with 34 additions and 8 deletions

View file

@ -18,7 +18,9 @@ use Psr\Log\LoggerInterface;
use WC_Order;
use WooCommerce\PayPalCommerce\OrderTracking\Assets\OrderEditPageAssets;
use WooCommerce\PayPalCommerce\OrderTracking\Endpoint\OrderTrackingEndpoint;
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
use WooCommerce\PayPalCommerce\WcGateway\Exception\NotFoundException;
use WooCommerce\PayPalCommerce\WcGateway\Helper\PayUponInvoiceHelper;
use WooCommerce\PayPalCommerce\WcGateway\Settings\Settings;
/**
* Class OrderTrackingModule
@ -39,9 +41,27 @@ class OrderTrackingModule implements ModuleInterface {
* {@inheritDoc}
*
* @param ContainerInterface $c A services container instance.
* @throws NotFoundException
*/
public function run( ContainerInterface $c ): void {
$settings = $c->get( 'wcgateway.settings' );
/**
* The Settings.
*
* @var Settings $settings
*/
$settings = $c->get( 'wcgateway.settings' );
/**
* The PUI helper.
*
* @var PayUponInvoiceHelper $pui_helper
*/
$pui_helper = $c->get( 'wcgateway.pay-upon-invoice-helper' );
if ( $pui_helper->is_pui_ready_in_admin() ) {
$settings->set( 'tracking_enabled', true );
$settings->persist();
}
$tracking_enabled = $settings->has( 'tracking_enabled' ) && $settings->get( 'tracking_enabled' );
if ( ! $tracking_enabled ) {
@ -136,9 +156,4 @@ class OrderTrackingModule implements ModuleInterface {
}
);
}
/**
* {@inheritDoc}
*/
public function getKey() { }
}

View file

@ -315,6 +315,13 @@ return array(
$module_url = $container->get( 'wcgateway.url' );
/**
* The PUI helper.
*
* @var PayUponInvoiceHelper $pui_helper
*/
$pui_helper = $container->get( 'wcgateway.pay-upon-invoice-helper' );
$fields = array(
'ppcp_onboarading_header' => array(
'type' => 'ppcp-text',
@ -873,6 +880,7 @@ return array(
),
'requirements' => array(),
'gateway' => array( 'paypal' ),
'input_class' => $pui_helper->is_pui_ready_in_admin() ? array( 'ppcp-disabled-checkbox' ) : array(),
),
// General button styles.
@ -2208,7 +2216,10 @@ return array(
);
},
'wcgateway.pay-upon-invoice-helper' => static function( ContainerInterface $container ): PayUponInvoiceHelper {
return new PayUponInvoiceHelper();
return new PayUponInvoiceHelper(
$container->get( 'api.shop.country' ),
$container->get( 'wcgateway.pay-upon-invoice-product-status' )
);
},
'wcgateway.pay-upon-invoice-product-status' => static function( ContainerInterface $container ): PayUponInvoiceProductStatus {
return new PayUponInvoiceProductStatus(