mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-07 19:54:15 +08:00
Get invoice prefix service in new settings ui
This commit is contained in:
parent
12df58b31c
commit
55199ed7d5
4 changed files with 29 additions and 12 deletions
|
@ -121,7 +121,8 @@ return array(
|
||||||
},
|
},
|
||||||
'settings.data.settings' => static function ( ContainerInterface $container ) : SettingsModel {
|
'settings.data.settings' => static function ( ContainerInterface $container ) : SettingsModel {
|
||||||
return new SettingsModel(
|
return new SettingsModel(
|
||||||
$container->get( 'settings.service.sanitizer' )
|
$container->get( 'settings.service.sanitizer' ),
|
||||||
|
$container->has( 'wcgateway.settings.invoice-prefix' ) ? $container->get( 'wcgateway.settings.invoice-prefix' ) : ''
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
'settings.data.paylater-messaging' => static function ( ContainerInterface $container ) : array {
|
'settings.data.paylater-messaging' => static function ( ContainerInterface $container ) : array {
|
||||||
|
|
|
@ -47,14 +47,24 @@ class SettingsModel extends AbstractDataModel {
|
||||||
*/
|
*/
|
||||||
protected DataSanitizer $sanitizer;
|
protected DataSanitizer $sanitizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice prefix.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private string $invoice_prefix;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param DataSanitizer $sanitizer Data sanitizer service.
|
* @param DataSanitizer $sanitizer Data sanitizer service.
|
||||||
|
* @param string $invoice_prefix Invoice prefix.
|
||||||
* @throws RuntimeException If the OPTION_KEY is not defined in the child class.
|
* @throws RuntimeException If the OPTION_KEY is not defined in the child class.
|
||||||
*/
|
*/
|
||||||
public function __construct( DataSanitizer $sanitizer ) {
|
public function __construct( DataSanitizer $sanitizer, string $invoice_prefix ) {
|
||||||
$this->sanitizer = $sanitizer;
|
$this->sanitizer = $sanitizer;
|
||||||
|
$this->invoice_prefix = $invoice_prefix;
|
||||||
|
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +76,7 @@ class SettingsModel extends AbstractDataModel {
|
||||||
protected function get_defaults() : array {
|
protected function get_defaults() : array {
|
||||||
return array(
|
return array(
|
||||||
// Free-form string values.
|
// Free-form string values.
|
||||||
'invoice_prefix' => '',
|
'invoice_prefix' => $this->invoice_prefix,
|
||||||
'brand_name' => '',
|
'brand_name' => '',
|
||||||
'soft_descriptor' => '',
|
'soft_descriptor' => '',
|
||||||
|
|
||||||
|
|
|
@ -2093,4 +2093,16 @@ return array(
|
||||||
'wcgateway.settings.admin-settings-enabled' => static function( ContainerInterface $container ): bool {
|
'wcgateway.settings.admin-settings-enabled' => static function( ContainerInterface $container ): bool {
|
||||||
return $container->has( 'settings.url' ) && ! SettingsModule::should_use_the_old_ui();
|
return $container->has( 'settings.url' ) && ! SettingsModule::should_use_the_old_ui();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a prefix for the site, ensuring the same site always gets the same prefix (unless the URL changes).
|
||||||
|
*/
|
||||||
|
'wcgateway.settings.invoice-prefix' => static function( ContainerInterface $container ): string {
|
||||||
|
$site_url = get_site_url( get_current_blog_id() );
|
||||||
|
$hash = md5( $site_url );
|
||||||
|
$letters = preg_replace( '~\d~', '', $hash ) ?? '';
|
||||||
|
$prefix = substr( $letters, 0, 6 );
|
||||||
|
|
||||||
|
return $prefix ? $prefix . '-' : '';
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
|
@ -510,13 +510,7 @@ return function ( ContainerInterface $container, array $fields ): array {
|
||||||
'custom_attributes' => array(
|
'custom_attributes' => array(
|
||||||
'pattern' => '[a-zA-Z_\\-]+',
|
'pattern' => '[a-zA-Z_\\-]+',
|
||||||
),
|
),
|
||||||
'default' => ( static function (): string {
|
'default' => $container->get( 'wcgateway.settings.invoice-prefix' ),
|
||||||
$site_url = get_site_url( get_current_blog_id() );
|
|
||||||
$hash = md5( $site_url );
|
|
||||||
$letters = preg_replace( '~\d~', '', $hash ) ?? '';
|
|
||||||
$prefix = substr( $letters, 0, 6 );
|
|
||||||
return $prefix ? $prefix . '-' : '';
|
|
||||||
} )(),
|
|
||||||
'screens' => array(
|
'screens' => array(
|
||||||
State::STATE_START,
|
State::STATE_START,
|
||||||
State::STATE_ONBOARDED,
|
State::STATE_ONBOARDED,
|
||||||
|
@ -539,7 +533,7 @@ return function ( ContainerInterface $container, array $fields ): array {
|
||||||
'requirements' => array(),
|
'requirements' => array(),
|
||||||
'gateway' => Settings::CONNECTION_TAB_ID,
|
'gateway' => Settings::CONNECTION_TAB_ID,
|
||||||
),
|
),
|
||||||
'stay_updated' => array(
|
'stay_updated' => array(
|
||||||
'title' => __( 'Stay Updated', 'woocommerce-paypal-payments' ),
|
'title' => __( 'Stay Updated', 'woocommerce-paypal-payments' ),
|
||||||
'type' => 'checkbox',
|
'type' => 'checkbox',
|
||||||
'desc_tip' => true,
|
'desc_tip' => true,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue