- Issue created by @joewickert
I tried the dev release, and there were a couple of errors that prevented me from using the module.
The first was triggered when trying to install the module.ArgumentCountError: Too few arguments to function Drupal\commerce_shipping\Packer\DefaultPacker::__construct(), 1 passed in /srv/www/project/site/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 261 and exactly 2 expected in /srv/www/project/site/web/modules/contrib/commerce_shipping/src/Packer/DefaultPacker.php on line 38
I managed to fix this by adding "@string_translation" to the arguments of the Drupal\commerce_auspost\Packer\CommerceAusPostPacker class in the commerce_auspost.services.yml file.
This allowed the module to be installed, but I got a similar error when trying to create a shipping method.
ArgumentCountError: Too few arguments to function Drupal\commerce_shipping\Plugin\Commerce\ShippingMethod\ShippingMethodBase::__construct(), 4 passed in /srv/www/project/site/web/modules/contrib/commerce_auspost/src/Plugin/Commerce/ShippingMethod/AusPost.php on line 243 and exactly 5 expected in Drupal\commerce_shipping\Plugin\Commerce\ShippingMethod\ShippingMethodBase->__construct() (line 66 of /srv/www/project/site/web/modules/contrib/commerce_shipping/src/Plugin/Commerce/ShippingMethod/ShippingMethodBase.php).
This one looks like the parent method is missing an argument of type workflow manager but my programming skills are limited to changing the occasional thing and hoping it works so I'm not really sure.
---
@joewickert I tried your fork and it's working! The one thing I had to do was to specifically require fontis/auspost-api-php dev-master because otherwise my min stability wouldn't allow it to be added by the auspost module.
The other thing I was struggling with while using the forked version was that it doesn't seem like shipping methods are hidden based on address. e.g. if I enable the standard domestic parcel post and the international air mail post, then if I set my address to overseas, both options are still visible and both show the same price, even though the price increases when changing to an international address. The same is true for switching back to domestic i.e. price goes down, both still visible. it could be that I just need to create multiple shipping methods and add conditions myself?
- 🇦🇺Australia dougiep
For the benefit of others, once resolved you also now need to update:
src/PostageServices/ServiceDefinitions/ServiceDestinations.php
2
3 namespace Drupal\commerce_auspost\PostageServices\ServiceDefinitions;
4
5 - use CommerceGuys\Enum\AbstractEnum;
6 -
5 /**
6 * Defines service destinations.
7 *
8 * @package Drupal\commerce_auspost\PostageServices\ServiceDefinitions
9 */
10 - final class ServiceDestinations extends AbstractEnum {
10 + final class ServiceDestinations {18 + /**
19 + * Returns all available destinations.
20 + *
21 + * @return array
22 + * Array of destination constants.
23 + */
24 + public static function getAll() {
25 + return [
26 + self::DOMESTIC,
27 + self::INTERNATIONAL,
28 + ];
29 + }
30 +
31 + /**
32 + * Asserts that a destination exists.
33 + *
34 + * @param string $destination
35 + * The destination to validate.
36 + *
37 + * @throws \InvalidArgumentException
38 + * If the destination doesn't exist.
39 + */
40 + public static function assertExists($destination) {
41 + if (!in_array($destination, self::getAll(), TRUE)) {
42 + throw new \InvalidArgumentException(sprintf('Invalid destination: %s', $destination));
43 + }
44 + }
45 +Then in ServiceCodes.php, remove the dependency and appending:
/**
* Returns all available service codes.
*
* @return array
* Array of service code constants.
*/
public static function getAll() {
return [
self::AUS_LETTER_REGULAR_SMALL,
self::AUS_LETTER_REGULAR_LARGE,
self::AUS_LETTER_PRIORITY_SMALL,
self::AUS_LETTER_PRIORITY_LARGE_500,
self::AUS_LETTER_EXPRESS_SMALL,
self::AUS_LETTER_EXPRESS_MEDIUM,
self::AUS_LETTER_EXPRESS_LARGE,
self::AUS_PARCEL_REGULAR,
self::AUS_PARCEL_REGULAR_SATCHEL_500G,
self::AUS_PARCEL_REGULAR_SATCHEL_3KG,
self::AUS_PARCEL_REGULAR_SATCHEL_5KG,
self::AUS_PARCEL_EXPRESS,
self::AUS_PARCEL_EXPRESS_SATCHEL_500G,
self::AUS_PARCEL_EXPRESS_SATCHEL_3KG,
self::AUS_PARCEL_EXPRESS_SATCHEL_5KG,
self::AUS_PARCEL_COURIER,
self::AUS_PARCEL_COURIER_SATCHEL_MEDIUM,
self::INT_LETTER_AIR_OWN_PACKAGING_LIGHT,
self::INT_LETTER_AIR_OWN_PACKAGING_MEDIUM,
self::INT_LETTER_AIR_OWN_PACKAGING_HEAVY,
self::INT_LETTER_COR_OWN_PACKAGING,
self::INT_LETTER_EXP_OWN_PACKAGING,
self::INT_LETTER_REG_SMALL_ENVELOPE,
self::INT_LETTER_REG_LARGE_ENVELOPE,
self::INT_PARCEL_SEA_OWN_PACKAGING,
self::INT_PARCEL_COR_OWN_PACKAGING,
self::INT_PARCEL_STD_OWN_PACKAGING,
self::INT_PARCEL_EXP_OWN_PACKAGING,
self::INT_PARCEL_AIR_OWN_PACKAGING,
];
}/**
* Asserts that a service code exists.
*
* @param string $code
* The service code to validate.
*
* @throws \InvalidArgumentException
* If the service code doesn't exist.
*/
public static function assertExists($code) {
if (!in_array($code, self::getAll(), TRUE)) {
throw new \InvalidArgumentException(sprintf('Invalid service code: %s', $code));
}
}Then ServiceOptions.php same thing, adding:
/**
* Returns all available service options.
*
* @return array
* Array of service option constants.
*/
public static function getAll() {
return [
self::AUS_SERVICE_OPTION_STANDARD,
self::AUS_SERVICE_OPTION_EXTRA_COVER,
self::AUS_SERVICE_OPTION_SIGNATURE_ON_DELIVERY,
self::AUS_SERVICE_OPTION_DELIVERY_CONFIRMATION,
self::AUS_SERVICE_OPTION_REGISTERED_POST,
self::AUS_SERVICE_OPTION_PERSON_TO_PERSON,
self::AUS_SERVICE_OPTION_COD_POSTAGE_FEES,
self::AUS_SERVICE_OPTION_COD_MONEY_COLLECTION,
self::INT_TRACKING,
self::INT_EXTRA_COVER,
self::INT_SMS_TRACK_ADVICE,
self::INT_SIGNATURE_ON_DELIVERY,
];
}/**
* Asserts that a service option exists.
*
* @param string $option
* The service option to validate.
*
* @throws \InvalidArgumentException
* If the service option doesn't exist.
*/
public static function assertExists($option) {
if (!in_array($option, self::getAll(), TRUE)) {
throw new \InvalidArgumentException(sprintf('Invalid service option: %s', $option));
}
}ServiceTypes.php same thing:
/**
* Returns all available service types.
*
* @return array
* Array of service type constants.
*/
public static function getAll() {
return [
self::PARCEL,
self::LETTER,
];
}/**
* Asserts that a service type exists.
*
* @param string $type
* The service type to validate.
*
* @throws \InvalidArgumentException
* If the service type doesn't exist.
*/
public static function assertExists($type) {
if (!in_array($type, self::getAll(), TRUE)) {
throw new \InvalidArgumentException(sprintf('Invalid service type: %s', $type));
}
}The commerceguys/enum library was deprecated because simple constants with static methods are cleaner and don't require an external dependency for basic enum functionality.
When enabling the shipping type there's also a form validation error to do with insurance percentage field due to min="0.1".
src/Forms/ConfigureForm.php with 1 addition and 1 removal
172 '#type' => 'number',
173 '#title' => $this->t('Percentage of order value'),
174 '#description' => $this->t('Percentage of order to add on as insurance. For example, enter 1.5 to add 150% extra insurance cover.'),
175 - '#min' => 0.1,
175 + '#min' => 0,Also necessary to add "dvdoug/boxpacker": "^3" to the module's composer.json
Various other fixes:
src/Packer/ShipmentPacking/PackableCommercePackageType.php with 1 addition and 1 removal
87 /**
88 * {@inheritdoc}
89 */
90 - public function getReference() {
90 + public function getReference(): string {src/Plugin/Deriver/ServiceDefinitionDeriver.php with 1 addition and 1 removal
30 'service_type' => $service['type'],
31 'service_code' => $service['service_code'],
32 'option_code' => $service['option_code'],
33 - 'sub_option_code' => $service['sub_option_code'],
33 + 'sub_option_code' => $service['sub_option_code'] ?? '',BoxPacker interface now requires return type declarations, so the following files need to be updated:
src/Packer/ShipmentPacking/PackableCommercePackageType.php
src/Packer/ShipmentPacking/PackableCommerceOrderItem.php
like this: public function getOuterWidth(): int {Next issue you'll face is fontis/auspost-api-php dev-master is outdated, relies on php 7. So we'll rewrite to use the cognito/auspost library instead which works with php 8. There's a lot of changes and this comment is already long enough.
- 🇦🇺Australia joewickert
Hi, sorry this delayed. I wasn't getting notifications on issue updates.
@toby-fz Glad it worked for you. I didn't need international post for my immediate project so I didn't really test it or try to get it working.
@dougiep Thanks for your work on this. I'd love to integrate your changes and be able to remove dependency on the outdated auspost repo.
Can you share your full working code or submit a patch here or on my github repo?
I don't see any comments from the current maintainer, so not sure what the status is on future developments.
Thanks