-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Deprecate creating new shipment with an item via API #4387
Deprecate creating new shipment with an item via API #4387
Conversation
This change is needed to allow deprecating passing the variant (and quanityt) in this endpoint.
There's no known reason why we need to force creating a shipment with exactly one variant into it. There's a dedicated endpoint for that, see the deprecation warning message in this commit for details.
The reload is probably there because, after adding some items to the order, the in-memory shipment object may be outdated. In case no item is added, there's no need to perform an extra query.
This commit move the generic specs in the outer context and keeps the one related to the deprecated variant_id params in its own context. It will be easier to remove them when it's time to remove deprecated code. This commit also removes a code comment that at the moment doesn't provide a lot of value.
There are a couple of untested scenarios now and this should cover this area well.
Due to the previous changes, we need to be sure that adding a product to an empty shipment works correctly. This was never done before because it wasn't possible to crete an empty shipment, so a new test is required.
variant = Spree::Variant.unscoped.find(params[:variant_id]) | ||
@order.contents.add(variant, quantity, { shipment: @shipment }) | ||
@shipment.save! | ||
@shipment.reload |
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.
Do we need reload
here?
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 don't know (see d018c6e). But being code that we are going to remove soon, I think it's not even worth spending too much time to understand if there was a reason for that reload to be there. If you think we need to investigate more, I'll happily commit to that.
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.
Yeah, you're right 👍
|
||
**Deprecation Warning**: Adding items to the shipment via this endpoint | ||
is deprecated. Instead, create an empty shipment and populate it with | ||
the dedicated endpoint [to add items to the shipment](/docs/solidus/7078dbcf415ac-add-shipment-item). |
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 don't know if this way of adding link will work. I saw the docs here but I don't know how to test it until it's published.
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.
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.
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.
@waiting-for-dev yep, but does it switch from the current branch to the main one? I don't think there's a way to capture the current branch information in the link anyhow.
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.
What do you mean? The deprecation warning is only rendered on master
, and I can switch the version with the top-left selector without problems.
I submitted #4397 to update my references.
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 mean that if you click on the link from the master
version, it will move you to the default one (currently 3.1) because the /branches/master/
part of the URL is not reflected in the link.
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.
Oh, I see 🤦
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.
still better than nothing 🤷
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.
Yeah, I thought exactly that 😉
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.
Thanks!!
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.
Looks good to me, thank you!
@@ -41,6 +41,8 @@ def select_shipping_method | |||
def create | |||
authorize! :create, Shipment | |||
quantity = params[:quantity].to_i | |||
variant = Spree::Variant.unscoped.find(params[:variant_id]) |
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.
Just for curiosity, do you know why we needed to unscope
variants here?
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.
Good point. It was added here, it seems to allow removing discarded items from a shipment. It doesn't seem necessary for adding them though, changing this, thanks for the question, Andrea!
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.
Wait, thinking twice, I'd prefer not to make that change. For the same reason described on another commet, I think changing this deprecated code now could give us more pain than benefits. Are you ok keeping this as is?
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.
That makes sense! Thanks for double-checking this.
…ipments Now you should create a shipment and after that, use the dedicated endpoint to add stuff to it: PUT /api/shipments/{shipment_number}/add Ref solidusio#4387
…ipments Now you should create a shipment and after that, use the dedicated endpoint to add stuff to it: PUT /api/shipments/{shipment_number}/add Ref solidusio#4387
…ipments Now you should create a shipment and after that, use the dedicated endpoint to add stuff to it: PUT /api/shipments/{shipment_number}/add Ref solidusio#4387
…ipments Now you should create a shipment and after that, use the dedicated endpoint to add stuff to it: PUT /api/shipments/{shipment_number}/add Ref solidusio#4387
Now you should create a shipment and after that, use the dedicated endpoint to add stuff to it: PUT /api/shipments/{shipment_number}/add Ref #4387
Description
There's no known reason why we need to force creating a shipment with exactly one variant into it.
There's a dedicated endpoint for that:
This feature is not used anymore in our backend UI and, if someone is using this endpoint, they will receive a deprecation warning with the instructions on how to adjust their flow to be compatible with the next major version.
TODO:
Checklist:
I have attached screenshots to this PR for visual changes (if needed)