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 template variants scope #5866

Merged
merged 2 commits into from
Oct 21, 2024
Merged

Conversation

mamhoff
Copy link
Contributor

@mamhoff mamhoff commented Oct 9, 2024

Summary

This introduces logic that removes the ability to add template ("master") variants to admin carts.

When a product has option types and option values, it can have multiple variants. It will also have a variant with the is_master flag set to true, but that variant will not be sellable in the frontend. For a t-shirt that has the option types "Size" and "Color", for example, the master variant would not have a color and not have a size - thus it would be impossible to actually buy.

However, for items that don't have option types - single-variant products - the variant with the is_master flag is actually what customers would add to their cart. The logic in this PR respects that.

If your store uses .where(is_master: false) to find out whether something is sellable, you can now instead do .sellable.

Checklist

The following are mandatory for all PRs:

The following are not always needed:

  • 📖 I have updated the README to account for my changes.
  • 📑 I have documented new code with YARD.
  • 🛣️ I have opened a PR to update the guides.
  • ✅ I have added automated tests to cover my changes.
  • 📸 I have attached screenshots to demo visual changes.

@mamhoff mamhoff requested a review from a team as a code owner October 9, 2024 06:39
@github-actions github-actions bot added the changelog:solidus_core Changes to the solidus_core gem label Oct 9, 2024
Copy link

codecov bot commented Oct 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.24%. Comparing base (3a92a45) to head (6b4d76d).
Report is 33 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5866   +/-   ##
=======================================
  Coverage   89.24%   89.24%           
=======================================
  Files         754      754           
  Lines       17533    17536    +3     
=======================================
+ Hits        15647    15650    +3     
  Misses       1886     1886           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

Nice, just left some notes on the naming. Let's discuss!

core/app/models/spree/variant.rb Show resolved Hide resolved
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. We paired on this

@tvdeyen tvdeyen changed the title Template variants Add template variants scope Oct 9, 2024
@tvdeyen tvdeyen added this to the 4.4 milestone Oct 9, 2024
All products have variants, but not all variants can actually be sold.
When a product has option types, the sellable variants are those that
are assigned to option values, whereas the "master" variant is only
there as a template for other variants to be created.

I'm using the language "template variant" because "master variant"
because it more closely matches what the `is_master` flag on the
Spree::Variant actually does.
Currently, one can add template variants to one's cart, but that should
not be possible. This commit makes sure that the variant search won't
return template variants.
@kennyadsl kennyadsl merged commit e509aa9 into solidusio:main Oct 21, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:solidus_core Changes to the solidus_core gem
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants