Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added apply_shipping_rules support to the createLabel call #35

Merged
merged 1 commit into from
Feb 13, 2024

Conversation

linaori
Copy link
Contributor

@linaori linaori commented Jan 26, 2024

When requesting labels it can also apply shipping rules when this feature is available. This will effectively override the shipping method given.

I've given it a default value in getParcelData to ensure backwards compatibility due to this method being protected. I've added false as default value to the callers as all parameter values are explicitly passed along, but can change this if desired.

@villermen villermen self-requested a review February 6, 2024 13:25
Copy link
Member

@villermen villermen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@linaori Thanks for the PR! I've left a comment/question on on the combination of shipping method and applyShippingRules. Please let me know your opnion here.

Additionally, the createParcel() method also supports passing a shipping method so I think adding this new argument would also be desireable there, right? Maybe even for updateParcel() too, but I don't really see a use case to set the shipping method in an update right now.

@@ -671,7 +677,8 @@ protected function getParcelData(
?string $customsInvoiceNumber,
?int $customsShipmentType,
?array $items,
?string $postNumber
?string $postNumber,
bool $applyShippingRules = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think false is the right default here because it will not change API behavior for extending classes (which I doubt there are any though).

* @throws SendcloudRequestException
*/
public function createLabel(Parcel|int $parcel, ShippingMethod|int $shippingMethod, SenderAddress|Address|int|null $senderAddress): Parcel
public function createLabel(Parcel|int $parcel, ShippingMethod|int $shippingMethod, SenderAddress|Address|int|null $senderAddress, bool $applyShippingRules = false): Parcel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is requiring $shippingMethod in combination with $applyShippingRules: true desirable if it's going to be ignored? Or does it serve as a fallback in case no shipping rules apply? I can't make up from the documentation whether the shipment property is required in this case. If adding $shippingMethod does nothing when $applyShippingRules: true we could add it as a separate method instead (createLabelWithShippingRules($parcel, ?$senderAddress)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell it's still required to pass a shipping method and this will indeed be used as fallback when the shipping rules can't be applied. This is how it was explained to me in a call with Sendcloud. That said it's a bit difficult for me to test as my Sendcloud account currently doesn't have any contracts with any carriers. I will try to verify this behavior myself:

  • pass a shipping method that requires a contract
  • pass apply rules: true
  • add a shipping rule that would set the shipping method to 8 (unstamped letter) with a condition that will never be hit
  • call createLabel() and see what happens

A second method is still possible regardless as the fallback shipping method would most likely be 8 (unstamped letter), but it does take away the ability to change this default. Unfortunately there's no API call to retrieve the default shipping method configured for your account.

@linaori
Copy link
Contributor Author

linaori commented Feb 12, 2024

Additionally, the createParcel() method also supports passing a shipping method so I think adding this new argument would also be desireable there, right?

I've looked into it and was unable to trigger the shipping rules unless I requested the label. My initial design included the create and update calls and I reverted to just createLabel() for that reason.

@villermen villermen merged commit 5b1cfcf into Webador:master Feb 13, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants