Skip to content

Commit

Permalink
saves changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelLozan committed Dec 20, 2024
1 parent 3227348 commit 9661eac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
14 changes: 10 additions & 4 deletions app/controllers/prints_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ def show
parsed_description = Nokogiri::HTML.parse(print['description'])

default_variant = print['variants'].find { |variant| variant['is_default'] == true && variant['is_enabled'] == true}

variants = print['variants']

puts"=========================================="
puts"Default variant is: #{default_variant}"
puts"=========================================="
Expand All @@ -68,7 +71,7 @@ def show
price = default_variant['price']
variant = default_variant['id']
else
first_variant = print['variants'].first
first_variant = variants.first
price = first_variant['price']
variant = first_variant['id']
end
Expand All @@ -80,19 +83,21 @@ def show
'title' => print['title'],
'description' => parsed_description.text,
'image' => 'abstractart.png',
'price' => price
'price' => price,
'variants' => variants || []
}
else
@print = {
'id' => print['id'],
'title' => print['title'],
'description' => parsed_description.text,
'images' => images,
'price' => price
'price' => price,
'variants' => variants || []
}
end

@print = @print
@print

end

Expand Down Expand Up @@ -223,6 +228,7 @@ def load_products
p "Product is: #{product["id"]}"
p "=========================================="

next if product['visible'] != true # Skip if product is not published

parsed_description = Nokogiri::HTML.parse(product['description'])

Expand Down
7 changes: 6 additions & 1 deletion app/views/prints/_print.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="container-fluid mt-3 text-center">
<div id="<%= dom_id print %>">

<div class="prod-card my-3">
<div>BUTTS</div>
<% if Rails.env.test? %>
<%= image_tag "photo1.jpeg", alt: "test image" %>
<% else %>
Expand All @@ -10,6 +10,11 @@
<h1 class="mt-3"><%= print["title"] %></h1>
<p class="prod-price"> <%= number_to_currency(print["price"] / 100.00, :unit=> '$') %></p>
<p><%= print["description"] %></p>
<% puts "PRINT: #{print}"%>
<% if !print["variants"].empty? %>
<p>Available Sizes:</p>
<%= select_tag "Sizes", options_for_select(print.collect{ |v| [v['title'], v['id']] })%>
<% end %>
<% if @prints_cart.include?(print) %>
<%= button_to 'Remove from cart', remove_from_cart_print_path(print), method: :delete, class: 'btn btn-danger' %>
<% else %>
Expand Down
6 changes: 6 additions & 0 deletions app/views/prints/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@

<p class="px-5"><%= @print["description"] %></p>

<% puts "PRINT: #{@print}"%>
<% if !@print["variants"].empty? %>
<p>Available Sizes:</p>
<%= select_tag "Sizes", options_for_select(@print['variants'].collect{ |v| [v['title'], v['id'].to_i] })%>
<% end %>

<% if @flat_cart_arr.any? { |print| print["id"] == @print["id"]} %>
<div class="d-flex flex-column">
<%= button_to 'Remove from cart', remove_from_cart_prints_path(@print["id"]), method: :delete, class: 'btn btn-lg btn-danger' %>
Expand Down

0 comments on commit 9661eac

Please sign in to comment.