| 1 |
<?php |
| 2 |
/** |
| 3 |
* HTML output adapter. |
| 4 |
* |
| 5 |
* @package WCPOS\WooCommercePOS\Templates\Adapters |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WCPOS\WooCommercePOS\Templates\Adapters; |
| 9 |
|
| 10 |
use WCPOS\WooCommercePOS\Interfaces\Receipt_Output_Adapter_Interface; |
| 11 |
|
| 12 |
/** |
| 13 |
* Html_Output_Adapter class. |
| 14 |
*/ |
| 15 |
class Html_Output_Adapter implements Receipt_Output_Adapter_Interface { |
| 16 |
/** |
| 17 |
* Transform receipt payload to HTML representation. |
| 18 |
* |
| 19 |
* @param array $receipt_data Canonical payload. |
| 20 |
* @param array $context Optional context. |
| 21 |
* |
| 22 |
* @return string |
| 23 |
*/ |
| 24 |
public function transform( array $receipt_data, array $context = array() ): string { |
| 25 |
if ( isset( $context['html'] ) && \is_string( $context['html'] ) ) { |
| 26 |
return wp_kses_post( $context['html'] ); |
| 27 |
} |
| 28 |
|
| 29 |
$order_number = isset( $receipt_data['order']['number'] ) ? (string) $receipt_data['order']['number'] : ''; |
| 30 |
$total = isset( $receipt_data['totals']['total_incl'] ) ? (float) $receipt_data['totals']['total_incl'] : 0; |
| 31 |
|
| 32 |
return sprintf( |
| 33 |
'<div class="wcpos-receipt" data-order="%s"><strong>%s</strong>: %s</div>', |
| 34 |
esc_attr( $order_number ), |
| 35 |
/* translators: Short WCPOS UI label; keep concise. */ |
| 36 |
esc_html__( 'Order', 'woocommerce-pos' ), |
| 37 |
wp_kses_post( wc_price( $total ) ) |
| 38 |
); |
| 39 |
} |
| 40 |
} |
| 41 |
|