Skip to content

Commit

Permalink
Use a more general export reference number approach instead of the (E…
Browse files Browse the repository at this point in the history
…U-specific) master reference number.
  • Loading branch information
dennisnissle committed May 22, 2024
1 parent 3caae11 commit 2deb2ba
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/DataStores/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class Label extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface {
'_height',
'_created_via',
'_print_format',
'_master_reference_number',
'_export_reference_number',
);

/*
Expand Down
2 changes: 1 addition & 1 deletion src/Interfaces/ShipmentLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function get_services();

public function get_print_format();

public function get_master_reference_number();
public function get_export_reference_number();

/**
* Returns the label shipment type, e.g. simple or return.
Expand Down
12 changes: 6 additions & 6 deletions src/Labels/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Label extends WC_Data implements ShipmentLabel {
'created_via' => '',
'services' => array(),
'print_format' => '',
'master_reference_number' => '',
'export_reference_number' => '',
);

public function __construct( $data = 0 ) {
Expand Down Expand Up @@ -196,8 +196,8 @@ public function get_print_format( $context = 'view' ) {
return $this->get_prop( 'print_format', $context );
}

public function get_master_reference_number( $context = 'view' ) {
return $this->get_prop( 'master_reference_number', $context );
public function get_export_reference_number( $context = 'view' ) {
return $this->get_prop( 'export_reference_number', $context );
}

public function has_number() {
Expand Down Expand Up @@ -344,8 +344,8 @@ public function set_print_format( $format ) {
$this->set_prop( 'print_format', $format );
}

public function set_master_reference_number( $ref_number ) {
$this->set_prop( 'master_reference_number', $ref_number );
public function set_export_reference_number( $ref_number ) {
$this->set_prop( 'export_reference_number', $ref_number );
}

public function set_shipping_provider( $slug ) {
Expand Down Expand Up @@ -858,7 +858,7 @@ public function get_customs_data( $max_desc_length = 255 ) {
'shipment_id' => $shipment->get_id(),
'additional_fee' => wc_format_decimal( $shipment->get_additional_total(), 2 ),
'place_of_commital' => $shipment->get_sender_city(),
'master_reference_number' => $this->get_master_reference_number(),
'export_reference_number' => $this->get_export_reference_number(),
// e.g. EORI number
'sender_customs_ref_number' => $shipment->get_sender_customs_reference_number(),
'receiver_customs_ref_number' => $shipment->get_customs_reference_number(),
Expand Down
4 changes: 2 additions & 2 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,10 @@ public static function country_belongs_to_eu_customs_area( $country, $postcode =
return apply_filters( 'woocommerce_gzd_country_belongs_to_eu_customs_area', $belongs, $country, $postcode );
}

public static function base_country_supports_master_reference_number() {
public static function base_country_supports_export_reference_number() {
$base_country = self::get_base_country();

return apply_filters( 'woocommerce_gzd_base_country_supports_master_reference_number', self::country_belongs_to_eu_customs_area( $base_country ) );
return apply_filters( 'woocommerce_gzd_base_country_supports_export_reference_number', self::country_belongs_to_eu_customs_area( $base_country ) );
}

public static function is_shipping_international( $country, $args = array() ) {
Expand Down
12 changes: 8 additions & 4 deletions src/ShippingProvider/Auto.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,14 +804,14 @@ protected function get_simple_label_fields( $shipment ) {
);
}

if ( $shipment->is_shipping_international() && Package::base_country_supports_master_reference_number() ) {
if ( $this->label_supports_export_reference_number( $shipment ) ) {
$settings = array_merge(
$settings,
array(
array(
'id' => 'master_reference_number',
'label' => _x( 'Master Reference Number', 'shipments', 'woocommerce-germanized-shipments' ),
'description' => _x( 'In case of a shipment with an export declaration (e.g. value of goods > 1000 EUR) - provide the assigned Master Reference Number (MRN) for customs purposes.', 'shipments', 'woocommerce-germanized-shipments' ),
'id' => 'export_reference_number',
'label' => _x( 'Export Reference Number', 'shipments', 'woocommerce-germanized-shipments' ),
'description' => _x( 'In case of a shipment with an export declaration - provide the assigned Export Reference Number for customs purposes.', 'shipments', 'woocommerce-germanized-shipments' ),
'value' => '',
'type' => 'text',
'desc_tip' => true,
Expand All @@ -823,6 +823,10 @@ protected function get_simple_label_fields( $shipment ) {
return $settings;
}

protected function label_supports_export_reference_number( $shipment ) {
return apply_filters( "{$this->get_general_hook_prefix()}supports_export_reference_number", false, $shipment, $this );
}

/**
* @param \Vendidero\Germanized\Shipments\Shipment $shipment
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ShippingProvider/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function get_setting_fields( $configuration_set ) {
array(
array(
'title' => $this->get_label(),
'desc' => $this->get_description() . ( ! empty( $this->get_long_description() ) ? ' ' . $this->get_long_description() : '' ),
'desc' => $this->get_description() . ( ! empty( $this->get_long_description() ) ? ' <div class="wc-gzd-additional-desc">' . $this->get_long_description() . '</div>' : '' ),
'id' => $setting_id,
'value' => $value,
'default' => $this->get_default_value(),
Expand Down

0 comments on commit 2deb2ba

Please sign in to comment.