-
Notifications
You must be signed in to change notification settings - Fork 371
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
Add ShippingOption override to cart #1316
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Nice. I think it just needs some docs adding. |
Can we change this to an H2 in the docs so the shipping header shows on the right?
|
@@ -16,6 +16,7 @@ public function __construct( | |||
public TaxClass $taxClass, | |||
public $taxReference = null, | |||
public $option = null, | |||
public bool $collection = false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just spotted this was added. I presume it's for orders that are being collected and not delivered.
Can we add the usage to the docs? Maybe also at the same time give an example of how you can manually override the shipping option directly on the cart too?
This PR looks to add the ability to carts for developers to override a shipping option for a cart in a single request, useful if you want to estimate what the total cost a cart will have with a certain shipping option selection, to present to the end user.
Usage
You can get an estimated shipping option for the cart like so:
This will fetch the cheapest shipping option from the manifest, but by default will not set the shipping override, so pipelines will function as they currently do. In order for the pipelines to take the override into account you just pass the additional
setOverride
parameter:Now when you call
calculate()
on a cart, the override will be taken into account, bypassing any shipping address logic you may have in place.This is a "once" off effect so, say you have another request that calls
calculate()
without setting the meta above, the pipeline will not take it into account.If you use the CartSession facade, this can remember the meta for you in the session, making subsequent calls easier:
You may not need to provide all arguments, but may affect how shipping options are resolved and which are added to the manifest.
Once set though, you can pass the optional
estimateShipping
parameter when getting the current cart.This will use the shipping override in the pipelines, based on the
Behind the scenes, we're just using the
getEstimatedShipping
on the cart as we fetch it and setting the override before thecalculate()
method is called.