mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-05 08:59:14 +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 {
|
||||
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 {
|
||||
|
|
|
@ -47,14 +47,24 @@ class SettingsModel extends AbstractDataModel {
|
|||
*/
|
||||
protected DataSanitizer $sanitizer;
|
||||
|
||||
/**
|
||||
* Invoice prefix.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private string $invoice_prefix;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @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.
|
||||
*/
|
||||
public function __construct( DataSanitizer $sanitizer ) {
|
||||
$this->sanitizer = $sanitizer;
|
||||
public function __construct( DataSanitizer $sanitizer, string $invoice_prefix ) {
|
||||
$this->sanitizer = $sanitizer;
|
||||
$this->invoice_prefix = $invoice_prefix;
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
@ -66,7 +76,7 @@ class SettingsModel extends AbstractDataModel {
|
|||
protected function get_defaults() : array {
|
||||
return array(
|
||||
// Free-form string values.
|
||||
'invoice_prefix' => '',
|
||||
'invoice_prefix' => $this->invoice_prefix,
|
||||
'brand_name' => '',
|
||||
'soft_descriptor' => '',
|
||||
|
||||
|
|
|
@ -2093,4 +2093,16 @@ return array(
|
|||
'wcgateway.settings.admin-settings-enabled' => static function( ContainerInterface $container ): bool {
|
||||
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(
|
||||
'pattern' => '[a-zA-Z_\\-]+',
|
||||
),
|
||||
'default' => ( static function (): 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 . '-' : '';
|
||||
} )(),
|
||||
'default' => $container->get( 'wcgateway.settings.invoice-prefix' ),
|
||||
'screens' => array(
|
||||
State::STATE_START,
|
||||
State::STATE_ONBOARDED,
|
||||
|
@ -539,7 +533,7 @@ return function ( ContainerInterface $container, array $fields ): array {
|
|||
'requirements' => array(),
|
||||
'gateway' => Settings::CONNECTION_TAB_ID,
|
||||
),
|
||||
'stay_updated' => array(
|
||||
'stay_updated' => array(
|
||||
'title' => __( 'Stay Updated', 'woocommerce-paypal-payments' ),
|
||||
'type' => 'checkbox',
|
||||
'desc_tip' => true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue