As the title says, I'm using Spree 3.1.0 on Rails 4.2 to build a store. On the product Show page, I'm trying to use Deface to replace the radio buttons with a drop-down, as per the client's request. I have the dropdown functioning, but the price doesn't update on the page when you select an option like it did for the radio buttons.
Here is my override for the menu:
Deface::Override.new(
virtual_path: 'spree/products/_cart_form',
name: 'add_variants_dropdown_to_product_show',
replace: "ul.list-group",
text: "
<%= select_tag 'variant_id', options_for_select(@product.variants_and_option_values(current_currency).collect{ |v| [create_dropdown(v), v.id] })%>
")
And the helper method:
def create_dropdown(variant)
price = variant.stock_items.count > 0 ? variant.price : Spree.t(:out_of_stock)
"#{variant.options_text.sub('Size: ', '')} - #{price}"
end
The dropdown menu displays as expected, but I would like the Price display on the page to show the price of the selected variant instead of the base price. I have been searching for this for a while, and the two answers I found were helpful for getting the dropdown working, but don't seem to go into maintaining the price functionality.
Thank you!
For achieving this you need to modify product.js.coffee
it should look something like this
See the changes I made to ensure the now all the events reflect on now select box instead of radio button I would also recommend you to go through this code and change the variable names to satisfy current situation. (
radios->optionsjust for naming convention)Use spree
can_supply?method instead ofvaraint.stock_items.countAlso, you need to change the way you are building your select box to add a class on all
optionofselect_box_tagwhich I am using in product.js.coffeeThis should solve your problem. Please let me know if you are still unable to acheive your goal.