sale_price
to be added or updated. We could do this by overriding the view Spree provides, but there are potential problems with this technique. If Spree updates the view in a new release we won’t get the updated view as we are already overriding it. We would need to update our view with the new content from Spree and then add our customizations back in to stay fully up to date.
Let’s do this instead using Deface, which we just learned about. Using Deface will allow us to keep our view customizations in one spot, app/overrides
, and make sure we are always using the latest implementation of the view provided by Spree.
spree/admin/products/_form.html.erb
.
First, let’s create the overrides directory with the following command:
spree/admin/products/_form.html.erb
. Here is the part of the file we are going to add content to you can also view the full file:
app/overrides/add_sale_price_to_product_edit.rb
and adding the following content:
sale_price
to the master variant in order to get the updated product edit form working.
We can do this by creating a new file app/models/spree/product_decorator.rb
and adding the following content to it:
http://localhost:3000/admin/products
and edit a product, we should be able to set a sale price for the product and be able to view it on our sale page, http://localhost:3000/sale
. Note that you will likely need to restart our example Spree application created in the Getting Started tutorial.
data-hook
can be present in a number of ways:
id
attribute the data-hook
attribute
contains a value similar to what would be included in the id
attribute.
id
attribute the data-hook
attribute does
not normally contain a value.
id
attribute the data-hook
will
contain a value different from the elements id. This is generally to
support migration from the old 0.60.x style of hooks, where the old
hook names were converted into data-hook
versions.
data-hook
attribute wherever possible. Here are a few examples based on products/show.html.erb above:
:original
option that can contain a string of the original content that’s being replaced. When Deface is applying the override it will ensure that the current source matches the value supplied and will output to the Rails application log if they are different.
These warnings are a good indicator that you need to review the source and ensure your replacement is adequately replacing all the functionality provided by Spree. This will help reduce unexpected issues after upgrades.
Once you’ve reviewed the new source you can update the :original
value to new source to clear the warning.
Deface removes all whitespace from both the actual and `:original` source values before comparing, to reduce false warnings caused by basic whitespace differences.