Skip to content

Commit

Permalink
New: updates sabre/xml library to version 4 (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmigf authored Oct 18, 2024
1 parent 78b74fb commit 1363b1a
Show file tree
Hide file tree
Showing 48 changed files with 574 additions and 462 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dompdf/dompdf": "^3.0",
"symfony/polyfill-mbstring": "^1.27",
"symfony/polyfill-iconv": "^1.27",
"sabre/xml": "^2.2.5"
"sabre/xml": "^4.0"
},
"extra": {
"strauss": {
Expand Down
70 changes: 35 additions & 35 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions includes/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function add_listing_actions( $order ) {
}
break;
case 'ubl':
if ( $document->is_enabled( $output_format ) ) {
if ( $document->is_enabled( $output_format ) && wcpdf_is_ubl_available() ) {
$document_url = WPO_WCPDF()->endpoint->get_document_link( $order, $document->get_type(), array( 'output' => $output_format ) );
$document_title = is_callable( array( $document, 'get_title' ) ) ? $document->get_title() : $document_title;
$document_exists = is_callable( array( $document, 'exists' ) ) ? $document->exists() : false;
Expand Down Expand Up @@ -669,7 +669,7 @@ public function ubl_actions_meta_box( $post_or_order_object ) {
}

$meta_box_actions = apply_filters( 'wpo_wcpdf_ubl_meta_box_actions', $meta_box_actions, $order->get_id() );
if ( empty( $meta_box_actions ) ) {
if ( empty( $meta_box_actions ) || ! wcpdf_is_ubl_available() ) {
return;
}
?>
Expand Down
9 changes: 6 additions & 3 deletions includes/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,15 @@ public function settings_page() {
'title' => __( 'Documents', 'woocommerce-pdf-invoices-packing-slips' ),
'preview_states' => 3,
),
'ubl' => array(
) );

if ( wcpdf_is_ubl_available() ) {
$settings_tabs['ubl'] = array(
'title' => __( 'UBL', 'woocommerce-pdf-invoices-packing-slips' ),
'preview_states' => 1,
'beta' => true,
),
) );
);
}

// add status and upgrade tabs last in row
$settings_tabs['debug'] = array(
Expand Down
4 changes: 4 additions & 0 deletions includes/Settings/SettingsDocuments.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function output( $section ) {
<h2 class="nav-tab-wrapper">
<?php
foreach ( $section_document->output_formats as $document_output_format ) {
if ( ! wcpdf_is_ubl_available() && 'ubl' === $document_output_format ) {
continue;
}

$active = ( $output_format == $document_output_format ) || ( 'pdf' !== $output_format && ! in_array( $output_format, $section_document->output_formats ) ) ? 'nav-tab-active' : '';
$tab_title = strtoupper( esc_html( $document_output_format ) );
if ( 'ubl' === $document_output_format ) {
Expand Down
35 changes: 18 additions & 17 deletions ubl/Handlers/Common/AddressHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,7 @@ public function return_supplier_party_details() {
),
);
}

$supplierPartyDetails[] = array(
'name' => 'cac:Contact',
'value' => array(
array(
'name' => 'cbc:ElectronicMail',
'value' => get_option( 'woocommerce_email_from_address' ),
),
),
);


if ( ! empty( $company ) && ! empty( $coc_number ) ) {
$supplierPartyDetails[] = array(
'name' => 'cac:PartyLegalEntity',
Expand All @@ -146,6 +136,17 @@ public function return_supplier_party_details() {
),
);
}

$supplierPartyDetails[] = array(
'name' => 'cac:Contact',
'value' => array(
array(
'name' => 'cbc:ElectronicMail',
'value' => get_option( 'woocommerce_email_from_address' ),
),
),
);

return $supplierPartyDetails;
}

Expand All @@ -167,16 +168,16 @@ public function return_customer_party( $data, $options = array() ) {
);

foreach ( $vat_meta_keys as $meta_key ) {
$vat_number = wpo_wcpdf_sanitize_html_content( $this->document->order->get_meta( $meta_key ), 'vat_number' );
$vat_number = $this->document->order->get_meta( $meta_key );

if ( $vat_number ) {
break;
}
}
}

$customerPartyName = $customerPartyContactName = wpo_wcpdf_sanitize_html_content( $this->document->order->get_formatted_billing_full_name(), 'full_name' );
$billing_company = wpo_wcpdf_sanitize_html_content( $this->document->order->get_billing_company(), 'company' );
$customerPartyName = $customerPartyContactName = $this->document->order->get_formatted_billing_full_name();
$billing_company = $this->document->order->get_billing_company();

if ( ! empty( $billing_company ) ) {
// $customerPartyName = "{$billing_company} ({$customerPartyName})";
Expand Down Expand Up @@ -207,11 +208,11 @@ public function return_customer_party( $data, $options = array() ) {
'value' => array(
array(
'name' => 'cbc:StreetName',
'value' => wpo_wcpdf_sanitize_html_content( $this->document->order->get_billing_address_1(), 'address_1' ),
'value' => $this->document->order->get_billing_address_1(),
),
array(
'name' => 'cbc:CityName',
'value' => wpo_wcpdf_sanitize_html_content( $this->document->order->get_billing_city(), 'city' ),
'value' => $this->document->order->get_billing_city(),
),
array(
'name' => 'cbc:PostalZone',
Expand All @@ -221,7 +222,7 @@ public function return_customer_party( $data, $options = array() ) {
'name' => 'cac:AddressLine',
'value' => array(
'name' => 'cbc:Line',
'value' => wpo_wcpdf_sanitize_html_content( $this->document->order->get_billing_address_1(), 'address_1' ) . '<br/>' . wpo_wcpdf_sanitize_html_content( $this->document->order->get_billing_address_2(), 'address_2' ),
'value' => $this->document->order->get_billing_address_1() . '<br/>' . $this->document->order->get_billing_address_2(),
),
),
array(
Expand Down
4 changes: 2 additions & 2 deletions ubl/Handlers/Common/TaxTotalHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public function handle( $data, $options = array() ) {
'value' => array(
array(
'name' => 'cbc:TaxableAmount',
'value' => round( $item['total_ex'], 2 ),
'value' => wc_round_tax_total( $item['total_ex'] ),
'attributes' => array(
'currencyID' => $this->document->order->get_currency(),
),
),
array(
'name' => 'cbc:TaxAmount',
'value' => round( $item['total_tax'], 2 ),
'value' => wc_round_tax_total( $item['total_tax'] ),
'attributes' => array(
'currencyID' => $this->document->order->get_currency(),
),
Expand Down
9 changes: 5 additions & 4 deletions ubl/Handlers/Invoice/InvoiceLineHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace WPO\IPS\UBL\Handlers\Invoice;

use WPO\IPS\UBL\Handlers\UblHandler;
use Automattic\WooCommerce\Utilities\NumberUtil;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
Expand Down Expand Up @@ -33,14 +34,14 @@ public function handle( $data, $options = array() ) {
'value' => array(
array(
'name' => 'cbc:TaxableAmount',
'value' => round( $item[ $lineTotalKey ], 2 ),
'value' => wc_round_tax_total( $item[ $lineTotalKey ] ),
'attributes' => array(
'currencyID' => $this->document->order->get_currency(),
),
),
array(
'name' => 'cbc:TaxAmount',
'value' => round( $tax, 2 ),
'value' => wc_round_tax_total( $tax ),
'attributes' => array(
'currencyID' => $this->document->order->get_currency(),
),
Expand Down Expand Up @@ -88,7 +89,7 @@ public function handle( $data, $options = array() ) {
),
array(
'name' => 'cbc:LineExtensionAmount',
'value' => round( $item->get_total(), 2 ),
'value' => NumberUtil::round( $item->get_total(), wc_get_price_decimals() ),
'attributes' => array(
'currencyID' => $this->document->order->get_currency(),
),
Expand All @@ -98,7 +99,7 @@ public function handle( $data, $options = array() ) {
'value' => array(
array(
'name' => 'cbc:TaxAmount',
'value' => round( $item->get_total_tax(), 2),
'value' => wc_round_tax_total( $item->get_total_tax() ),
'attributes' => array(
'currencyID' => $this->document->order->get_currency(),
),
Expand Down
10 changes: 5 additions & 5 deletions ubl/Transformers/AddressTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class AddressTransformer {
*/
public function transform( \WC_Abstract_Order $item, $billing_or_shipping ) {
$model = new Address();
$model->address_1 = wpo_wcpdf_sanitize_html_content( $item->{'get_'.$billing_or_shipping.'_address_1'}(), 'address_1' );
$model->address_2 = wpo_wcpdf_sanitize_html_content( $item->{'get_'.$billing_or_shipping.'_address_2'}(), 'address_2' );
$model->first_name = wpo_wcpdf_sanitize_html_content( $item->{'get_'.$billing_or_shipping.'_first_name'}(), 'first_name' );
$model->last_name = wpo_wcpdf_sanitize_html_content( $item->{'get_'.$billing_or_shipping.'_last_name'}(), 'last_name' );
$model->city = wpo_wcpdf_sanitize_html_content( $item->{'get_'.$billing_or_shipping.'_city'}(), 'city' );
$model->address_1 = $item->{'get_'.$billing_or_shipping.'_address_1'}();
$model->address_2 = $item->{'get_'.$billing_or_shipping.'_address_2'}();
$model->first_name = $item->{'get_'.$billing_or_shipping.'_first_name'}();
$model->last_name = $item->{'get_'.$billing_or_shipping.'_last_name'}();
$model->city = $item->{'get_'.$billing_or_shipping.'_city'}();
$model->state = $item->{'get_'.$billing_or_shipping.'_state'}();
$model->postcode = $item->{'get_'.$billing_or_shipping.'_postcode'}();
$model->country = $item->{'get_'.$billing_or_shipping.'_country'}();
Expand Down
Loading

0 comments on commit 1363b1a

Please sign in to comment.