Fix new-variant admin form when master variant has no default price - #6576
Open
wakqasahmed wants to merge 2 commits into
Open
Fix new-variant admin form when master variant has no default price#6576wakqasahmed wants to merge 2 commits into
wakqasahmed wants to merge 2 commits into
Conversation
Fixes solidusio#4831. Spree::Admin::VariantsController#new_before unconditionally cloned the master variant's default_price into the new variant. When the master variant has no default price (e.g. it was removed), default_price is nil and .attributes on it raised, crashing the new-variant admin page. Build a blank price in the store's default currency instead when the master has none, matching how Spree::Variant#default_price_or_build already handles this elsewhere.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6576 +/- ##
=======================================
Coverage 92.26% 92.26%
=======================================
Files 1037 1037
Lines 21228 21243 +15
=======================================
+ Hits 19586 19600 +14
- Misses 1642 1643 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
jarednorman
requested changes
Sep 3, 2026
Comment on lines
+18
to
+20
| # Shallow Clone of the default price to populate the price field, or | ||
| # build a blank one in the store's default currency when the master | ||
| # variant has no default price (e.g. it was removed). |
Member
There was a problem hiding this comment.
This comment is not necessary.
jarednorman flagged the 3-line comment as unnecessary — the if/else with the named master_default_price variable already makes the two branches' intent clear without restating it in prose.
Contributor
Author
|
Good call — removed the comment, the if/else with the named variable already reads clearly on its own. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4831.
Spree::Admin::VariantsController#new_beforeunconditionally clones the master variant'sdefault_priceonto the new variant. When the master variant has no default price (for example it was deleted),default_priceisniland calling.attributeson it raises, so opening the new-variant admin page for that product crashes.This builds a blank price in the store's default currency instead when the master has none, the same way
Spree::Variant#default_price_or_buildalready handles the same situation elsewhere in the codebase.Testing
bundle exec rspec spec/controllers/spree/admin/variants_controller_spec.rb— 7 examples, 0 failuresbundle exec standardrb backend/app/controllers/spree/admin/variants_controller.rb backend/spec/controllers/spree/admin/variants_controller_spec.rb— no offensesRan both in a plain
ruby:3.4-slim-bookwormcontainer against thebackendgem, sqlite test DB.