Skip to content

Commit

Permalink
Added master reference number for customs purposes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed May 14, 2024
1 parent df8c202 commit 24ac47f
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 15 deletions.
4 changes: 4 additions & 0 deletions assets/css/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ a.woocommerce-gzd-input-toggle-trigger {
.woocommerce-help-tip {
display: inline-flex;
margin-bottom: 5px;
margin-left: 3px;
margin-top: 2px;
}

select, input[type=text], input[type=email], input[type=date] {
Expand Down Expand Up @@ -1395,6 +1397,8 @@ a.button.wc-gzd-shipment-action-button {

.woocommerce-help-tip {
float: none;
margin-left: 5px;
margin-bottom: 2px;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/DataStores/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class Label extends WC_Data_Store_WP implements WC_Object_Data_Store_Interface {
'_height',
'_created_via',
'_print_format',
'_master_reference_number',
);

/*
Expand Down
2 changes: 2 additions & 0 deletions src/Interfaces/ShipmentLabel.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public function get_services();

public function get_print_format();

public function get_master_reference_number();

/**
* Returns the label shipment type, e.g. simple or return.
*
Expand Down
40 changes: 25 additions & 15 deletions src/Labels/Label.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,22 @@ class Label extends WC_Data implements ShipmentLabel {
* @var array
*/
protected $data = array(
'date_created' => null,
'shipment_id' => 0,
'product_id' => '',
'parent_id' => 0,
'number' => '',
'shipping_provider' => '',
'weight' => '',
'net_weight' => '',
'length' => '',
'width' => '',
'height' => '',
'path' => '',
'created_via' => '',
'services' => array(),
'print_format' => '',
'date_created' => null,
'shipment_id' => 0,
'product_id' => '',
'parent_id' => 0,
'number' => '',
'shipping_provider' => '',
'weight' => '',
'net_weight' => '',
'length' => '',
'width' => '',
'height' => '',
'path' => '',
'created_via' => '',
'services' => array(),
'print_format' => '',
'master_reference_number' => '',
);

public function __construct( $data = 0 ) {
Expand Down Expand Up @@ -195,6 +196,10 @@ 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 has_number() {
$number = $this->get_number();

Expand Down Expand Up @@ -339,6 +344,10 @@ 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_shipping_provider( $slug ) {
$this->set_prop( 'shipping_provider', $slug );
}
Expand Down Expand Up @@ -849,6 +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(),
// 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
6 changes: 6 additions & 0 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,12 @@ 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() {
$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 ) );
}

public static function is_shipping_international( $country, $args = array() ) {
$args = self::parse_location_data( $args );
/**
Expand Down
16 changes: 16 additions & 0 deletions src/ShippingProvider/Auto.php
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,22 @@ protected function get_simple_label_fields( $shipment ) {
);
}

if ( $shipment->is_shipping_international() && Package::base_country_supports_master_reference_number() ) {
$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' ),
'value' => '',
'type' => 'text',
'desc_tip' => true,
),
)
);
}

return $settings;
}

Expand Down

0 comments on commit 24ac47f

Please sign in to comment.