Skip to content

Commit

Permalink
Merge pull request #59 from wuunder/fix-strict-typing-error-when-weig…
Browse files Browse the repository at this point in the history
…ht-is-not-set

Fix strict typing error when weight is not set
  • Loading branch information
MarcelZijlstraWuunder authored Nov 24, 2022
2 parents f863f3b + 24a797d commit d79123a
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 114 deletions.
Binary file removed .DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).

## Released

## [2.7.25](https://github.com/wuunder/wuunder-webshopplugin-woocommerce/tag/2.7.25) - 2022-11-24

### Fixed
- Weight calculations ensure number during calculations

## [2.7.24](https://github.com/wuunder/wuunder-webshopplugin-woocommerce/tag/2.7.24) - 2022-04-19

### Fixed
Expand Down
51 changes: 27 additions & 24 deletions includes/checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function wcwp_parcelshop_html()
$tmpEnvironment = new \Wuunder\Api\Environment(get_option('wc_wuunder_api_status') === 'staging' ? 'staging' : 'production');

$baseApiUrl = substr($tmpEnvironment->getStageBaseUrl(), 0, -3);
$carrierConfigList = get_option('woocommerce_wuunder_parcelshop_settings')['select_carriers'] ? get_option('woocommerce_wuunder_parcelshop_settings')['select_carriers'] : [];
$carrierConfigList = get_option('woocommerce_wuunder_parcelshop_settings')['select_carriers'] ?? [];
$carrierList = implode(',', $carrierConfigList);
if (0 !== strlen($carrierList)) {
$availableCarriers = $carrierList;
Expand Down Expand Up @@ -112,7 +112,6 @@ function prefix_wc_rest_prepare_order_object($response, $object, $request)
$shipping_method_id = wcwp_get_filter_from_shippingmethod(reset($shipping_object)->get_method_id());
}
} catch (Exception $e) {

}
$response->data['wuunder_preferred_service_level'] = $shipping_method_id;

Expand Down Expand Up @@ -150,28 +149,34 @@ function wcwp_get_order_weight($order_id)
// Create the product
$product = $item->get_product();
// Set item weight
$weight = $product->get_weight();
$weight = floatval($product->get_weight());
$weight = empty($weight) ? 0 : $weight;
$weight_unit = get_option('woocommerce_weight_unit');
$quantity = $item['qty'];
switch ($weight_unit) {
case 'kg':
$data['weight'] = $weight * 1000;
break;
case 'g':
$data['weight'] = $weight;
break;
case 'lbs':
$data['weight'] = $weight * 0.45359237;
break;
case 'oz':
$data['weight'] = $weight * 0.0283495231;
break;
default:
$data['weight'] = $weight;
break;
$quantity = (int)$item->get_quantity();
try {
switch ($weight_unit) {
case 'kg':
$data['weight'] = $weight * 1000;
break;
case 'g':
$data['weight'] = $weight;
break;
case 'lbs':
$data['weight'] = $weight * 0.45359237;
break;
case 'oz':
$data['weight'] = $weight * 0.0283495231;
break;
default:
$data['weight'] = $weight;
break;
}
} catch (\Throwable $e) {
$data['weight'] = 0;
wcwp_log('error', 'Invalid weight value: ' . $weight);
}

$total_product_weight = $quantity * $data['weight'];
$total_product_weight = intval($quantity * $data['weight']);
$total_weight += $total_product_weight;
}
}
Expand All @@ -186,7 +191,7 @@ function wcwp_update_parcelshop_id($order_id)
{
if (!empty($_POST['parcelshop_id']) && isset($_POST['shipping_method']) && isset($_POST['shipping_method'][0]) && 'wuunder_parcelshop' === sanitize_text_field($_POST['shipping_method'][0])) {
update_post_meta($order_id, 'parcelshop_id', sanitize_text_field($_POST['parcelshop_id']));
WC()->session->__unset( 'WCWP_SELECTED_PARCELSHOP_ID' );
WC()->session->__unset('WCWP_SELECTED_PARCELSHOP_ID');
}
}

Expand All @@ -204,5 +209,3 @@ function wcwp_check_parcelshop_selection()
}
}
}

?>
42 changes: 15 additions & 27 deletions includes/wcwuunder-create.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ public function __construct()
$this->version_obj = array(
'product' => 'Woocommerce extension',
'version' => array(
'build' => '2.7.24',
'plugin' => '2.0'),
'build' => '2.7.25',
'plugin' => '2.0'
),
'platform' => array(
'name' => 'Woocommerce',
'build' => WC()->version
));
)
);
add_action('load-edit.php', array(&$this, 'wcwp_generateBookingUrl'));
add_action('woocommerce_admin_order_actions_end', array(&$this, 'wcwp_add_listing_actions'));
add_action('add_meta_boxes_shop_order', array(&$this, 'wcwp_add_meta_boxes'));
Expand All @@ -44,15 +46,12 @@ public function wcwp_sample_admin_notice__error()
$message .= '</ul>';

printf('<div class="%1$s"><p>%2$s</p></div>', $class, $message);

} elseif ('success' == isset($_GET['notice']) && $_GET['notice']) {

$class = 'notice notice-success';
$message = __('Het verzendlabel voor #' . sanitize_text_field($_GET['id']) . ' is aangemaakt', 'woocommerce-wuunder');
printf('<div class="%1$s"><p>%2$s</p></div>', $class, $message);

}

}

/**
Expand Down Expand Up @@ -268,7 +267,7 @@ public function wcwp_get_company_address()
*/
private function wcwp_get_customer_address_part($order_meta, $suffix, $prefix = null)
{
if (!is_null($prefix)){
if (!is_null($prefix)) {
if (isset($order_meta[$prefix . $suffix]) && !empty($order_meta[$prefix . $suffix][0])) {
return $order_meta[$prefix . $suffix][0];
}
Expand Down Expand Up @@ -408,17 +407,12 @@ public function wcwp_add_listing_actions($order)
echo '<div style="clear:both;">';
foreach ($listing_actions as $action => $data) {
$target = ' target="_blank" ';
?>
<a
<?php
echo $target; ?>href=" <?php echo $data['url']; ?>"
class="<?php echo $action; ?> button tips <?php echo $action; ?>"
style="background:#8dcc00; height:2em; width:2em; padding:3px;"
alt="<?php echo $data['title']; ?>" data-tip="<?php echo $data['title']; ?>">
<img src="<?php echo $data['img']; ?>" style="width:18px; margin: 4px 3px;"
alt="<?php echo $data['title']; ?>">
?>
<a <?php
echo $target; ?>href=" <?php echo $data['url']; ?>" class="<?php echo $action; ?> button tips <?php echo $action; ?>" style="background:#8dcc00; height:2em; width:2em; padding:3px;" alt="<?php echo $data['title']; ?>" data-tip="<?php echo $data['title']; ?>">
<img src="<?php echo $data['img']; ?>" style="width:18px; margin: 4px 3px;" alt="<?php echo $data['title']; ?>">
</a>
<?php
<?php
}
echo '</div>';
} else {
Expand All @@ -431,17 +425,13 @@ class="<?php echo $action; ?> button tips <?php echo $action; ?>"
);

foreach ($listing_actions as $action => $data) {
?>
<a href="<?php echo $data['url']; ?>" class="button tips <?php echo $action; ?>"
style="background:#8dcc00; height:2em; width:2em; padding:3px;" alt="<?php echo $data['alt']; ?>"
data-tip="<?php echo $data['alt']; ?>">
<img src="<?php echo $data['img']; ?>" style="width:18px; margin: 4px 3px;"
alt="<?php echo $data['alt']; ?>">
?>
<a href="<?php echo $data['url']; ?>" class="button tips <?php echo $action; ?>" style="background:#8dcc00; height:2em; width:2em; padding:3px;" alt="<?php echo $data['alt']; ?>" data-tip="<?php echo $data['alt']; ?>">
<img src="<?php echo $data['img']; ?>" style="width:18px; margin: 4px 3px;" alt="<?php echo $data['alt']; ?>">
</a>
<?php
<?php
}
}

}

/**
Expand Down Expand Up @@ -545,9 +535,7 @@ public function wcwp_get_order_items($order_id)
$data_list['images'] = $images;
return $data_list;
}

}

}

new WC_Wuunder_Create();
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ You can best contact us via [email protected]
7. Eenvoudig labels printen

== Changelog ==
= 2.7.25 =
* Fix weight typing
= 2.7.20 =
* Fix hook used for webhook processing
= 2.7.19 =
Expand Down
Loading

0 comments on commit d79123a

Please sign in to comment.