Giter Site home page Giter Site logo

commerce_auspost's People

Contributors

gig745 avatar jhesketh avatar jimmyjc avatar schoonzie avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

joewickert

commerce_auspost's Issues

ShippingRate requires an array.

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,
  ]
);

International Package Validation Incorrect

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']}'."
        );
      }
    }
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.