Skip to content

Commit

Permalink
Merge branch 'master' into pickup-delivery
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisnissle authored Apr 9, 2024
2 parents ffacbd8 + 8ee78db commit 218399b
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 163 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "woocommerce-germanized-shipments",
"title": "Shipments for WooCommerce",
"version": "3.0.5",
"version": "3.1.1",
"homepage": "https://vendidero.de",
"repository": {
"type": "git",
Expand Down
3 changes: 1 addition & 2 deletions src/Automation.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,12 +220,11 @@ public static function create_shipments( $order ) {

if ( $order_shipment = wc_gzd_get_shipment_order( $order ) ) {
/**
* Sync existing shipments and items before creating new shipments
* Sync existing shipments before creating new shipments
*/
foreach ( $order_shipment->get_simple_shipments() as $shipment ) {
if ( $shipment->is_editable() ) {
$shipment->sync();
$shipment->sync_items();
$shipment->save();
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Package {
*
* @var string
*/
const VERSION = '3.0.5';
const VERSION = '3.1.1';

public static $upload_dir_suffix = '';

Expand Down Expand Up @@ -424,11 +424,15 @@ public static function register_endpoints( $query_vars ) {

public static function install() {
self::init();

if ( ! self::has_dependencies() ) {
return;
}

Install::install();
}

public static function install_integration() {
self::init();
self::install();
}

Expand Down Expand Up @@ -478,6 +482,14 @@ protected static function generate_key() {
return md5( serialize( $key ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize
}

public static function is_shipping_debug_mode() {
return apply_filters( 'woocommerce_gzd_shipments_is_shipping_debug_mode', 'yes' === get_option( 'woocommerce_shipping_debug_mode', 'no' ) );
}

public static function is_constant_defined( $constant ) {
return class_exists( 'Automattic\Jetpack\Constants' ) ? \Automattic\Jetpack\Constants::is_defined( $constant ) : defined( $constant );
}

public static function log( $message, $type = 'info', $source = '' ) {
$enable_logging = defined( 'WP_DEBUG' ) && WP_DEBUG ? true : false;

Expand Down
10 changes: 9 additions & 1 deletion src/Packaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,12 @@ public function has_inner_dimensions() {
return ! empty( $this->get_inner_width( 'edit' ) ) || ! empty( $this->get_inner_length( 'edit' ) ) || ! empty( $this->get_inner_height( 'edit' ) );
}

public function has_shipping_class_restrictions() {
$classes = $this->get_available_shipping_classes( 'edit' );

return ! empty( $classes ) ? true : false;
}

/**
* Returns the available shipping provider names.
*
Expand Down Expand Up @@ -315,7 +321,9 @@ public function supports_shipping_class( $shipping_class ) {
$classes = $this->get_available_shipping_classes( 'edit' );
$supports = false;

if ( empty( $classes ) || in_array( $shipping_class, $classes, true ) ) {
if ( empty( $shipping_class ) && empty( $classes ) ) {
$supports = true;
} elseif ( empty( $classes ) || in_array( $shipping_class, $classes, true ) ) {
$supports = true;
}

Expand Down
3 changes: 1 addition & 2 deletions src/Packing/CartItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ public function __construct( $item, $incl_taxes = false ) {
$line_subtotal += (int) wc_add_number_precision( $this->item['line_subtotal_tax'] );
}

$this->weight = (int) wc_get_weight( $weight, 'g' );

$this->weight = (int) wc_get_weight( $weight, 'g' );
$this->total = $quantity > 0 ? NumberUtil::round( $line_total / $quantity ) : 0;
$this->subtotal = $quantity > 0 ? NumberUtil::round( $line_subtotal / $quantity ) : 0;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Packing/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function canBePacked( $box, $already_packed_items, int $proposed_x, int $
if ( $product = $this->get_product() ) {
$shipping_class = $product->get_shipping_class_id();

if ( ! empty( $shipping_class ) ) {
if ( $box->get_packaging()->has_shipping_class_restrictions() ) {
if ( ! $box->get_packaging()->supports_shipping_class( $shipping_class ) ) {
$fits = false;
}
Expand Down
36 changes: 22 additions & 14 deletions src/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,17 @@ public function get_shipping_zone() {
}

public function is_shipping_domestic() {
return Package::is_shipping_domestic(
$this->get_country(),
array(
'sender_country' => $this->get_sender_country(),
'sender_postcode' => $this->get_sender_postcode(),
'postcode' => $this->get_postcode(),
)
return apply_filters(
"{$this->get_general_hook_prefix()}is_shipping_domestic",
Package::is_shipping_domestic(
$this->get_country(),
array(
'sender_country' => $this->get_sender_country(),
'sender_postcode' => $this->get_sender_postcode(),
'postcode' => $this->get_postcode(),
)
),
$this
);
}

Expand All @@ -290,13 +294,17 @@ public function is_shipping_domestic() {
* @return bool
*/
public function is_shipping_inner_eu() {
if ( Package::is_shipping_inner_eu_country(
$this->get_country(),
array(
'sender_country' => $this->get_sender_country(),
'sender_postcode' => $this->get_sender_postcode(),
'postcode' => $this->get_postcode(),
)
if ( apply_filters(
"{$this->get_general_hook_prefix()}is_shipping_inner_eu",
Package::is_shipping_inner_eu_country(
$this->get_country(),
array(
'sender_country' => $this->get_sender_country(),
'sender_postcode' => $this->get_sender_postcode(),
'postcode' => $this->get_postcode(),
)
),
$this
) ) {
return true;
}
Expand Down
Loading

0 comments on commit 218399b

Please sign in to comment.