-
-
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
Add an allocator class to extend the Solidus initial allocation logic #2810
Add an allocator class to extend the Solidus initial allocation logic #2810
Conversation
9a64dee
to
82971eb
Compare
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 like this 👍
But the config should live under the stock configuration like all other stock config.
Thanks 💯
82971eb
to
636f2b7
Compare
8492bba
to
f6c7c3e
Compare
f6c7c3e
to
db700cf
Compare
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 for the PR! Can we revisit this and get specs passing, please?
db700cf
to
0b93553
Compare
With this PR we add the possibility to change the stock allocation logic using a custom class without override the allocate_inventory method in SimpleCoordinator.
0b93553
to
f177d85
Compare
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.
Specs are passing now. Thanks @vassalloandrea!
With this PR we add the possibility to change the stock allocation logic using a custom class without overriding the allocate_inventory method in SimpleCoordinator.
How it works
Default class
Without changing the Solidus default stock allocation, I wrote a
Spree::Stock::Allocator::OnHandFirst
allocator with the same logic of theallocate_inventory
method.How to override Solidus default stock allocation
You can tell the
SimpleCoordinator
to use a custom allocator overriding theSpree
configuration:Spree::Config.stock.allocator_class
How to write a custom allocator
To write a custom stock allocator you can extend
Spree::Stock::Allocator::Base
if you also want to change the allocation priority ( on hand first or backorderable first ). Otherwise, you can extendSpree::Stock::Allocator::OnHandFirst
to only change the allocation logic.