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 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 simple-coordinator-allocator branch from 9a64dee to 82971eb Compare July 24, 2018 14:43
kennyadsl
kennyadsl previously approved these changes Jul 25, 2018
Copy link
Member

@tvdeyen tvdeyen left a 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 💯

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 simple-coordinator-allocator branch from 82971eb to 636f2b7 Compare September 26, 2018 07:31
@vassalloandrea vassalloandrea force-pushed the simple-coordinator-allocator branch 4 times, most recently from 8492bba to f6c7c3e Compare October 12, 2018 17:16
@vassalloandrea vassalloandrea force-pushed the simple-coordinator-allocator branch from f6c7c3e to db700cf Compare October 17, 2018 08:13
Copy link
Contributor

@jacobherrington jacobherrington left a 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?

@kennyadsl kennyadsl dismissed their stale review November 28, 2018 10:18

Specs are failing

@vassalloandrea vassalloandrea force-pushed the simple-coordinator-allocator branch from db700cf to 0b93553 Compare December 12, 2018 14:36
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 simple-coordinator-allocator branch from 0b93553 to f177d85 Compare December 12, 2018 15:07
Copy link
Member

@tvdeyen tvdeyen 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
Contributor

@jacobherrington jacobherrington left a 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!

@kennyadsl kennyadsl merged commit a4f29e3 into solidusio:master Dec 12, 2018
@kennyadsl kennyadsl deleted the simple-coordinator-allocator branch December 12, 2018 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants