From 24ac47f0e16f9a54d584fb9971c23dc03fe1bb5d Mon Sep 17 00:00:00 2001 From: vendidero Date: Tue, 14 May 2024 15:44:50 +0200 Subject: [PATCH] Added master reference number for customs purposes. --- assets/css/admin.scss | 4 ++++ src/DataStores/Label.php | 1 + src/Interfaces/ShipmentLabel.php | 2 ++ src/Labels/Label.php | 40 ++++++++++++++++++++------------ src/Package.php | 6 +++++ src/ShippingProvider/Auto.php | 16 +++++++++++++ 6 files changed, 54 insertions(+), 15 deletions(-) diff --git a/assets/css/admin.scss b/assets/css/admin.scss index 020a35ab..9dcf9a4b 100644 --- a/assets/css/admin.scss +++ b/assets/css/admin.scss @@ -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] { @@ -1395,6 +1397,8 @@ a.button.wc-gzd-shipment-action-button { .woocommerce-help-tip { float: none; + margin-left: 5px; + margin-bottom: 2px; } } } diff --git a/src/DataStores/Label.php b/src/DataStores/Label.php index f5ded323..6d2b5e8e 100644 --- a/src/DataStores/Label.php +++ b/src/DataStores/Label.php @@ -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', ); /* diff --git a/src/Interfaces/ShipmentLabel.php b/src/Interfaces/ShipmentLabel.php index 758a2801..cc2b347d 100644 --- a/src/Interfaces/ShipmentLabel.php +++ b/src/Interfaces/ShipmentLabel.php @@ -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. * diff --git a/src/Labels/Label.php b/src/Labels/Label.php index febcaccc..4529fe27 100644 --- a/src/Labels/Label.php +++ b/src/Labels/Label.php @@ -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 ) { @@ -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(); @@ -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 ); } @@ -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(), diff --git a/src/Package.php b/src/Package.php index 3ba710eb..f5f82a1c 100644 --- a/src/Package.php +++ b/src/Package.php @@ -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 ); /** diff --git a/src/ShippingProvider/Auto.php b/src/ShippingProvider/Auto.php index 849ed0f7..c096f1fc 100644 --- a/src/ShippingProvider/Auto.php +++ b/src/ShippingProvider/Auto.php @@ -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; }