mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +08:00
Refactor disable gateways with new settings
This commit is contained in:
parent
da07c3b5fa
commit
7f120720cc
2 changed files with 16 additions and 27 deletions
|
@ -142,7 +142,8 @@ return array(
|
|||
'wcgateway.disabler' => static function ( ContainerInterface $container ): DisableGateways {
|
||||
$session_handler = $container->get( 'session.handler' );
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
return new DisableGateways( $session_handler, $settings );
|
||||
$settings_status = $container->get( 'wcgateway.settings.status' );
|
||||
return new DisableGateways( $session_handler, $settings, $settings_status );
|
||||
},
|
||||
|
||||
'wcgateway.is-wc-payments-page' => static function ( ContainerInterface $container ): bool {
|
||||
|
@ -1279,32 +1280,9 @@ return array(
|
|||
return array_keys( $container->get( 'wcgateway.settings.pay-later.messaging-locations' ) );
|
||||
},
|
||||
'wcgateway.settings.pay-later.button-locations' => static function( ContainerInterface $container ): array {
|
||||
$button_locations = array();
|
||||
|
||||
$settings = $container->get( 'wcgateway.settings' );
|
||||
assert( $settings instanceof Settings );
|
||||
|
||||
$is_product_buttons_enabled = $settings->has( 'button_product_enabled' ) && $settings->get( 'button_product_enabled' );
|
||||
$is_mini_cart_buttons_enabled = $settings->has( 'button_mini-cart_enabled' ) && $settings->get( 'button_mini-cart_enabled' );
|
||||
$is_cart_buttons_enabled = $settings->has( 'button_cart_enabled' ) && $settings->get( 'button_cart_enabled' );
|
||||
$is_checkout_buttons_enabled = $settings->has( 'button_enabled' ) && $settings->get( 'button_enabled' );
|
||||
|
||||
if ( $is_product_buttons_enabled ) {
|
||||
$button_locations['product'] = 'Single Product';
|
||||
}
|
||||
|
||||
if ( $is_mini_cart_buttons_enabled ) {
|
||||
$button_locations['mini-cart'] = 'Mini Cart';
|
||||
}
|
||||
|
||||
if ( $is_cart_buttons_enabled ) {
|
||||
$button_locations['cart'] = 'Cart';
|
||||
}
|
||||
|
||||
if ( $is_checkout_buttons_enabled ) {
|
||||
$button_locations['checkout'] = 'Checkout';
|
||||
}
|
||||
|
||||
return $button_locations;
|
||||
return $this->settings->has( 'smart_button_locations' ) ? $this->settings->get( 'smart_button_locations' ) : array();
|
||||
},
|
||||
);
|
||||
|
|
|
@ -14,6 +14,7 @@ use WooCommerce\PayPalCommerce\WcGateway\Gateway\CardButtonGateway;
|
|||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\CreditCardGateway;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Gateway\PayPalGateway;
|
||||
use WooCommerce\PayPalCommerce\Vendor\Psr\Container\ContainerInterface;
|
||||
use WooCommerce\PayPalCommerce\WcGateway\Helper\SettingsStatus;
|
||||
|
||||
/**
|
||||
* Class DisableGateways
|
||||
|
@ -34,19 +35,29 @@ class DisableGateways {
|
|||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* The Settings status helper.
|
||||
*
|
||||
* @var SettingsStatus
|
||||
*/
|
||||
protected $settings_status;
|
||||
|
||||
/**
|
||||
* DisableGateways constructor.
|
||||
*
|
||||
* @param SessionHandler $session_handler The Session Handler.
|
||||
* @param ContainerInterface $settings The Settings.
|
||||
* @param SettingsStatus $settings_status The Settings status helper.
|
||||
*/
|
||||
public function __construct(
|
||||
SessionHandler $session_handler,
|
||||
ContainerInterface $settings
|
||||
ContainerInterface $settings,
|
||||
SettingsStatus $settings_status
|
||||
) {
|
||||
|
||||
$this->session_handler = $session_handler;
|
||||
$this->settings = $settings;
|
||||
$this->settings_status = $settings_status;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -71,7 +82,7 @@ class DisableGateways {
|
|||
unset( $methods[ CreditCardGateway::ID ] );
|
||||
}
|
||||
|
||||
if ( $this->settings->has( 'button_enabled' ) && ! $this->settings->get( 'button_enabled' ) && ! $this->session_handler->order() && is_checkout() ) {
|
||||
if ( ! $this->settings_status->is_smart_button_enabled_for_location( 'checkout' ) && ! $this->session_handler->order() && is_checkout() ) {
|
||||
unset( $methods[ PayPalGateway::ID ] );
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue