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

Deprecate creating new shipment with an item via API #4387

Conversation

kennyadsl
Copy link
Member

@kennyadsl kennyadsl commented May 30, 2022

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:

PUT /api/shipments/{shipment_number}/add

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 followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

kennyadsl added 6 commits May 30, 2022 12:22
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.
@kennyadsl kennyadsl self-assigned this May 30, 2022
variant = Spree::Variant.unscoped.find(params[:variant_id])
@order.contents.add(variant, quantity, { shipment: @shipment })
@shipment.save!
@shipment.reload
Copy link
Contributor

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?

Copy link
Member Author

@kennyadsl kennyadsl May 30, 2022

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.

Copy link
Contributor

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).
Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, interesting. I was looking for something like it for #4385 & #4388. If it works, I'll update the references I added there.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see 🤦

Copy link
Member Author

Choose a reason for hiding this comment

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

still better than nothing 🤷

Copy link
Contributor

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 😉

@kennyadsl kennyadsl added changelog:solidus_api Changes to the solidus_api gem and removed Needs Work labels May 30, 2022
@kennyadsl kennyadsl marked this pull request as ready for review May 30, 2022 14:51
Copy link
Contributor

@waiting-for-dev waiting-for-dev left a comment

Choose a reason for hiding this comment

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

Thanks!!

Copy link
Member

@spaghetticode spaghetticode left a 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])
Copy link
Member

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?

Copy link
Member Author

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!

Copy link
Member Author

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?

Copy link
Member

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.

@kennyadsl kennyadsl merged commit a5e184d into solidusio:master May 31, 2022
@kennyadsl kennyadsl deleted the kennyadsl/api/deprecate-creating-shipment-with-items branch May 31, 2022 11:25
kennyadsl added a commit to nebulab/solidus that referenced this pull request Mar 27, 2023
…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
kennyadsl added a commit to nebulab/solidus that referenced this pull request Apr 12, 2023
…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
kennyadsl added a commit to nebulab/solidus that referenced this pull request Apr 14, 2023
…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
kennyadsl added a commit to nebulab/solidus that referenced this pull request Apr 18, 2023
…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
kennyadsl added a commit that referenced this pull request Apr 18, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_api Changes to the solidus_api gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants