@@ -8,31 +8,31 @@ |
||
| 8 | 8 | */ |
| 9 | 9 | class ProductSearchResultsTemplate { |
| 10 | 10 | |
| 11 | - const SLUG = 'product-search-results'; |
|
| 11 | + const SLUG = 'product-search-results'; |
|
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Constructor. |
|
| 15 | - */ |
|
| 16 | - public function __construct() { |
|
| 17 | - $this->init(); |
|
| 18 | - } |
|
| 13 | + /** |
|
| 14 | + * Constructor. |
|
| 15 | + */ |
|
| 16 | + public function __construct() { |
|
| 17 | + $this->init(); |
|
| 18 | + } |
|
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Initialization method. |
|
| 22 | - */ |
|
| 23 | - protected function init() { |
|
| 24 | - add_filter( 'search_template_hierarchy', array( $this, 'update_search_template_hierarchy' ), 10, 3 ); |
|
| 25 | - } |
|
| 20 | + /** |
|
| 21 | + * Initialization method. |
|
| 22 | + */ |
|
| 23 | + protected function init() { |
|
| 24 | + add_filter( 'search_template_hierarchy', array( $this, 'update_search_template_hierarchy' ), 10, 3 ); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * When the search is for products and a block theme is active, render the Product Search Template. |
|
| 29 | - * |
|
| 30 | - * @param array $templates Templates that match the search hierarchy. |
|
| 31 | - */ |
|
| 32 | - public function update_search_template_hierarchy( $templates ) { |
|
| 33 | - if ( ( is_search() && is_post_type_archive( 'product' ) ) && wc_current_theme_is_fse_theme() ) { |
|
| 34 | - array_unshift( $templates, self::SLUG ); |
|
| 35 | - } |
|
| 36 | - return $templates; |
|
| 37 | - } |
|
| 27 | + /** |
|
| 28 | + * When the search is for products and a block theme is active, render the Product Search Template. |
|
| 29 | + * |
|
| 30 | + * @param array $templates Templates that match the search hierarchy. |
|
| 31 | + */ |
|
| 32 | + public function update_search_template_hierarchy( $templates ) { |
|
| 33 | + if ( ( is_search() && is_post_type_archive( 'product' ) ) && wc_current_theme_is_fse_theme() ) { |
|
| 34 | + array_unshift( $templates, self::SLUG ); |
|
| 35 | + } |
|
| 36 | + return $templates; |
|
| 37 | + } |
|
| 38 | 38 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | * Initialization method. |
| 22 | 22 | */ |
| 23 | 23 | protected function init() { |
| 24 | - add_filter( 'search_template_hierarchy', array( $this, 'update_search_template_hierarchy' ), 10, 3 ); |
|
| 24 | + add_filter('search_template_hierarchy', array($this, 'update_search_template_hierarchy'), 10, 3); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | * |
| 30 | 30 | * @param array $templates Templates that match the search hierarchy. |
| 31 | 31 | */ |
| 32 | - public function update_search_template_hierarchy( $templates ) { |
|
| 33 | - if ( ( is_search() && is_post_type_archive( 'product' ) ) && wc_current_theme_is_fse_theme() ) { |
|
| 34 | - array_unshift( $templates, self::SLUG ); |
|
| 32 | + public function update_search_template_hierarchy($templates) { |
|
| 33 | + if ((is_search() && is_post_type_archive('product')) && wc_current_theme_is_fse_theme()) { |
|
| 34 | + array_unshift($templates, self::SLUG); |
|
| 35 | 35 | } |
| 36 | 36 | return $templates; |
| 37 | 37 | } |
@@ -12,70 +12,70 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class ClassicTemplatesCompatibility { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Instance of the asset data registry. |
|
| 17 | - * |
|
| 18 | - * @var AssetDataRegistry |
|
| 19 | - */ |
|
| 20 | - protected $asset_data_registry; |
|
| 15 | + /** |
|
| 16 | + * Instance of the asset data registry. |
|
| 17 | + * |
|
| 18 | + * @var AssetDataRegistry |
|
| 19 | + */ |
|
| 20 | + protected $asset_data_registry; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Constructor. |
|
| 24 | - * |
|
| 25 | - * @param AssetDataRegistry $asset_data_registry Instance of the asset data registry. |
|
| 26 | - */ |
|
| 27 | - public function __construct( AssetDataRegistry $asset_data_registry ) { |
|
| 28 | - $this->asset_data_registry = $asset_data_registry; |
|
| 29 | - $this->init(); |
|
| 30 | - } |
|
| 22 | + /** |
|
| 23 | + * Constructor. |
|
| 24 | + * |
|
| 25 | + * @param AssetDataRegistry $asset_data_registry Instance of the asset data registry. |
|
| 26 | + */ |
|
| 27 | + public function __construct( AssetDataRegistry $asset_data_registry ) { |
|
| 28 | + $this->asset_data_registry = $asset_data_registry; |
|
| 29 | + $this->init(); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Initialization method. |
|
| 34 | - */ |
|
| 35 | - protected function init() { |
|
| 36 | - if ( ! wc_current_theme_is_fse_theme() ) { |
|
| 37 | - add_action( 'template_redirect', array( $this, 'set_classic_template_data' ) ); |
|
| 38 | - // We need to set this data on the widgets screen so the filters render previews. |
|
| 39 | - add_action( 'load-widgets.php', array( $this, 'set_filterable_product_data' ) ); |
|
| 40 | - } |
|
| 41 | - } |
|
| 32 | + /** |
|
| 33 | + * Initialization method. |
|
| 34 | + */ |
|
| 35 | + protected function init() { |
|
| 36 | + if ( ! wc_current_theme_is_fse_theme() ) { |
|
| 37 | + add_action( 'template_redirect', array( $this, 'set_classic_template_data' ) ); |
|
| 38 | + // We need to set this data on the widgets screen so the filters render previews. |
|
| 39 | + add_action( 'load-widgets.php', array( $this, 'set_filterable_product_data' ) ); |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Executes the methods which set the necessary data needed for filter blocks to work correctly as widgets in Classic templates. |
|
| 45 | - * |
|
| 46 | - * @return void |
|
| 47 | - */ |
|
| 48 | - public function set_classic_template_data() { |
|
| 49 | - $this->set_filterable_product_data(); |
|
| 50 | - $this->set_php_template_data(); |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * Executes the methods which set the necessary data needed for filter blocks to work correctly as widgets in Classic templates. |
|
| 45 | + * |
|
| 46 | + * @return void |
|
| 47 | + */ |
|
| 48 | + public function set_classic_template_data() { |
|
| 49 | + $this->set_filterable_product_data(); |
|
| 50 | + $this->set_php_template_data(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * This method passes the value `has_filterable_products` to the front-end for product archive pages, |
|
| 55 | - * so that widget product filter blocks are aware of the context they are in and can render accordingly. |
|
| 56 | - * |
|
| 57 | - * @return void |
|
| 58 | - */ |
|
| 59 | - public function set_filterable_product_data() { |
|
| 60 | - global $pagenow; |
|
| 53 | + /** |
|
| 54 | + * This method passes the value `has_filterable_products` to the front-end for product archive pages, |
|
| 55 | + * so that widget product filter blocks are aware of the context they are in and can render accordingly. |
|
| 56 | + * |
|
| 57 | + * @return void |
|
| 58 | + */ |
|
| 59 | + public function set_filterable_product_data() { |
|
| 60 | + global $pagenow; |
|
| 61 | 61 | |
| 62 | - if ( is_shop() || is_product_taxonomy() || 'widgets.php' === $pagenow ) { |
|
| 63 | - $this->asset_data_registry->add( 'has_filterable_products', true, true ); |
|
| 64 | - } |
|
| 65 | - } |
|
| 62 | + if ( is_shop() || is_product_taxonomy() || 'widgets.php' === $pagenow ) { |
|
| 63 | + $this->asset_data_registry->add( 'has_filterable_products', true, true ); |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * This method passes the value `is_rendering_php_template` to the front-end of Classic themes, |
|
| 69 | - * so that widget product filter blocks are aware of how to filter the products. |
|
| 70 | - * |
|
| 71 | - * This data only matters on WooCommerce product archive pages. |
|
| 72 | - * On non-archive pages the merchant could be using the All Products block which is not a PHP template. |
|
| 73 | - * |
|
| 74 | - * @return void |
|
| 75 | - */ |
|
| 76 | - public function set_php_template_data() { |
|
| 77 | - if ( is_shop() || is_product_taxonomy() ) { |
|
| 78 | - $this->asset_data_registry->add( 'is_rendering_php_template', true, true ); |
|
| 79 | - } |
|
| 80 | - } |
|
| 67 | + /** |
|
| 68 | + * This method passes the value `is_rendering_php_template` to the front-end of Classic themes, |
|
| 69 | + * so that widget product filter blocks are aware of how to filter the products. |
|
| 70 | + * |
|
| 71 | + * This data only matters on WooCommerce product archive pages. |
|
| 72 | + * On non-archive pages the merchant could be using the All Products block which is not a PHP template. |
|
| 73 | + * |
|
| 74 | + * @return void |
|
| 75 | + */ |
|
| 76 | + public function set_php_template_data() { |
|
| 77 | + if ( is_shop() || is_product_taxonomy() ) { |
|
| 78 | + $this->asset_data_registry->add( 'is_rendering_php_template', true, true ); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | * @param AssetDataRegistry $asset_data_registry Instance of the asset data registry. |
| 26 | 26 | */ |
| 27 | - public function __construct( AssetDataRegistry $asset_data_registry ) { |
|
| 27 | + public function __construct(AssetDataRegistry $asset_data_registry) { |
|
| 28 | 28 | $this->asset_data_registry = $asset_data_registry; |
| 29 | 29 | $this->init(); |
| 30 | 30 | } |
@@ -33,10 +33,10 @@ discard block |
||
| 33 | 33 | * Initialization method. |
| 34 | 34 | */ |
| 35 | 35 | protected function init() { |
| 36 | - if ( ! wc_current_theme_is_fse_theme() ) { |
|
| 37 | - add_action( 'template_redirect', array( $this, 'set_classic_template_data' ) ); |
|
| 36 | + if (!wc_current_theme_is_fse_theme()) { |
|
| 37 | + add_action('template_redirect', array($this, 'set_classic_template_data')); |
|
| 38 | 38 | // We need to set this data on the widgets screen so the filters render previews. |
| 39 | - add_action( 'load-widgets.php', array( $this, 'set_filterable_product_data' ) ); |
|
| 39 | + add_action('load-widgets.php', array($this, 'set_filterable_product_data')); |
|
| 40 | 40 | } |
| 41 | 41 | } |
| 42 | 42 | |
@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | public function set_filterable_product_data() { |
| 60 | 60 | global $pagenow; |
| 61 | 61 | |
| 62 | - if ( is_shop() || is_product_taxonomy() || 'widgets.php' === $pagenow ) { |
|
| 63 | - $this->asset_data_registry->add( 'has_filterable_products', true, true ); |
|
| 62 | + if (is_shop() || is_product_taxonomy() || 'widgets.php' === $pagenow) { |
|
| 63 | + $this->asset_data_registry->add('has_filterable_products', true, true); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | * @return void |
| 75 | 75 | */ |
| 76 | 76 | public function set_php_template_data() { |
| 77 | - if ( is_shop() || is_product_taxonomy() ) { |
|
| 78 | - $this->asset_data_registry->add( 'is_rendering_php_template', true, true ); |
|
| 77 | + if (is_shop() || is_product_taxonomy()) { |
|
| 78 | + $this->asset_data_registry->add('is_rendering_php_template', true, true); |
|
| 79 | 79 | } |
| 80 | 80 | } |
| 81 | 81 | } |
@@ -5,12 +5,12 @@ |
||
| 5 | 5 | * FormatterInterface. |
| 6 | 6 | */ |
| 7 | 7 | interface FormatterInterface { |
| 8 | - /** |
|
| 9 | - * Format a given value and return the result. |
|
| 10 | - * |
|
| 11 | - * @param mixed $value Value to format. |
|
| 12 | - * @param array $options Options that influence the formatting. |
|
| 13 | - * @return mixed |
|
| 14 | - */ |
|
| 15 | - public function format( $value, array $options = [] ); |
|
| 8 | + /** |
|
| 9 | + * Format a given value and return the result. |
|
| 10 | + * |
|
| 11 | + * @param mixed $value Value to format. |
|
| 12 | + * @param array $options Options that influence the formatting. |
|
| 13 | + * @return mixed |
|
| 14 | + */ |
|
| 15 | + public function format( $value, array $options = [] ); |
|
| 16 | 16 | } |
@@ -12,5 +12,5 @@ |
||
| 12 | 12 | * @param array $options Options that influence the formatting. |
| 13 | 13 | * @return mixed |
| 14 | 14 | */ |
| 15 | - public function format( $value, array $options = [] ); |
|
| 15 | + public function format($value, array $options = []); |
|
| 16 | 16 | } |
@@ -5,14 +5,14 @@ |
||
| 5 | 5 | * Default Formatter. |
| 6 | 6 | */ |
| 7 | 7 | class DefaultFormatter implements FormatterInterface { |
| 8 | - /** |
|
| 9 | - * Format a given value and return the result. |
|
| 10 | - * |
|
| 11 | - * @param mixed $value Value to format. |
|
| 12 | - * @param array $options Options that influence the formatting. |
|
| 13 | - * @return mixed |
|
| 14 | - */ |
|
| 15 | - public function format( $value, array $options = [] ) { |
|
| 16 | - return $value; |
|
| 17 | - } |
|
| 8 | + /** |
|
| 9 | + * Format a given value and return the result. |
|
| 10 | + * |
|
| 11 | + * @param mixed $value Value to format. |
|
| 12 | + * @param array $options Options that influence the formatting. |
|
| 13 | + * @return mixed |
|
| 14 | + */ |
|
| 15 | + public function format( $value, array $options = [] ) { |
|
| 16 | + return $value; |
|
| 17 | + } |
|
| 18 | 18 | } |
@@ -12,7 +12,7 @@ |
||
| 12 | 12 | * @param array $options Options that influence the formatting. |
| 13 | 13 | * @return mixed |
| 14 | 14 | */ |
| 15 | - public function format( $value, array $options = [] ) { |
|
| 15 | + public function format($value, array $options = []) { |
|
| 16 | 16 | return $value; |
| 17 | 17 | } |
| 18 | 18 | } |
@@ -7,45 +7,45 @@ |
||
| 7 | 7 | * Formats an array of monetary values by inserting currency data. |
| 8 | 8 | */ |
| 9 | 9 | class CurrencyFormatter implements FormatterInterface { |
| 10 | - /** |
|
| 11 | - * Format a given value and return the result. |
|
| 12 | - * |
|
| 13 | - * @param array $value Value to format. |
|
| 14 | - * @param array $options Options that influence the formatting. |
|
| 15 | - * @return array |
|
| 16 | - */ |
|
| 17 | - public function format( $value, array $options = [] ) { |
|
| 18 | - $position = get_option( 'woocommerce_currency_pos' ); |
|
| 19 | - $symbol = html_entity_decode( get_woocommerce_currency_symbol() ); |
|
| 20 | - $prefix = ''; |
|
| 21 | - $suffix = ''; |
|
| 10 | + /** |
|
| 11 | + * Format a given value and return the result. |
|
| 12 | + * |
|
| 13 | + * @param array $value Value to format. |
|
| 14 | + * @param array $options Options that influence the formatting. |
|
| 15 | + * @return array |
|
| 16 | + */ |
|
| 17 | + public function format( $value, array $options = [] ) { |
|
| 18 | + $position = get_option( 'woocommerce_currency_pos' ); |
|
| 19 | + $symbol = html_entity_decode( get_woocommerce_currency_symbol() ); |
|
| 20 | + $prefix = ''; |
|
| 21 | + $suffix = ''; |
|
| 22 | 22 | |
| 23 | - switch ( $position ) { |
|
| 24 | - case 'left_space': |
|
| 25 | - $prefix = $symbol . ' '; |
|
| 26 | - break; |
|
| 27 | - case 'left': |
|
| 28 | - $prefix = $symbol; |
|
| 29 | - break; |
|
| 30 | - case 'right_space': |
|
| 31 | - $suffix = ' ' . $symbol; |
|
| 32 | - break; |
|
| 33 | - case 'right': |
|
| 34 | - $suffix = $symbol; |
|
| 35 | - break; |
|
| 36 | - } |
|
| 23 | + switch ( $position ) { |
|
| 24 | + case 'left_space': |
|
| 25 | + $prefix = $symbol . ' '; |
|
| 26 | + break; |
|
| 27 | + case 'left': |
|
| 28 | + $prefix = $symbol; |
|
| 29 | + break; |
|
| 30 | + case 'right_space': |
|
| 31 | + $suffix = ' ' . $symbol; |
|
| 32 | + break; |
|
| 33 | + case 'right': |
|
| 34 | + $suffix = $symbol; |
|
| 35 | + break; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - return array_merge( |
|
| 39 | - (array) $value, |
|
| 40 | - [ |
|
| 41 | - 'currency_code' => get_woocommerce_currency(), |
|
| 42 | - 'currency_symbol' => $symbol, |
|
| 43 | - 'currency_minor_unit' => wc_get_price_decimals(), |
|
| 44 | - 'currency_decimal_separator' => wc_get_price_decimal_separator(), |
|
| 45 | - 'currency_thousand_separator' => wc_get_price_thousand_separator(), |
|
| 46 | - 'currency_prefix' => $prefix, |
|
| 47 | - 'currency_suffix' => $suffix, |
|
| 48 | - ] |
|
| 49 | - ); |
|
| 50 | - } |
|
| 38 | + return array_merge( |
|
| 39 | + (array) $value, |
|
| 40 | + [ |
|
| 41 | + 'currency_code' => get_woocommerce_currency(), |
|
| 42 | + 'currency_symbol' => $symbol, |
|
| 43 | + 'currency_minor_unit' => wc_get_price_decimals(), |
|
| 44 | + 'currency_decimal_separator' => wc_get_price_decimal_separator(), |
|
| 45 | + 'currency_thousand_separator' => wc_get_price_thousand_separator(), |
|
| 46 | + 'currency_prefix' => $prefix, |
|
| 47 | + 'currency_suffix' => $suffix, |
|
| 48 | + ] |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -14,13 +14,13 @@ |
||
| 14 | 14 | * @param array $options Options that influence the formatting. |
| 15 | 15 | * @return array |
| 16 | 16 | */ |
| 17 | - public function format( $value, array $options = [] ) { |
|
| 18 | - $position = get_option( 'woocommerce_currency_pos' ); |
|
| 19 | - $symbol = html_entity_decode( get_woocommerce_currency_symbol() ); |
|
| 17 | + public function format($value, array $options = []) { |
|
| 18 | + $position = get_option('woocommerce_currency_pos'); |
|
| 19 | + $symbol = html_entity_decode(get_woocommerce_currency_symbol()); |
|
| 20 | 20 | $prefix = ''; |
| 21 | 21 | $suffix = ''; |
| 22 | 22 | |
| 23 | - switch ( $position ) { |
|
| 23 | + switch ($position) { |
|
| 24 | 24 | case 'left_space': |
| 25 | 25 | $prefix = $symbol . ' '; |
| 26 | 26 | break; |
@@ -9,20 +9,20 @@ |
||
| 9 | 9 | * @internal This API is used internally by Blocks--it is still in flux and may be subject to revisions. |
| 10 | 10 | */ |
| 11 | 11 | class HtmlFormatter implements FormatterInterface { |
| 12 | - /** |
|
| 13 | - * Format a given value and return the result. |
|
| 14 | - * |
|
| 15 | - * The wptexturize, convert_chars, and trim functions are also used in the `the_title` filter. |
|
| 16 | - * The function wp_kses_post removes disallowed HTML tags. |
|
| 17 | - * |
|
| 18 | - * @param string|array $value Value to format. |
|
| 19 | - * @param array $options Options that influence the formatting. |
|
| 20 | - * @return string |
|
| 21 | - */ |
|
| 22 | - public function format( $value, array $options = [] ) { |
|
| 23 | - if ( is_array( $value ) ) { |
|
| 24 | - return array_map( [ $this, 'format' ], $value ); |
|
| 25 | - } |
|
| 26 | - return is_scalar( $value ) ? wp_kses_post( trim( convert_chars( wptexturize( $value ) ) ) ) : $value; |
|
| 27 | - } |
|
| 12 | + /** |
|
| 13 | + * Format a given value and return the result. |
|
| 14 | + * |
|
| 15 | + * The wptexturize, convert_chars, and trim functions are also used in the `the_title` filter. |
|
| 16 | + * The function wp_kses_post removes disallowed HTML tags. |
|
| 17 | + * |
|
| 18 | + * @param string|array $value Value to format. |
|
| 19 | + * @param array $options Options that influence the formatting. |
|
| 20 | + * @return string |
|
| 21 | + */ |
|
| 22 | + public function format( $value, array $options = [] ) { |
|
| 23 | + if ( is_array( $value ) ) { |
|
| 24 | + return array_map( [ $this, 'format' ], $value ); |
|
| 25 | + } |
|
| 26 | + return is_scalar( $value ) ? wp_kses_post( trim( convert_chars( wptexturize( $value ) ) ) ) : $value; |
|
| 27 | + } |
|
| 28 | 28 | } |
@@ -19,10 +19,10 @@ |
||
| 19 | 19 | * @param array $options Options that influence the formatting. |
| 20 | 20 | * @return string |
| 21 | 21 | */ |
| 22 | - public function format( $value, array $options = [] ) { |
|
| 23 | - if ( is_array( $value ) ) { |
|
| 24 | - return array_map( [ $this, 'format' ], $value ); |
|
| 22 | + public function format($value, array $options = []) { |
|
| 23 | + if (is_array($value)) { |
|
| 24 | + return array_map([$this, 'format'], $value); |
|
| 25 | 25 | } |
| 26 | - return is_scalar( $value ) ? wp_kses_post( trim( convert_chars( wptexturize( $value ) ) ) ) : $value; |
|
| 26 | + return is_scalar($value) ? wp_kses_post(trim(convert_chars(wptexturize($value)))) : $value; |
|
| 27 | 27 | } |
| 28 | 28 | } |
@@ -7,28 +7,28 @@ |
||
| 7 | 7 | * Formats monetary values using store settings. |
| 8 | 8 | */ |
| 9 | 9 | class MoneyFormatter implements FormatterInterface { |
| 10 | - /** |
|
| 11 | - * Format a given value and return the result. |
|
| 12 | - * |
|
| 13 | - * @param mixed $value Value to format. |
|
| 14 | - * @param array $options Options that influence the formatting. |
|
| 15 | - * @return mixed |
|
| 16 | - */ |
|
| 17 | - public function format( $value, array $options = [] ) { |
|
| 18 | - $options = wp_parse_args( |
|
| 19 | - $options, |
|
| 20 | - [ |
|
| 21 | - 'decimals' => wc_get_price_decimals(), |
|
| 22 | - 'rounding_mode' => PHP_ROUND_HALF_UP, |
|
| 23 | - ] |
|
| 24 | - ); |
|
| 10 | + /** |
|
| 11 | + * Format a given value and return the result. |
|
| 12 | + * |
|
| 13 | + * @param mixed $value Value to format. |
|
| 14 | + * @param array $options Options that influence the formatting. |
|
| 15 | + * @return mixed |
|
| 16 | + */ |
|
| 17 | + public function format( $value, array $options = [] ) { |
|
| 18 | + $options = wp_parse_args( |
|
| 19 | + $options, |
|
| 20 | + [ |
|
| 21 | + 'decimals' => wc_get_price_decimals(), |
|
| 22 | + 'rounding_mode' => PHP_ROUND_HALF_UP, |
|
| 23 | + ] |
|
| 24 | + ); |
|
| 25 | 25 | |
| 26 | - return (string) intval( |
|
| 27 | - round( |
|
| 28 | - ( (float) wc_format_decimal( $value ) ) * ( 10 ** absint( $options['decimals'] ) ), |
|
| 29 | - 0, |
|
| 30 | - absint( $options['rounding_mode'] ) |
|
| 31 | - ) |
|
| 32 | - ); |
|
| 33 | - } |
|
| 26 | + return (string) intval( |
|
| 27 | + round( |
|
| 28 | + ( (float) wc_format_decimal( $value ) ) * ( 10 ** absint( $options['decimals'] ) ), |
|
| 29 | + 0, |
|
| 30 | + absint( $options['rounding_mode'] ) |
|
| 31 | + ) |
|
| 32 | + ); |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * @param array $options Options that influence the formatting. |
| 15 | 15 | * @return mixed |
| 16 | 16 | */ |
| 17 | - public function format( $value, array $options = [] ) { |
|
| 17 | + public function format($value, array $options = []) { |
|
| 18 | 18 | $options = wp_parse_args( |
| 19 | 19 | $options, |
| 20 | 20 | [ |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | return (string) intval( |
| 27 | 27 | round( |
| 28 | - ( (float) wc_format_decimal( $value ) ) * ( 10 ** absint( $options['decimals'] ) ), |
|
| 28 | + ((float) wc_format_decimal($value)) * (10 ** absint($options['decimals'])), |
|
| 29 | 29 | 0, |
| 30 | - absint( $options['rounding_mode'] ) |
|
| 30 | + absint($options['rounding_mode']) |
|
| 31 | 31 | ) |
| 32 | 32 | ); |
| 33 | 33 | } |
@@ -9,61 +9,61 @@ |
||
| 9 | 9 | * Legacy class. |
| 10 | 10 | */ |
| 11 | 11 | class Legacy { |
| 12 | - /** |
|
| 13 | - * Hook into WP lifecycle events. |
|
| 14 | - */ |
|
| 15 | - public function init() { |
|
| 16 | - add_action( 'woocommerce_rest_checkout_process_payment_with_context', array( $this, 'process_legacy_payment' ), 999, 2 ); |
|
| 17 | - } |
|
| 12 | + /** |
|
| 13 | + * Hook into WP lifecycle events. |
|
| 14 | + */ |
|
| 15 | + public function init() { |
|
| 16 | + add_action( 'woocommerce_rest_checkout_process_payment_with_context', array( $this, 'process_legacy_payment' ), 999, 2 ); |
|
| 17 | + } |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Attempt to process a payment for the checkout API if no payment methods support the |
|
| 21 | - * woocommerce_rest_checkout_process_payment_with_context action. |
|
| 22 | - * |
|
| 23 | - * @param PaymentContext $context Holds context for the payment. |
|
| 24 | - * @param PaymentResult $result Result of the payment. |
|
| 25 | - */ |
|
| 26 | - public function process_legacy_payment( PaymentContext $context, PaymentResult &$result ) { |
|
| 27 | - if ( $result->status ) { |
|
| 28 | - return; |
|
| 29 | - } |
|
| 19 | + /** |
|
| 20 | + * Attempt to process a payment for the checkout API if no payment methods support the |
|
| 21 | + * woocommerce_rest_checkout_process_payment_with_context action. |
|
| 22 | + * |
|
| 23 | + * @param PaymentContext $context Holds context for the payment. |
|
| 24 | + * @param PaymentResult $result Result of the payment. |
|
| 25 | + */ |
|
| 26 | + public function process_legacy_payment( PaymentContext $context, PaymentResult &$result ) { |
|
| 27 | + if ( $result->status ) { |
|
| 28 | + return; |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - // phpcs:ignore WordPress.Security.NonceVerification |
|
| 32 | - $post_data = $_POST; |
|
| 31 | + // phpcs:ignore WordPress.Security.NonceVerification |
|
| 32 | + $post_data = $_POST; |
|
| 33 | 33 | |
| 34 | - // Set constants. |
|
| 35 | - wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 34 | + // Set constants. |
|
| 35 | + wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 36 | 36 | |
| 37 | - // Add the payment data from the API to the POST global. |
|
| 38 | - $_POST = $context->payment_data; |
|
| 37 | + // Add the payment data from the API to the POST global. |
|
| 38 | + $_POST = $context->payment_data; |
|
| 39 | 39 | |
| 40 | - // Call the process payment method of the chosen gateway. |
|
| 41 | - $payment_method_object = $context->get_payment_method_instance(); |
|
| 40 | + // Call the process payment method of the chosen gateway. |
|
| 41 | + $payment_method_object = $context->get_payment_method_instance(); |
|
| 42 | 42 | |
| 43 | - if ( ! $payment_method_object instanceof \WC_Payment_Gateway ) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 43 | + if ( ! $payment_method_object instanceof \WC_Payment_Gateway ) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - $payment_method_object->validate_fields(); |
|
| 47 | + $payment_method_object->validate_fields(); |
|
| 48 | 48 | |
| 49 | - // If errors were thrown, we need to abort. |
|
| 50 | - NoticeHandler::convert_notices_to_exceptions( 'woocommerce_rest_payment_error' ); |
|
| 49 | + // If errors were thrown, we need to abort. |
|
| 50 | + NoticeHandler::convert_notices_to_exceptions( 'woocommerce_rest_payment_error' ); |
|
| 51 | 51 | |
| 52 | - // Process Payment. |
|
| 53 | - $gateway_result = $payment_method_object->process_payment( $context->order->get_id() ); |
|
| 52 | + // Process Payment. |
|
| 53 | + $gateway_result = $payment_method_object->process_payment( $context->order->get_id() ); |
|
| 54 | 54 | |
| 55 | - // Restore $_POST data. |
|
| 56 | - $_POST = $post_data; |
|
| 55 | + // Restore $_POST data. |
|
| 56 | + $_POST = $post_data; |
|
| 57 | 57 | |
| 58 | - // If `process_payment` added notices, clear them. Notices are not displayed from the API -- payment should fail, |
|
| 59 | - // and a generic notice will be shown instead if payment failed. |
|
| 60 | - wc_clear_notices(); |
|
| 58 | + // If `process_payment` added notices, clear them. Notices are not displayed from the API -- payment should fail, |
|
| 59 | + // and a generic notice will be shown instead if payment failed. |
|
| 60 | + wc_clear_notices(); |
|
| 61 | 61 | |
| 62 | - // Handle result. |
|
| 63 | - $result->set_status( isset( $gateway_result['result'] ) && 'success' === $gateway_result['result'] ? 'success' : 'failure' ); |
|
| 62 | + // Handle result. |
|
| 63 | + $result->set_status( isset( $gateway_result['result'] ) && 'success' === $gateway_result['result'] ? 'success' : 'failure' ); |
|
| 64 | 64 | |
| 65 | - // set payment_details from result. |
|
| 66 | - $result->set_payment_details( array_merge( $result->payment_details, $gateway_result ) ); |
|
| 67 | - $result->set_redirect_url( $gateway_result['redirect'] ); |
|
| 68 | - } |
|
| 65 | + // set payment_details from result. |
|
| 66 | + $result->set_payment_details( array_merge( $result->payment_details, $gateway_result ) ); |
|
| 67 | + $result->set_redirect_url( $gateway_result['redirect'] ); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * Hook into WP lifecycle events. |
| 14 | 14 | */ |
| 15 | 15 | public function init() { |
| 16 | - add_action( 'woocommerce_rest_checkout_process_payment_with_context', array( $this, 'process_legacy_payment' ), 999, 2 ); |
|
| 16 | + add_action('woocommerce_rest_checkout_process_payment_with_context', array($this, 'process_legacy_payment'), 999, 2); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -23,8 +23,8 @@ discard block |
||
| 23 | 23 | * @param PaymentContext $context Holds context for the payment. |
| 24 | 24 | * @param PaymentResult $result Result of the payment. |
| 25 | 25 | */ |
| 26 | - public function process_legacy_payment( PaymentContext $context, PaymentResult &$result ) { |
|
| 27 | - if ( $result->status ) { |
|
| 26 | + public function process_legacy_payment(PaymentContext $context, PaymentResult & $result) { |
|
| 27 | + if ($result->status) { |
|
| 28 | 28 | return; |
| 29 | 29 | } |
| 30 | 30 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | $post_data = $_POST; |
| 33 | 33 | |
| 34 | 34 | // Set constants. |
| 35 | - wc_maybe_define_constant( 'WOOCOMMERCE_CHECKOUT', true ); |
|
| 35 | + wc_maybe_define_constant('WOOCOMMERCE_CHECKOUT', true); |
|
| 36 | 36 | |
| 37 | 37 | // Add the payment data from the API to the POST global. |
| 38 | 38 | $_POST = $context->payment_data; |
@@ -40,17 +40,17 @@ discard block |
||
| 40 | 40 | // Call the process payment method of the chosen gateway. |
| 41 | 41 | $payment_method_object = $context->get_payment_method_instance(); |
| 42 | 42 | |
| 43 | - if ( ! $payment_method_object instanceof \WC_Payment_Gateway ) { |
|
| 43 | + if (!$payment_method_object instanceof \WC_Payment_Gateway) { |
|
| 44 | 44 | return; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | $payment_method_object->validate_fields(); |
| 48 | 48 | |
| 49 | 49 | // If errors were thrown, we need to abort. |
| 50 | - NoticeHandler::convert_notices_to_exceptions( 'woocommerce_rest_payment_error' ); |
|
| 50 | + NoticeHandler::convert_notices_to_exceptions('woocommerce_rest_payment_error'); |
|
| 51 | 51 | |
| 52 | 52 | // Process Payment. |
| 53 | - $gateway_result = $payment_method_object->process_payment( $context->order->get_id() ); |
|
| 53 | + $gateway_result = $payment_method_object->process_payment($context->order->get_id()); |
|
| 54 | 54 | |
| 55 | 55 | // Restore $_POST data. |
| 56 | 56 | $_POST = $post_data; |
@@ -60,10 +60,10 @@ discard block |
||
| 60 | 60 | wc_clear_notices(); |
| 61 | 61 | |
| 62 | 62 | // Handle result. |
| 63 | - $result->set_status( isset( $gateway_result['result'] ) && 'success' === $gateway_result['result'] ? 'success' : 'failure' ); |
|
| 63 | + $result->set_status(isset($gateway_result['result']) && 'success' === $gateway_result['result'] ? 'success' : 'failure'); |
|
| 64 | 64 | |
| 65 | 65 | // set payment_details from result. |
| 66 | - $result->set_payment_details( array_merge( $result->payment_details, $gateway_result ) ); |
|
| 67 | - $result->set_redirect_url( $gateway_result['redirect'] ); |
|
| 66 | + $result->set_payment_details(array_merge($result->payment_details, $gateway_result)); |
|
| 67 | + $result->set_redirect_url($gateway_result['redirect']); |
|
| 68 | 68 | } |
| 69 | 69 | } |
@@ -5,17 +5,17 @@ |
||
| 5 | 5 | * RouteInterface. |
| 6 | 6 | */ |
| 7 | 7 | interface RouteInterface { |
| 8 | - /** |
|
| 9 | - * Get the path of this REST route. |
|
| 10 | - * |
|
| 11 | - * @return string |
|
| 12 | - */ |
|
| 13 | - public function get_path(); |
|
| 8 | + /** |
|
| 9 | + * Get the path of this REST route. |
|
| 10 | + * |
|
| 11 | + * @return string |
|
| 12 | + */ |
|
| 13 | + public function get_path(); |
|
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Get arguments for this REST route. |
|
| 17 | - * |
|
| 18 | - * @return array An array of endpoints. |
|
| 19 | - */ |
|
| 20 | - public function get_args(); |
|
| 15 | + /** |
|
| 16 | + * Get arguments for this REST route. |
|
| 17 | + * |
|
| 18 | + * @return array An array of endpoints. |
|
| 19 | + */ |
|
| 20 | + public function get_args(); |
|
| 21 | 21 | } |