-
-
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
Hide the master variants from stock management #4155
Hide the master variants from stock management #4155
Conversation
@@ -51,7 +51,10 @@ def load_stock_management_data | |||
|
|||
def variant_scope | |||
scope = Spree::Variant.accessible_by(current_ability) | |||
scope = scope.where(product: @product) if @product | |||
if @product do |
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.
Lint/Syntax: unexpected token kDO
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 think this makes sense. Just one small suggestion on making the tests a little less verbose.
expect(assigns(:variants)).not_to include variant_1 | ||
expect(assigns(:variants)).not_to include variant_2 | ||
expect(assigns(:variants)).to include product_1.master | ||
expect(assigns(:variants)).not_to include product_2.master | ||
expect(assigns(:variants)).not_to include variant_3 | ||
expect(assigns(:variants)).not_to include variant_4 |
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.
These are pretty verbose, could use the contain_exactly
to make them a little more terse:
expect(assigns(:variants)).not_to include variant_1 | |
expect(assigns(:variants)).not_to include variant_2 | |
expect(assigns(:variants)).to include product_1.master | |
expect(assigns(:variants)).not_to include product_2.master | |
expect(assigns(:variants)).not_to include variant_3 | |
expect(assigns(:variants)).not_to include variant_4 | |
expect(assigns(:variants)).to contain_exactly(product_1.master) |
expect(assigns(:variants)).not_to include variant_1 | ||
expect(assigns(:variants)).not_to include variant_2 | ||
expect(assigns(:variants)).not_to include product_1.master | ||
expect(assigns(:variants)).not_to include product_2.master | ||
expect(assigns(:variants)).to include variant_3 | ||
expect(assigns(:variants)).to include variant_4 |
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.
Similarly:
expect(assigns(:variants)).not_to include variant_1 | |
expect(assigns(:variants)).not_to include variant_2 | |
expect(assigns(:variants)).not_to include product_1.master | |
expect(assigns(:variants)).not_to include product_2.master | |
expect(assigns(:variants)).to include variant_3 | |
expect(assigns(:variants)).to include variant_4 | |
expect(assigns(:variants)).to contain_exactly(variant_3, variant_4) |
expect(assigns(:variants)).to include variant_1 | ||
expect(assigns(:variants)).to include variant_2 | ||
expect(assigns(:variants)).to include product_1.master | ||
expect(assigns(:variants)).to include product_2.master | ||
expect(assigns(:variants)).to include variant_3 | ||
expect(assigns(:variants)).to include variant_4 |
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.
And:
expect(assigns(:variants)).to include variant_1 | |
expect(assigns(:variants)).to include variant_2 | |
expect(assigns(:variants)).to include product_1.master | |
expect(assigns(:variants)).to include product_2.master | |
expect(assigns(:variants)).to include variant_3 | |
expect(assigns(:variants)).to include variant_4 | |
expect(assigns(:variants)).to contain_exactly( | |
variant_1, | |
variant_2, | |
product_1.master, | |
product_2.master, | |
variant_3, | |
variant_4 | |
) |
Good suggestion - thanks! Updated to be a little more terse. |
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.
Just left one minor suggestion. Would you mind also squashing this all down to one commit? I think this is all fundamentally one change and we like to keep the git history pretty clean on the project.
scope = scope.where(product: @product) | ||
scope = scope.where(is_master: [email protected]_variants?) |
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.
You can do this as one call:
scope = scope.where(product: @product) | |
scope = scope.where(is_master: !@product.has_variants?) | |
scope = scope.where( | |
product: @product, | |
is_master: !@product.has_variants? | |
) |
This PR hides the master variants from the stock management list if the product has variants. This prevents a strange experience when managing inventory for these products - they don't really have SKUs, and aren't sellable in the general case.
1edbd8a
to
9cf55e5
Compare
Updated and squashed! Let me know if you'd prefer a different format in the message/etc. Thanks, Jared! |
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.
That's perfect. This looks good to me. I can't think of a reason right now that this would cause any issues for stores I work on.
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.
Thank you Tom!
This PR hides the master variants from the stock management list if the product has variants. This prevents a strange experience when managing inventory for these products - they don't really have SKUs, and aren't sellable in the general case.
Before:
After: