mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Merge pull request #1827 from woocommerce/PCP-1771-separate-card-button-style
Add Standard Card Button gateway styling settings & preview (1771)
This commit is contained in:
commit
af638334ae
7 changed files with 249 additions and 28 deletions
|
@ -1007,8 +1007,9 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
|
|||
'id' => CardButtonGateway::ID,
|
||||
'wrapper' => '#ppc-button-' . CardButtonGateway::ID,
|
||||
'style' => array(
|
||||
'shape' => $this->style_for_context( 'shape', $this->context() ),
|
||||
// TODO: color black, white from the gateway settings.
|
||||
'shape' => $this->style_for_apm( 'shape', 'card' ),
|
||||
'color' => $this->style_for_apm( 'color', 'card', 'black' ),
|
||||
'layout' => $this->style_for_apm( 'poweredby_tagline', 'card', false ) === $this->normalize_style_value( true ) ? 'vertical' : 'horizontal',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
@ -1342,9 +1343,9 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
|
|||
}
|
||||
|
||||
/**
|
||||
* Determines the style for a given indicator in a given context.
|
||||
* Determines the style for a given property in a given context.
|
||||
*
|
||||
* @param string $style The style.
|
||||
* @param string $style The name of the style property.
|
||||
* @param string $context The context.
|
||||
*
|
||||
* @return string
|
||||
|
@ -1367,13 +1368,46 @@ document.querySelector("#payment").before(document.querySelector("#ppcp-messages
|
|||
$context = 'general';
|
||||
}
|
||||
|
||||
$value = isset( $defaults[ $style ] ) ?
|
||||
$defaults[ $style ] : '';
|
||||
$value = $this->settings->has( 'button_' . $style ) ?
|
||||
$this->settings->get( 'button_' . $style ) : $value;
|
||||
$value = $this->settings->has( 'button_' . $context . '_' . $style ) ?
|
||||
$this->settings->get( 'button_' . $context . '_' . $style ) : $value;
|
||||
return $this->get_style_value( "button_{$context}_${style}" )
|
||||
?? $this->get_style_value( "button_${style}" )
|
||||
?? $this->normalize_style_value( $defaults[ $style ] ?? '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines the style for a given property in a given APM.
|
||||
*
|
||||
* @param string $style The name of the style property.
|
||||
* @param string $apm The APM name, such as 'card'.
|
||||
* @param ?mixed $default The default value.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
private function style_for_apm( string $style, string $apm, $default = null ): string {
|
||||
return $this->get_style_value( "${apm}_button_${style}" )
|
||||
?? ( $default ? $this->normalize_style_value( $default ) : null )
|
||||
?? $this->style_for_context( $style, 'checkout' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the style property value or null.
|
||||
*
|
||||
* @param string $key The style property key in the settings.
|
||||
* @return string|null
|
||||
*/
|
||||
private function get_style_value( string $key ): ?string {
|
||||
if ( ! $this->settings->has( $key ) ) {
|
||||
return null;
|
||||
}
|
||||
return $this->normalize_style_value( $this->settings->get( $key ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the style property value to string.
|
||||
*
|
||||
* @param mixed $value The style property value.
|
||||
* @return string
|
||||
*/
|
||||
private function normalize_style_value( $value ): string {
|
||||
if ( is_bool( $value ) ) {
|
||||
$value = $value ? 'true' : 'false';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue