Skip to content

Commit

Permalink
Merge pull request #2389 from woocommerce/fix/use-lb-instead-of-lbs-b…
Browse files Browse the repository at this point in the history
…efore-sync-to-gmc

Convert `lbs` to `lb` when mapping WC products to Google products
  • Loading branch information
ianlin authored May 8, 2024
2 parents 96dba1c + bc8d13c commit b26050f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Product/WCProductAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,12 @@ protected function map_wc_shipping_weight( string $unit = 'g' ): WCProductAdapte
}

$weight = wc_get_weight( $this->wc_product->get_weight(), $unit );

// Use lb if the unit is lbs, since GMC uses lb.
if ( 'lbs' === $unit ) {
$unit = 'lb';
}

$this->setShippingWeight(
new GoogleProductShippingWeight(
[
Expand Down
22 changes: 22 additions & 0 deletions tests/Unit/Product/WCProductAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,28 @@ public function test_shipping_dimensions_and_weight_units_use_default_if_wc_opti
$this->assertEquals( 1000, $adapted_product->getShippingWeight()->getValue() );
}

public function test_shipping_weight_unit_uses_lb_if_wc_option_is_lbs() {
update_option( 'woocommerce_weight_unit', 'lbs' );

$product = WC_Helper_Product::create_simple_product(
false,
[
'height' => '3',
'length' => '4',
'width' => '5',
'weight' => '1',
]
);

$adapted_product = new WCProductAdapter(
[
'wc_product' => $product,
'targetCountry' => 'US',
]
);
$this->assertEquals( 'lb', $adapted_product->getShippingWeight()->getUnit() );
}

/**
* @param array $shipping_dimensions
*
Expand Down

0 comments on commit b26050f

Please sign in to comment.