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

undefined method `adjust_count_on_hand' for nil:NilClass #3737

Closed
Lordnibbler opened this issue Sep 18, 2013 · 1 comment
Closed

undefined method `adjust_count_on_hand' for nil:NilClass #3737

Lordnibbler opened this issue Sep 18, 2013 · 1 comment

Comments

@Lordnibbler
Copy link
Contributor

Since Spree 2.1.1, product.stock_items.first.adjust_count_on_hand(10) throws the error undefined methodadjust_count_on_hand' for nil:NilClass`.

Changing to product.master.stock_items.first.adjust_count_on_hand(10) fixes it.

@radar said: In product.rb, has_many :stock_items, through: :variants, rather than has_many :stock_items, through: :variants_including_master.

@radar
Copy link
Contributor

radar commented Sep 19, 2013

Thanks for finding this @Lordnibbler.

The cause of this bug was that the stock_items association defined on the Product model was only fetching stock items for variants of that product that weren't the master variant. If the master variant is the only variant of this product, then no stock items at all were being returned.

I have submitted a fix for it to my 2-0-stable, 2-1-stable and master branches.

@radar radar closed this as completed in 12c749e Sep 19, 2013
radar added a commit that referenced this issue Sep 19, 2013
Fixes #3737

Conflicts:
	core/app/models/spree/product.rb
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

No branches or pull requests

2 participants