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

Add an allocator class to extend the Solidus initial allocation logic #2810

Merged
merged 1 commit into from Dec 12, 2018

Conversation

@vassalloandrea
Copy link
Contributor

vassalloandrea commented Jul 24, 2018

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 the allocate_inventory method.

How to override Solidus default stock allocation

You can tell the SimpleCoordinator to use a custom allocator overriding the Spree 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 extend Spree::Stock::Allocator::OnHandFirst to only change the allocation logic.

@vassalloandrea vassalloandrea force-pushed the nebulab:simple-coordinator-allocator branch from 9a64dee Jul 24, 2018
Copy link
Member

tvdeyen left a comment

I like this 👍

But the config should live under the stock configuration like all other stock config.

Thanks 💯

core/lib/spree/app_configuration.rb Outdated Show resolved Hide resolved
core/app/models/spree/stock/simple_coordinator.rb Outdated Show resolved Hide resolved
@vassalloandrea vassalloandrea force-pushed the nebulab:simple-coordinator-allocator branch Sep 26, 2018
@vassalloandrea vassalloandrea force-pushed the nebulab:simple-coordinator-allocator branch 4 times, most recently to f6c7c3e Oct 12, 2018
@vassalloandrea vassalloandrea force-pushed the nebulab:simple-coordinator-allocator branch from f6c7c3e Oct 17, 2018
Copy link
Member

jacobherrington left a comment

Thanks for the PR! Can we revisit this and get specs passing, please?

@kennyadsl kennyadsl dismissed their stale review Nov 28, 2018

Specs are failing

@vassalloandrea vassalloandrea force-pushed the nebulab:simple-coordinator-allocator branch Dec 12, 2018
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.
@vassalloandrea vassalloandrea force-pushed the nebulab:simple-coordinator-allocator branch to f177d85 Dec 12, 2018
Copy link
Member

tvdeyen left a comment

Thanks

Copy link
Member

jacobherrington left a comment

Specs are passing now. Thanks @vassalloandrea!

@kennyadsl kennyadsl merged commit a4f29e3 into solidusio:master Dec 12, 2018
10 checks passed
10 checks passed
Header rules - solidus-guides No header rules processed
Details
Pages changed - solidus-guides 2 new files uploaded
Details
Redirect rules - solidus-guides No redirect rules processed
Details
Hound No violations found. Woof!
Mixed content - solidus-guides No mixed content detected
Details
ci/circleci: mysql Your tests passed on CircleCI!
Details
ci/circleci: mysql_rails51 Your tests passed on CircleCI!
Details
ci/circleci: postgres Your tests passed on CircleCI!
Details
ci/circleci: postgres_rails51 Your tests passed on CircleCI!
Details
netlify/solidus-guides/deploy-preview Deploy preview ready!
Details
@kennyadsl kennyadsl deleted the nebulab:simple-coordinator-allocator branch Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.