* Fix lint

This commit is contained in:
Pedro Silva 2023-07-27 10:29:24 +01:00
parent 9cdd11b3b3
commit b25a124ffa
No known key found for this signature in database
GPG key ID: E2EE20C0669D24B3
2 changed files with 38 additions and 29 deletions

View file

@ -1372,15 +1372,15 @@ class SmartButton implements SmartButtonInterface {
/** /**
* Fills and returns the product context_data array to be used in filters. * Fills and returns the product context_data array to be used in filters.
* *
* @param array $context_data * @param array $context_data The context data for this filter.
* @return array * @return array
*/ */
private function product_filter_context_data( array $context_data = [] ): array { private function product_filter_context_data( array $context_data = array() ): array {
if ( ! isset( $context_data['product'] ) ) { if ( ! isset( $context_data['product'] ) ) {
$context_data['product'] = wc_get_product(); $context_data['product'] = wc_get_product();
} }
if ( ! $context_data['product'] ) { if ( ! $context_data['product'] ) {
return []; return array();
} }
if ( ! isset( $context_data['order_total'] ) && ( $context_data['product'] instanceof WC_Product ) ) { if ( ! isset( $context_data['order_total'] ) && ( $context_data['product'] instanceof WC_Product ) ) {
$context_data['order_total'] = (float) $context_data['product']->get_price( 'raw' ); $context_data['order_total'] = (float) $context_data['product']->get_price( 'raw' );
@ -1393,24 +1393,28 @@ class SmartButton implements SmartButtonInterface {
* Checks if PayPal buttons/messages should be rendered for the current page. * Checks if PayPal buttons/messages should be rendered for the current page.
* *
* @param string|null $context The context that should be checked, use default otherwise. * @param string|null $context The context that should be checked, use default otherwise.
* @param array $context_data The context data for this filter * @param array $context_data The context data for this filter.
* @return bool * @return bool
*/ */
public function is_button_disabled( string $context = null, array $context_data = [] ): bool { public function is_button_disabled( string $context = null, array $context_data = array() ): bool {
if ( null === $context ) { if ( null === $context ) {
$context = $this->context(); $context = $this->context();
} }
if ( 'product' === $context ) { if ( 'product' === $context ) {
// Allows to decide if the button should be disabled for a given product. /**
* Allows to decide if the button should be disabled for a given product.
*/
return apply_filters( return apply_filters(
'woocommerce_paypal_payments_product_buttons_disabled', 'woocommerce_paypal_payments_product_buttons_disabled',
false, false,
$this->product_filter_context_data($context_data) $this->product_filter_context_data( $context_data )
); );
} }
// Allows to decide if the button should be disabled globally or on a given context. /**
* Allows to decide if the button should be disabled globally or on a given context.
*/
return apply_filters( return apply_filters(
'woocommerce_paypal_payments_buttons_disabled', 'woocommerce_paypal_payments_buttons_disabled',
false, false,
@ -1422,21 +1426,25 @@ class SmartButton implements SmartButtonInterface {
* Checks a filter if pay_later/messages should be rendered on a given location / context. * Checks a filter if pay_later/messages should be rendered on a given location / context.
* *
* @param string $location The location. * @param string $location The location.
* @param array $context_data The context data for this filter * @param array $context_data The context data for this filter.
* @return bool * @return bool
*/ */
private function is_pay_later_filter_enabled_for_location( string $location, array $context_data = [] ): bool { private function is_pay_later_filter_enabled_for_location( string $location, array $context_data = array() ): bool {
if ( 'product' === $location ) { if ( 'product' === $location ) {
// Allows to decide if the button should be disabled for a given product. /**
* Allows to decide if the button should be disabled for a given product.
*/
return ! apply_filters( return ! apply_filters(
'woocommerce_paypal_payments_product_buttons_paylater_disabled', 'woocommerce_paypal_payments_product_buttons_paylater_disabled',
false, false,
$this->product_filter_context_data($context_data) $this->product_filter_context_data( $context_data )
); );
} }
// Allows to decide if the button should be disabled on a given context. /**
* Allows to decide if the button should be disabled on a given context.
*/
return ! apply_filters( return ! apply_filters(
'woocommerce_paypal_payments_buttons_paylater_disabled', 'woocommerce_paypal_payments_buttons_paylater_disabled',
false, false,
@ -1448,10 +1456,10 @@ class SmartButton implements SmartButtonInterface {
* Check whether Pay Later button is enabled for a given location. * Check whether Pay Later button is enabled for a given location.
* *
* @param string $location The location. * @param string $location The location.
* @param array $context_data The context data for this filter * @param array $context_data The context data for this filter.
* @return bool true if is enabled, otherwise false. * @return bool true if is enabled, otherwise false.
*/ */
public function is_pay_later_button_enabled_for_location( string $location, array $context_data = [] ): bool { public function is_pay_later_button_enabled_for_location( string $location, array $context_data = array() ): bool {
return $this->is_pay_later_filter_enabled_for_location( $location, $context_data ) return $this->is_pay_later_filter_enabled_for_location( $location, $context_data )
&& $this->settings_status->is_pay_later_button_enabled_for_location( $location ); && $this->settings_status->is_pay_later_button_enabled_for_location( $location );
@ -1460,11 +1468,11 @@ class SmartButton implements SmartButtonInterface {
/** /**
* Check whether Pay Later message is enabled for a given location. * Check whether Pay Later message is enabled for a given location.
* *
* @param string $location The location setting name. * @param string $location The location setting name.
* @param array $context_data The context data for this filter * @param array $context_data The context data for this filter.
* @return bool true if is enabled, otherwise false. * @return bool true if is enabled, otherwise false.
*/ */
public function is_pay_later_messaging_enabled_for_location( string $location, array $context_data = [] ): bool { public function is_pay_later_messaging_enabled_for_location( string $location, array $context_data = array() ): bool {
return $this->is_pay_later_filter_enabled_for_location( $location, $context_data ) return $this->is_pay_later_filter_enabled_for_location( $location, $context_data )
&& $this->settings_status->is_pay_later_messaging_enabled_for_location( $location ); && $this->settings_status->is_pay_later_messaging_enabled_for_location( $location );
} }

View file

@ -85,32 +85,33 @@ class SimulateCartEndpoint extends AbstractCartEndpoint {
unset( $this->cart ); unset( $this->cart );
// Process filters. // Process filters.
$pay_later_enabled = true; $pay_later_enabled = true;
$pay_later_messaging_enabled = true; $pay_later_messaging_enabled = true;
$button_enabled = true; $button_enabled = true;
foreach ( $products as $product ) { foreach ( $products as $product ) {
$context_data = [ $context_data = array(
'product' => $product['product'], 'product' => $product['product'],
'order_total' => $total, 'order_total' => $total,
]; );
$pay_later_enabled = $pay_later_enabled && $this->smart_button->is_pay_later_button_enabled_for_location( 'product', $context_data );
$pay_later_enabled = $pay_later_enabled && $this->smart_button->is_pay_later_button_enabled_for_location( 'product', $context_data );
$pay_later_messaging_enabled = $pay_later_messaging_enabled && $this->smart_button->is_pay_later_messaging_enabled_for_location( 'product', $context_data ); $pay_later_messaging_enabled = $pay_later_messaging_enabled && $this->smart_button->is_pay_later_messaging_enabled_for_location( 'product', $context_data );
$button_enabled = $button_enabled && ! $this->smart_button->is_button_disabled( 'product', $context_data ); $button_enabled = $button_enabled && ! $this->smart_button->is_button_disabled( 'product', $context_data );
} }
wp_send_json_success( wp_send_json_success(
array( array(
'total' => $total, 'total' => $total,
'funding' => array( 'funding' => array(
'paylater' => array( 'paylater' => array(
'enabled' => $pay_later_enabled, 'enabled' => $pay_later_enabled,
), ),
), ),
'button' => array( 'button' => array(
'is_disabled' => ! $button_enabled, 'is_disabled' => ! $button_enabled,
), ),
'messages' => array( 'messages' => array(
'is_hidden' => ! $pay_later_messaging_enabled, 'is_hidden' => ! $pay_later_messaging_enabled,
), ),
) )