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

Hide the master variants from stock management #4155

Merged
merged 1 commit into from
Sep 1, 2021

Conversation

tmtrademarked
Copy link
Contributor

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:
Screen Shot 2021-08-26 at 3 20 29 PM

After:
image

  • I have followed Pull Request guidelines
  • I have added a detailed description into each commit message
  • I have updated Guides and README accordingly to this change (if needed)
  • I have added tests to cover this change (if needed)
  • I have attached screenshots to this PR for visual changes (if needed)

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

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

Copy link
Member

@jarednorman jarednorman left a 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.

Comment on lines 51 to 56
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
Copy link
Member

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:

Suggested change
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)

Comment on lines 61 to 66
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
Copy link
Member

Choose a reason for hiding this comment

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

Similarly:

Suggested change
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)

Comment on lines 73 to 78
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
Copy link
Member

Choose a reason for hiding this comment

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

And:

Suggested change
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
)

@tmtrademarked
Copy link
Contributor Author

Good suggestion - thanks! Updated to be a little more terse.

Copy link
Member

@jarednorman jarednorman left a 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.

Comment on lines 55 to 56
scope = scope.where(product: @product)
scope = scope.where(is_master: [email protected]_variants?)
Copy link
Member

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:

Suggested change
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.
@tmtrademarked
Copy link
Contributor Author

Updated and squashed! Let me know if you'd prefer a different format in the message/etc. Thanks, Jared!

Copy link
Member

@jarednorman jarednorman left a 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.

Copy link
Member

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

Thank you Tom!

@kennyadsl kennyadsl merged commit 3b0b76b into solidusio:master Sep 1, 2021
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.

None yet

4 participants