@@ -232,45 +232,13 @@ protected function get_store_currency_properties() {
232232 }
233233
234234 /**
235- * Prepares a list of store currency data to return in responses .
235+ * Adds currency data to an array of monetary values .
236236 *
237- * @todo Core could use a more defined currency object format, making use of
238- * constants for currency format rather than strings, and holding this type
239- * of information instead of plugins/blocks needed to normalize things
240- * themselves.
241- *
242- * @return array
237+ * @param array $values Monetary amounts.
238+ * @return array Monetary amounts with currency data appended.
243239 */
244- protected function get_store_currency_response () {
245- $ position = get_option ( 'woocommerce_currency_pos ' );
246- $ symbol = html_entity_decode ( get_woocommerce_currency_symbol () );
247- $ prefix = '' ;
248- $ suffix = '' ;
249-
250- switch ( $ position ) {
251- case 'left_space ' :
252- $ prefix = $ symbol . ' ' ;
253- break ;
254- case 'left ' :
255- $ prefix = $ symbol ;
256- break ;
257- case 'right_space ' :
258- $ suffix = ' ' . $ symbol ;
259- break ;
260- case 'right ' :
261- $ suffix = $ symbol ;
262- break ;
263- }
264-
265- return [
266- 'currency_code ' => get_woocommerce_currency (),
267- 'currency_symbol ' => $ symbol ,
268- 'currency_minor_unit ' => wc_get_price_decimals (),
269- 'currency_decimal_separator ' => wc_get_price_decimal_separator (),
270- 'currency_thousand_separator ' => wc_get_price_thousand_separator (),
271- 'currency_prefix ' => $ prefix ,
272- 'currency_suffix ' => $ suffix ,
273- ];
240+ protected function prepare_currency_response ( $ values ) {
241+ return $ this ->extend ->get_formatter ( 'currency ' )->format ( $ values );
274242 }
275243
276244 /**
@@ -283,28 +251,22 @@ protected function get_store_currency_response() {
283251 * @return string The new amount.
284252 */
285253 protected function prepare_money_response ( $ amount , $ decimals = 2 , $ rounding_mode = PHP_ROUND_HALF_UP ) {
286- return ( string ) intval (
287- round (
288- ( ( float ) wc_format_decimal ( $ amount ) ) * ( 10 ** $ decimals ),
289- 0 ,
290- absint ( $ rounding_mode )
291- )
254+ return $ this -> extend -> get_formatter ( ' money ' )-> format (
255+ $ amount ,
256+ [
257+ ' decimals ' => $ decimals ,
258+ ' rounding_mode ' => $ rounding_mode,
259+ ]
292260 );
293261 }
294262
295263 /**
296264 * Prepares HTML based content, such as post titles and content, for the API response.
297265 *
298- * The wptexturize, convert_chars, and trim functions are also used in the `the_title` filter.
299- * The function wp_kses_post removes disallowed HTML tags.
300- *
301266 * @param string|array $response Data to format.
302267 * @return string|array Formatted data.
303268 */
304269 protected function prepare_html_response ( $ response ) {
305- if ( is_array ( $ response ) ) {
306- return array_map ( [ $ this , 'prepare_html_response ' ], $ response );
307- }
308- return is_scalar ( $ response ) ? wp_kses_post ( trim ( convert_chars ( wptexturize ( $ response ) ) ) ) : $ response ;
270+ return $ this ->extend ->get_formatter ( 'html ' )->format ( $ response );
309271 }
310272}
0 commit comments