-
-
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
Make more stock classes configurable #4395
Make more stock classes configurable #4395
Conversation
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.
Great change, thanks @jarednorman !
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 Jared! Approved and left some suggestions to try (if not done already) to avoid stubbing the preference manually. Let me know if those are valid or if I am missing something.
2483b46
to
bcb06e3
Compare
Only change here is that I applied @kennyadsl's suggestion for stubbing the preferences. |
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, @jarednorman. It's always nice having more flexibility. I left some suggestions.
bcb06e3
to
3300cf9
Compare
3300cf9
to
0b4eebb
Compare
I've updated the description and added two additional commits to hook into the other two spots where |
@waiting-for-dev can we merge this? |
Needs documentation update. |
I've opened up a change request in Git Book to explain the use of these endpoints. |
3ce8dc4
to
b41f7ce
Compare
In writing the documentation I discovered that the commit that made the inventory validator configurable actually hadn't; it had added the configuration option, but it had neither used it, nor even attempted to assert that it the configured value was used. I've now fixed that and rebased this. Assuming tests pass I believe this should be ready to merge after it receives reviews. |
This adds the inventory unit builder (Spree::Stock::InventoryUnitBuilder by default) to the Spree::Config.stock configuration, so that it can be overridden. This is desirable for any store that doesn't have a one-to-one mapping between purchased variants and the fulfilled inventory units. The extension solidus_product_assembly heavily overrides this class to accomplish this, so with this change it will be able to stop decorating Spree::Stock::InventoryUnitBuilder and instead provide its own. I also reworked the stock configuration specs a bit. I fixed the repeated typo, simplified the structure slightly, and ensured they don't leak constants anymore.
This makes the Spree::Stock::AvailabilityValidator swappable. I need to justify using `send` in that test: this method is called by the order state machine, itself a swappable component. I could imagine making it a public method, but I don't want to increase the surface area of Spree::Order's API. Instead, I think it's useful to test this method in isolation (i.e. separately from the state machine) with the assumption that it is part of the API that the configured state machine will call. I've not added tests for the change to the checkout controller in the frontend... because it's too hard. The configured class already gets called a bunch just in setting up these tests, so trying to write a test that cares that it gets called with the right arguments at that particular moment did not seem worth the effort given we're deprecated frontend. Hopefully we can do something better in solidus_starter_frontend, where we also need to care about whether we're on a Solidus version that supports this configuration option.
Similar to the two parent commits, I'm making more of the stock-related classes in Solidus configurable to better support functionality like solidus_product_assembly provides. Also like the previous commit, I've chosen to unit test a private method on Spree::Order because I think it warrants being tested independently of the order state machine (the only place that calls this method).
This ensures that even if the specs fail, they don't leak constants.
b41f7ce
to
244c5c0
Compare
I've implemented @waiting-for-dev's remaining suggestion now. |
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, @jarednorman! ❤️
Description
This makes three additional stock classes configurable, so that they can be overridden by extensions like
solidus_product_assembly
or any stores that need similar functionality:Spree::Stock::InventoryUnitBuilder
Spree::Stock::InventoryValidator
Spree::Stock::AvailabilityValidator
I think there's probably more (breaking) work to be done to improve how this system works and better support the use case of having line items that map to inventory units with different quantities or variants, but this is a good first step.
Checklist: