diff --git a/plugins/ShinyCMS/lib/tasks/demo_site.rake b/plugins/ShinyCMS/lib/tasks/demo_site.rake index 999e9c15d..7e80d66ec 100644 --- a/plugins/ShinyCMS/lib/tasks/demo_site.rake +++ b/plugins/ShinyCMS/lib/tasks/demo_site.rake @@ -34,10 +34,11 @@ namespace :shinycms do load_demo_site_data_file + load_demo_site_extras + ShinyCMS::FeatureFlag.enable :user_login - puts 'Loaded demo site data and created admin account.' - puts "You can log in as '#{@shiny_admin.username}' now." + puts "Loaded demo site data and created admin account. You can log in as '#{@shiny_admin.username}' now." # :nocov: end diff --git a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb index 9777ffac9..fad95e897 100644 --- a/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb +++ b/plugins/ShinyCMS/lib/tasks/support/demo_site_task.rb @@ -139,5 +139,13 @@ def fix_primary_key_sequence( table_name ) COMMIT; SQL end + + def load_demo_site_extras + ActiveStorage::Attachment.find_each do |attached| + name = attached.filename.to_s + file = Rails.public_path( 'public', 'images', name ).open + attached.record.image.attach io: file, filename: name + end + end end end diff --git a/plugins/ShinyShop/app/controllers/shiny_shop/products_controller.rb b/plugins/ShinyShop/app/controllers/shiny_shop/products_controller.rb index 9d9c39bf5..64affa9a9 100644 --- a/plugins/ShinyShop/app/controllers/shiny_shop/products_controller.rb +++ b/plugins/ShinyShop/app/controllers/shiny_shop/products_controller.rb @@ -40,12 +40,21 @@ def show if just_purchased? confirm_order else - render 'show' + show_product end end private + # Render the product with the appropriate template + def show_product + if @product.template.file_exists? + render template: "shiny_shop/products/#{@product.template.filename}", locals: @product.elements_hash + else + render status: :failed_dependency, inline: I18n.t( 'shiny_shop.products.template_file_missing' ) + end + end + def find_section( path_parts, error: true ) section_scope = Section.top_level_sections diff --git a/plugins/ShinyShop/app/models/shiny_shop/product.rb b/plugins/ShinyShop/app/models/shiny_shop/product.rb index 2883df5ff..b1d266a5b 100644 --- a/plugins/ShinyShop/app/models/shiny_shop/product.rb +++ b/plugins/ShinyShop/app/models/shiny_shop/product.rb @@ -13,6 +13,7 @@ class Product < ApplicationRecord include ShinyCMS::HasPublicName include ShinyCMS::HasReadableName include ShinyCMS::HasSlug + include ShinyCMS::HasTemplate include ShinyCMS::ProvidesDemoSiteData diff --git a/plugins/ShinyShop/spec/requests/shiny_shop/products_controller_spec.rb b/plugins/ShinyShop/spec/requests/shiny_shop/products_controller_spec.rb index 0738db622..4b800a8f2 100644 --- a/plugins/ShinyShop/spec/requests/shiny_shop/products_controller_spec.rb +++ b/plugins/ShinyShop/spec/requests/shiny_shop/products_controller_spec.rb @@ -69,11 +69,10 @@ product = create( :product, active: true ) get shiny_shop.product_or_section_path( product.slug ) - expect( response ).to have_http_status :ok expect( response.body ).to have_title product.name - expect( response.body ).to have_css 'h2', text: product.name + expect( response.body ).to have_css 'h1', text: product.name end it 'displays products in different sections with same slug' do @@ -88,14 +87,14 @@ expect( response ).to have_http_status :ok expect( response.body ).to have_title product1.name - expect( response.body ).to have_css 'h2', text: product1.name + expect( response.body ).to have_css 'h1', text: product1.name get shiny_shop.product_or_section_path( [ section2.slug, product2.slug ] ) expect( response ).to have_http_status :ok expect( response.body ).to have_title product2.name - expect( response.body ).to have_css 'h2', text: product2.name + expect( response.body ).to have_css 'h1', text: product2.name end it 'displays product in deeply-nested sections' do @@ -109,7 +108,7 @@ expect( response ).to have_http_status :ok expect( response.body ).to have_title product1.name - expect( response.body ).to have_css 'h2', text: product1.name + expect( response.body ).to have_css 'h1', text: product1.name end it 'thanks user after successful checkout' do diff --git a/themes/halcyonic/views/shiny_shop/products/no-sidebar.html.erb b/themes/halcyonic/views/shiny_shop/products/no-sidebar.html.erb index 919e60747..4b7e26e1e 100644 --- a/themes/halcyonic/views/shiny_shop/products/no-sidebar.html.erb +++ b/themes/halcyonic/views/shiny_shop/products/no-sidebar.html.erb @@ -9,8 +9,12 @@

<%= subheading %>

- <%#= sanitize html_content %> - <%= simple_format text_content %> + <%= sanitize html_content %> + +

+ <%= html_content %> +

+ <%#= simple_format text_content %>