Skip to content

Commit 72bc837

Browse files
committed
views etc
1 parent e10990d commit 72bc837

File tree

74 files changed

+2738
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+2738
-4
lines changed

app/controllers/home_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
class HomeController < Spree::BaseController
2-
#helper :products, :taxons
2+
helper :products, :taxons
33

44
def index
55
home_taxonomy = get_taxonomies.find{|t| t.show_on_homepage? }
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Spree::BaseHelper.module_eval do
2+
def link_to_cart(text = t('cart'))
3+
item_count = (current_order.nil? or current_order.line_items.empty?) ? 0 : current_order.item_count
4+
text = "<h4>#{text} <span class=\"badge badge-info\">#{item_count}</span></h4>"
5+
6+
link_to text.html_safe, cart_path
7+
end
8+
9+
# Outputs the corresponding flash message if any are set
10+
def flash_messages
11+
bootstrap_class = {"notice" => "alert alert-success", "error" => "alert alert-error", "warning" => "alert"}
12+
bootstrap_class.keys.map do |msg|
13+
content_tag(:div, ("<a class=\"close\" data-dismiss=\"alert\">&#215;</a>".html_safe + flash.delete(msg.to_sym).html_safe), {:class => bootstrap_class[msg]}) unless flash[msg.to_sym].blank?
14+
end.join("\n").html_safe
15+
end
16+
end
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
CheckoutHelper.module_eval do
2+
3+
def checkout_states
4+
%w(address delivery payment confirm)
5+
end
6+
7+
# TODO: this can be deleted from extension after Spree 0.70.0 release
8+
def checkout_progress
9+
states = checkout_states
10+
items = states.map do |state|
11+
css_class = "empty"
12+
current_index = states.index(@order.state)
13+
state_index = states.index(state)
14+
15+
text = t("order_state.#{state}").titleize
16+
link = link_to "#{state_index + 1}. #{text}", checkout_state_path(state)
17+
18+
if state == @order.state
19+
link = link_to "#{state_index + 1}. #{text}", "#"
20+
css_class = 'active'
21+
end
22+
23+
content_tag('li', link, :class => css_class) if state_index <= current_index
24+
end
25+
content_tag('ul', raw(items.join("\n")), :class => 'nav nav-tabs checkout_states', :id => "checkout-step-#{@order.state}")
26+
end
27+
28+
29+
def address_field(form, method, id_prefix = "b", &handler)
30+
if handler
31+
handler.call
32+
else
33+
label = form.label(method, :class => "control-label")
34+
field = content_tag :div, :class => "controls" do
35+
form.text_field(method)
36+
end
37+
label + field
38+
end
39+
end
40+
41+
def address_state(form, country)
42+
country ||= Country.find(Spree::Config[:default_country_id])
43+
have_states = !country.states.empty?
44+
state_elements = [
45+
form.collection_select(:state_id, country.states.order(:name),
46+
:id, :name,
47+
{:include_blank => true},
48+
{:style => have_states ? "" : "display:none",
49+
:disabled => !have_states}) +
50+
form.text_field(:state_name,
51+
:style => !have_states ? "" : "display:none",
52+
:disabled => have_states)
53+
].join.gsub('"', "'").gsub("\n", "")
54+
55+
content_tag :div, :class => "control-group" do
56+
label = form.label(:state, t(:state), :class => "control-label")
57+
field = content_tag :div, :class => "controls" do
58+
content_tag(:noscript, form.text_field(:state_name, :class => 'required')) +
59+
javascript_tag("document.write(\"#{state_elements.html_safe}\");")
60+
end
61+
label + field
62+
end
63+
64+
65+
end
66+
67+
68+
end
69+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
OrdersHelper.module_eval do
2+
def truncate(text, options = {})
3+
super(strip_tags(text), options)
4+
end
5+
end
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ProductsHelper.module_eval do
2+
def variant_price_diff(variant)
3+
return product_price(variant) unless variant.product.master.price
4+
diff = product_price(variant, :format_as_currency => false) - product_price(variant.product, :format_as_currency => false)
5+
return nil if diff == 0
6+
if diff > 0
7+
"(+ #{format_price diff.abs})"
8+
else
9+
"(- #{format_price diff.abs})"
10+
end
11+
end
12+
13+
def product_description(product)
14+
raw(product.description)
15+
end
16+
17+
def large_sizes
18+
return @large_sizes if @large_sizes
19+
match = Image.attachment_definitions[:attachment][:styles][:large].match(/(\d+)x(\d+)/)
20+
@large_sizes = {:width => match[1], :height => match[2]}
21+
end
22+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
TaxonsHelper.module_eval do
2+
def taxon_preview(taxon, max=6)
3+
Rails.cache.fetch([taxon, 'preview'], :expires_in => LONG_INTERVAL) do
4+
taxon.active_products.includes(:master, :images).order("rand()").limit(max).all
5+
end
6+
end
7+
end

app/models/image_decorator.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Image.class_eval do
2+
attachment_definitions[:attachment][:styles] = { :mini => '50x50>', :small => '150x150>', :product => '240x240>', :large => '600x600>' }
3+
end

app/models/product_decorator.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Product.class_eval do
2+
3+
def similar_products(limit=4)
4+
Product.joins(:taxons).where(["products.id != ?", self.id]).where("taxons.id" => [5]).order("rand()").limit(limit)
5+
end
6+
7+
end

app/models/taxon_decorator.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Taxon.class_eval do
2+
attachment_definitions[:icon][:styles] = {:normal => '200x150>'}
3+
attachment_definitions[:icon][:default_url] = "/images/noimage/taxon.png"
4+
end

app/views/addresses/_form.html.erb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<% ADDRESS_FIELDS.each do |field| %>
2+
<div id="<%= [address_name, field].join('_') %>" class="control-group">
3+
<% if field == "country" %>
4+
<%= address_form.label :country_id, t(field, :scope => [:activerecord, :attributes, :address]), :class => "control-label" %>
5+
<div class="controls"><%= address_form.collection_select :country_id, available_countries, :id, :name, {}, {:class => 'required'} %></div>
6+
<% elsif field == "state" && Spree::Config[:address_requires_state] %>
7+
<%= address_field(address_form, :state, address_name) { address_state(address_form, address.country) } %>
8+
<% else %>
9+
<%= address_field(address_form, field.to_sym, address_name) %>
10+
<% end %>
11+
</div>
12+
<% end %>
13+
<% if Spree::Config["alternative_#{address_name}_phone"] %>
14+
<%= address_field(address_form, :alternative_phone, address_name) %>
15+
<% end %>

0 commit comments

Comments
 (0)