Skip to content

Commit

Permalink
Store packaging title in shipment data.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle committed Sep 19, 2024
1 parent 63422f7 commit af272a5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/DataStores/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Shipment extends WC_Data_Store_WP implements WC_Object_Data_Store_Interfac
'_height',
'_weight',
'_packaging_weight',
'_packaging_title',
'_address',
'_total',
'_subtotal',
Expand Down
23 changes: 22 additions & 1 deletion src/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ abstract class Shipment extends WC_Data {
'height' => '',
'length' => '',
'packaging_weight' => '',
'packaging_title' => '',
'weight_unit' => '',
'dimension_unit' => '',
'country' => '',
Expand Down Expand Up @@ -486,6 +487,18 @@ public function get_packaging_weight( $context = 'view' ) {
return $weight;
}

public function get_packaging_title( $context = 'view' ) {
$title = $this->get_prop( 'packaging_title', $context );

if ( 'view' === $context && '' === $title ) {
if ( $packaging = $this->get_packaging() ) {
$title = $packaging->get_title();
}
}

return $title;
}

/**
* @return ShipmentItem[]|ItemList
*/
Expand Down Expand Up @@ -1863,6 +1876,10 @@ public function set_packaging_weight( $weight ) {
$this->set_prop( 'packaging_weight', '' === $weight ? '' : wc_format_decimal( $weight ) );
}

public function set_packaging_title( $title ) {
$this->set_prop( 'packaging_title', $title );
}

/**
* Set shipment total weight.
*
Expand Down Expand Up @@ -2092,11 +2109,15 @@ public function update_packaging() {
'length' => wc_get_dimension( $packaging->get_length( 'edit' ), $this->get_dimension_unit(), $packaging_dimension ),
'height' => wc_get_dimension( $packaging->get_height( 'edit' ), $this->get_dimension_unit(), $packaging_dimension ),
'packaging_weight' => wc_get_weight( $packaging->get_weight( 'edit' ), $this->get_weight_unit(), wc_gzd_get_packaging_weight_unit() ),
'packaging_title' => $packaging->get_title(),
);

$this->set_props( $props );
} else {
$props = array( 'packaging_weight' => '' );
$props = array(
'packaging_weight' => '',
'packaging_title' => '',
);
$changes = $this->get_changes();

/**
Expand Down

0 comments on commit af272a5

Please sign in to comment.