sitback / commerce_auspost Goto Github PK
View Code? Open in Web Editor NEWDrupal 8 fork of the Drupal 'commerce_auspost' module
Home Page: https://www.drupal.org/sandbox/torpy/2876488
Drupal 8 fork of the Drupal 'commerce_auspost' module
Home Page: https://www.drupal.org/sandbox/torpy/2876488
An invalid form control with name='plugin[0][target_plugin_configuration][auspost][options][insurance_settings][insurance_percentage]' is not focusable.
The ShippingRate object requires an array when it is created.
src/Plugin/Commerce/ShippingMethod/AusPost.php - Line 494, function calculateRates()
Should be:
$rates[] = new ShippingRate(
[
'shipping_method_id' => $serviceId,
'service' => $service,
'amount' => $postagePrice,
]
);
The current international package validation is not the correct approach for the the specifications provided by Australia Post.
Australia Post states:
The formula for working out the girth of your overseas parcel is: (width + height) x 2 = girth. When measuring dimensions, the longest side of the parcel is considered the length. Ie, the two shortest sides are used to calculate girth.
https://auspost.com.au/sending/check-sending-guidelines/size-weight-guidelines
The current validation checks several combinations of the sides that include the length. I think the idea being that the user may mix up the L x W x H and so you're checking them all to be safe. The issue with this is that it can lead to falsely preventing a package from being used in the rate calculation.
I think a better approach would be to identify the two shortest sides and use that to calculate the girth as this is what Australia Post specifically states to do.
Below is my suggestion:
src/PostageServices/ServiceSupport.php - function validatePackageSize()
...
else {
// International packages have girth requirements,
// (where girth = ((width + height) * 2)).
// Australia Post considers the longest edge of a parcel to be the length.
$values = [
'height' => $height,
'length' => $length,
'width' => $width,
];
$valueA = $valueB = new Length(9999, LengthUnit::CENTIMETER);
foreach ($values as $key => $value) {
if ($value->compareTo($valueA) < 0) {
$valueB = $valueA;
$valueA = $value;
}
else if ($value->compareTo($valueB) < 0) {
$valueB = $value;
}
}
$girth = $valueA->add($valueB)
->multiply('2');
if ($max['girth']->lessThan($girth)) {
throw new PackageSizeException(
"Package girth ({$girth}, calculated using '{$valueA}cm' and '{$valueB}cm') is greater than the AusPost maximum of '{$max['girth']}'."
);
}
}
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.