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

Validate only additional parts necessary #106

Closed
wants to merge 1 commit into from

Conversation

mstate
Copy link

@mstate mstate commented Feb 12, 2015

The AvailabilityValidator seems to be validating for the entire quantity of the line_item instead of the quantity being added to the line_item (as spree's does). The proposed AvailabilityValidator change validates only the availability of additional parts needed to fulfill changes to the line_item's quantity.

…e line_item's quantity (instead of the entire quantity).
@@ -3,14 +3,17 @@ module Stock
# Overridden from spree core to make it also check for assembly parts stock
class AvailabilityValidator < ActiveModel::Validator
def validate(line_item)
unit_count = line_item.inventory_units.size
return if unit_count >= line_item.quantity

Choose a reason for hiding this comment

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

I don't think this will work. I think this is what's needed...

unit_count = line_item.inventory_units.size
parts_total = line_item.parts.to_a.sum { |v| line_item.count_of(v) } * line_item.quantity

return if unit_count >= parts_total

@vinniefranco
Copy link

Closing as stale

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants