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 Master Price input when there's no default price #3155

Merged
merged 2 commits into from
May 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions backend/app/views/spree/admin/products/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,22 @@
<div data-hook="admin_product_form_price">
<%= f.field_container :price do %>
<%= f.label :price, class: Spree::Config.require_master_price ? 'required' : '' %>
<%= render "spree/admin/shared/number_with_currency", f: f,
amount_attr: :price,
required: Spree::Config.require_master_price,
currency: Spree::Config.default_pricing_options.currency %>
<%= f.error_message_on :price %>

<% if f.object.new_record? || f.object.has_default_price? %>
<%= render "spree/admin/shared/number_with_currency",
f: f,
amount_attr: :price,
required: Spree::Config.require_master_price,
currency: Spree::Config.default_pricing_options.currency %>
<%= f.error_message_on :price %>
<% else %>
<span class="info">
<%= t('spree.product_without_default_price_info',
default_currency: Spree::Config.default_pricing_options.currency) %>
<%= link_to t('spree.product_without_default_price_cta'),
spree.admin_product_prices_url(@product) %>
</span>
<% end %>
<% end %>
</div>

Expand Down
25 changes: 25 additions & 0 deletions backend/spec/features/admin/products/edit/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,31 @@
end
end

context "when default price is deleted" do
it "does not show the master price", js: true do
product = create(:product, name: 'Bún thịt nướng', sku: 'A100',
description: 'lorem ipsum', available_on: '2013-08-14 01:02:03')

visit spree.admin_path
click_nav "Products"
within_row(1) { click_icon :edit }

click_link 'Prices'

within "#spree_price_#{product.master.default_price.id}" do
accept_alert do
click_icon :trash
end
end
expect(page).to have_content("Price has been successfully removed")

click_link 'Product Details'

expect(page).not_to have_field('product_price')
expect(page).to have_content('This Product has no price in the default currency (USD).')
end
end

# Regression test for https://github.com/spree/spree/issues/3385
context "deleting a product", js: true do
it "is still able to find the master variant" do
Expand Down
2 changes: 1 addition & 1 deletion backend/spec/features/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def build_option_type_with_values(name, values)
check "Show Deleted"
click_button "Search"
click_link product.name
expect(page).to have_field('Master Price', with: product.price.to_f)
expect(page).to_not have_field('Master Price')
expect(page).to_not have_content('Images')
expect(page).to_not have_content('Prices')
expect(page).to_not have_content('Product Properties')
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/concerns/spree/default_price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def find_or_build_default_price
delegate :price=, to: :find_or_build_default_price

def has_default_price?
!default_price.nil?
default_price.present? && !default_price.discarded?
end
end
end
2 changes: 2 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,8 @@ en:
product_source:
group: From product group
manual: Manually choose
product_without_default_price_info: 'This Product has no price in the default currency (%{default_currency}).'
product_without_default_price_cta: 'Please, create a Master Price!'
products: Products
promotion: Promotion
promotion_action: Promotion Action
Expand Down
8 changes: 8 additions & 0 deletions core/spec/support/concerns/default_price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,13 @@
describe '#has_default_price?' do
subject { super().has_default_price? }
it { is_expected.to be_truthy }

context 'when default price is discarded' do
before do
instance.default_price.discard
end

it { is_expected.to be_falsey }
end
end
end