Skip to content

Commit

Permalink
Add discontinue_on datepicker field to product form
Browse files Browse the repository at this point in the history
Like with the available on date we want to be able to set the discontinue on date as well.
  • Loading branch information
tvdeyen committed Oct 9, 2020
1 parent 235c307 commit b1421e2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
11 changes: 11 additions & 0 deletions backend/app/views/spree/admin/products/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,17 @@
<% end %>
</div>

<div data-hook="admin_product_form_discontinue_on">
<%= f.field_container :discontinue_on do %>
<%= f.label :discontinue_on %>
<%= f.field_hint :discontinue_on %>

<%= render "spree/admin/shared/datepicker", f: f, date_attr: :discontinue_on %>

<%= f.error_message_on :discontinue_on %>
<% end %>
</div>

<div data-hook="admin_product_form_promotionable">
<%= f.field_container :promotionable do %>
<label>
Expand Down
8 changes: 8 additions & 0 deletions backend/spec/features/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ def build_option_type_with_values(name, values)
expect(page).to have_content("successfully updated!")
expect(Spree::Product.last.available_on).to eq('Tue, 25 Dec 2012 00:00:00 UTC +00:00')
end

it 'should correctly update discontinue_on' do
visit spree.admin_product_path(product)
fill_in "product_discontinue_on", with: "2020/12/4"
click_button "Update"
expect(page).to have_content("successfully updated!")
expect(product.reload.discontinue_on.to_s).to eq('2020-12-04 00:00:00 UTC')
end
end

context 'deleting a product', js: true do
Expand Down
3 changes: 3 additions & 0 deletions core/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,9 @@ en:
available_on: This sets the availability date for the product. If this value
is not set, or it is set to a date in the future, then the product is not
available on the storefront.
discontinue_on: This sets the discontinue date for the product. If this value
is set to a date, then the product is not available on the storefront from
that day on anymore.
promotionable: 'This determines whether or not promotions can apply to this
product.<br/>Default: Checked'
shipping_category: 'This determines what kind of shipping this product requires.<br/>
Expand Down
2 changes: 1 addition & 1 deletion core/lib/spree/permitted_attributes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module PermittedAttributes
@@product_properties_attributes = [:property_name, :value, :position]

@@product_attributes = [
:name, :description, :available_on, :permalink, :meta_description,
:name, :description, :available_on, :discontinue_on, :permalink, :meta_description,
:meta_keywords, :price, :sku, :deleted_at,
:option_values_hash, :weight, :height, :width, :depth,
:shipping_category_id, :tax_category_id,
Expand Down

0 comments on commit b1421e2

Please sign in to comment.