-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy all prices from master over children variants
This commit changes functionalities in three ways: - Backend: Before this change, when a user created a new variant the form was pre-populated only with a single price field for the default currency. In the case the user removed the amount field and submitted the form, the created price had an amount equal to 0. Now, all the prices created for a given product (for a given master variant, in fact) get pre-populated in a nested form. In the case one of the amounts is removed by the user, the form becomes invalid on submission and forces the user to set an amount for every price. - API: Before this change, the user was able to create a variant 1) manually assigning a single price in the default currency through the `price` attribute, and 2) letting it inherit the default price from the master variant when `price` attribute was not present. Now, when not overridden all master prices get inherited. Otherwise, the user can specify both through `price` (for the default currency) and `prices_attributes` attributes. - Product duplicator: Before this change, only the default master price was copied. Now, all prices are taken into account. Internally, the `set_price` callback on `Variant` has been removed in order to allow that flexibility. The behavior has been moved to a layer one step closer than where it should actually be: A service layer. It will help when we tackle this long-term goal. It also means that when we manually create a variant we must specify the default price for it. Having three rails associations between `Variant` and `Price` is a source of inconsistencies, as when we add a `Price` in-memory to one of them the others don't get updated. It should be changed as follow-up work. For now, `Variant#any_price?` hack has been added. In the same way, `Variant#find_or_build_default_price` didn't find it when it still was in-memory. `Variant#default_price_from_memory` have been added to fix it.
- Loading branch information
1 parent
3cc2d3e
commit 7a54da9
Showing
20 changed files
with
243 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,9 @@ | |
} | ||
} | ||
} | ||
|
||
.field_with_errors { | ||
flex: 1 1 auto; | ||
width: 1%; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="mb-3"> | ||
<%= render "spree/admin/shared/number_with_currency", f: f, amount_attr: :amount, currency: currency, extra_attrs: { "aria-label" => t("spree.helpers.prices.amount_in", currency: currency) } %> | ||
<%= f.hidden_field :currency, value: currency %> | ||
</div> |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.