radiant-shop-extension 0.9.3 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -3
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/app/controllers/admin/shop/customers_controller.rb +35 -126
- data/app/controllers/shop/categories_controller.rb +1 -5
- data/app/controllers/shop/products_controller.rb +1 -1
- data/app/models/form_checkout.rb +198 -112
- data/app/models/shop_category.rb +3 -3
- data/app/models/shop_customer.rb +3 -12
- data/app/models/shop_order.rb +5 -3
- data/app/models/shop_payment.rb +0 -1
- data/app/models/shop_product.rb +3 -3
- data/app/views/admin/shop/customers/edit.html.haml +13 -0
- data/app/views/admin/shop/customers/edit/_fields.html.haml +33 -0
- data/app/views/admin/shop/customers/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/customers/edit/_meta.html.haml +7 -0
- data/app/views/admin/shop/customers/edit/_parts.html.haml +4 -0
- data/app/views/admin/shop/customers/edit/_popups.html.haml +3 -0
- data/app/views/admin/shop/customers/edit/meta/_login.html.haml +5 -0
- data/app/views/admin/shop/customers/edit/meta/_password.html.haml +5 -0
- data/app/views/admin/shop/customers/edit/meta/_password_confirmation.html.haml +5 -0
- data/app/views/admin/shop/customers/edit/parts/_address.html.haml +7 -0
- data/app/views/admin/shop/customers/edit/parts/_addresses.html.haml +13 -0
- data/app/views/admin/shop/customers/edit/parts/_orders.html.haml +29 -0
- data/app/views/admin/shop/customers/index.html.haml +9 -35
- data/app/views/admin/shop/customers/index/_bottom.html.haml +4 -0
- data/app/views/admin/shop/customers/index/_customer.html.haml +9 -0
- data/app/views/admin/shop/customers/new.html.haml +11 -0
- data/app/views/admin/shop/customers/remove.html.haml +12 -0
- data/app/views/admin/shop/products/new.html.haml +1 -1
- data/config/locales/en.yml +37 -29
- data/config/routes.rb +2 -0
- data/db/migrate/20100927041219_remove_payment_methods.rb +16 -0
- data/db/migrate/20100927041624_change_payments_add_gateway.rb +11 -0
- data/db/migrate/20100927140446_change_payment_add_card_type_card_number.rb +11 -0
- data/db/seed.rb +1 -0
- data/db/seeds/forms.rb +179 -0
- data/db/{migrate/20100520033059_create_layouts.rb → seeds/layouts.rb} +19 -27
- data/db/seeds/snippets.rb +23 -0
- data/lib/shop/interface/customers.rb +34 -0
- data/lib/shop/tags/address.rb +1 -0
- data/lib/shop/tags/card.rb +51 -0
- data/lib/shop/tags/helpers.rb +53 -38
- data/lib/shop/tags/item.rb +1 -1
- data/lib/shop/tags/product.rb +23 -22
- data/lib/shop/tags/responses.rb +3 -3
- data/lib/tasks/shop_extension_tasks.rake +6 -0
- data/public/stylesheets/sass/admin/extensions/shop/index.sass +64 -0
- data/radiant-shop-extension.gemspec +37 -6
- data/shop_extension.rb +7 -2
- data/spec/datasets/forms.rb +112 -118
- data/spec/datasets/shop_customers.rb +30 -0
- data/spec/datasets/shop_orders.rb +7 -3
- data/spec/datasets/shop_products.rb +1 -0
- data/spec/lib/shop/tags/card_spec.rb +71 -0
- data/spec/lib/shop/tags/helpers_spec.rb +270 -283
- data/spec/lib/shop/tags/item_spec.rb +9 -0
- data/spec/lib/shop/tags/product_spec.rb +172 -158
- data/spec/lib/shop/tags/responses_spec.rb +129 -0
- data/spec/models/form_checkout_spec.rb +228 -294
- data/spec/models/shop_category_page_spec.rb +2 -2
- data/spec/models/shop_order_spec.rb +27 -20
- data/spec/models/shop_product_attachment_spec.rb +1 -0
- metadata +61 -17
- data/app/models/shop_payment_method.rb +0 -5
- data/db/migrate/20100903122123_create_forms.rb +0 -44
- data/db/migrate/20100908063639_create_snippets.rb +0 -22
@@ -0,0 +1,11 @@
|
|
1
|
+
class ChangePaymentsAddGateway < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :shop_payments, :gateway, :string
|
4
|
+
add_index :shop_payments, :gateway
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_index :shop_payments, :gateway
|
9
|
+
remove_column :shop_payments, :gateway
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class ChangePaymentAddCardTypeCardNumber < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
add_column :shop_payments, :card_type, :string
|
4
|
+
add_column :shop_payments, :card_number, :string
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.down
|
8
|
+
remove_column :shop_payments, :card_type
|
9
|
+
remove_column :shop_payments, :card_number
|
10
|
+
end
|
11
|
+
end
|
data/db/seed.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) + "/seeds/*.rb"].each {|file| require file }
|
data/db/seeds/forms.rb
ADDED
@@ -0,0 +1,179 @@
|
|
1
|
+
puts "Seed Shop Forms";
|
2
|
+
|
3
|
+
# Add Cart Item
|
4
|
+
|
5
|
+
Form.create({
|
6
|
+
:title => 'AddCartItem',
|
7
|
+
:action => '/shop/cart/items',
|
8
|
+
:body => <<-BODY
|
9
|
+
<r:shop:product>
|
10
|
+
<input type="hidden" name="line_item[item_id]" value="<r:id />" />
|
11
|
+
<!-- Your Customisation Below -->
|
12
|
+
|
13
|
+
<r:form:text name='line_item[quantity]' value="1" /> <!-- Amount of items to add -->
|
14
|
+
<input type="submit" name="add_to_cart" id="add_to_cart_<r:id />" value="Add To Cart" />
|
15
|
+
|
16
|
+
<!-- Your Customisation Above -->
|
17
|
+
</r:shop:product>
|
18
|
+
BODY
|
19
|
+
})
|
20
|
+
|
21
|
+
# Update Cart Item
|
22
|
+
|
23
|
+
Form.create({
|
24
|
+
:title => 'UpdateCartItem',
|
25
|
+
:action => '/shop/cart/items/x',
|
26
|
+
:body => <<-BODY
|
27
|
+
<r:shop:cart:item>
|
28
|
+
<input type="hidden" name="_method" value="put" />
|
29
|
+
<input type="hidden" name="line_item[id]" value="<r:id />" />
|
30
|
+
<!-- Your Customisation Below -->
|
31
|
+
|
32
|
+
<input type="text" name="line_item[quantity]" value="<r:quantity />" />
|
33
|
+
<input type="submit" name="add_to_cart" id="update_<r:id />" value="Update" />
|
34
|
+
|
35
|
+
<!-- Your Customisation Above -->
|
36
|
+
</r:shop:cart:item>
|
37
|
+
BODY
|
38
|
+
})
|
39
|
+
|
40
|
+
# Checkout Addresses
|
41
|
+
|
42
|
+
addresses_body = <<-BODY
|
43
|
+
<r:shop:cart>
|
44
|
+
<div class="addresses">
|
45
|
+
<div id="billing" class="address">
|
46
|
+
<h4>Billing</h4>
|
47
|
+
<ol class="address">
|
48
|
+
<r:address type='billing'>
|
49
|
+
<r:if_address><input type="hidden" name="billing[id]" value="<r:id />" /></r:if_address>
|
50
|
+
<li>
|
51
|
+
<r:label for='billing[name]'>Full Name</r:label>
|
52
|
+
<input type="text" name="billing[name]" value="<r:name/>" />
|
53
|
+
</li>
|
54
|
+
<li>
|
55
|
+
<r:label for='billing[email]'>Email</r:label>
|
56
|
+
<input type="text" name="billing[email]" value="<r:email/>" />
|
57
|
+
</li>
|
58
|
+
<li>
|
59
|
+
<r:label for='billing[street]'>Street</r:label>
|
60
|
+
<input type="text" name="billing[street]" value="<r:street/>" />
|
61
|
+
</li>
|
62
|
+
<li>
|
63
|
+
<r:label for='billing[city]'>Suburb and Postcode</r:label>
|
64
|
+
<input type="text" name="billing[city]" value="<r:city/>" />
|
65
|
+
<input type="text" name="billing[postcode]" value="<r:postcode/>" />
|
66
|
+
</li>
|
67
|
+
<li>
|
68
|
+
<r:label for='billing[state]'>State and Country</r:label>
|
69
|
+
<input type="text" name="billing[state]" value="<r:state/>" />
|
70
|
+
<input type="text" name="billing[country]" value="<r:country/>" />
|
71
|
+
</li>
|
72
|
+
</r:address>
|
73
|
+
</ol>
|
74
|
+
</div>
|
75
|
+
|
76
|
+
<div id="shipping" class="address">
|
77
|
+
<h4>Shipping</h4>
|
78
|
+
<ol class="address">
|
79
|
+
<r:address type='shipping'>
|
80
|
+
<r:if_address><input type="hidden" name="shipping[id]" value="<r:id />" /></r:if_address>
|
81
|
+
<li>
|
82
|
+
<r:label for='shipping[name]'>Full Name</r:label>
|
83
|
+
<input type="text" name="shipping[name]" value="<r:name/>" />
|
84
|
+
</li>
|
85
|
+
<li>
|
86
|
+
<r:label for='shipping[email]'>Email</r:label>
|
87
|
+
<input type="text" name="shipping[email]" value="<r:email/>" />
|
88
|
+
</li>
|
89
|
+
<li>
|
90
|
+
<r:label for='shipping[street]'>Street</r:label>
|
91
|
+
<input type="text" name="shipping[street]" value="<r:street/>" />
|
92
|
+
</li>
|
93
|
+
<li>
|
94
|
+
<r:label for='shipping[city]'>Suburb and Postcode</r:label>
|
95
|
+
<input type="text" name="shipping[city]" value="<r:city/>" />
|
96
|
+
<input type="text" name="shipping[postcode]" value="<r:postcode/>" />
|
97
|
+
</li>
|
98
|
+
<li>
|
99
|
+
<r:label for='shipping[state]'>State and Country</r:label>
|
100
|
+
<input type="text" name="shipping[state]" value="<r:state/>" />
|
101
|
+
<input type="text" name="shipping[country]" value="<r:country/>" />
|
102
|
+
</li>
|
103
|
+
</r:address>
|
104
|
+
</ol>
|
105
|
+
</div>
|
106
|
+
</div>
|
107
|
+
</r:shop:cart>
|
108
|
+
|
109
|
+
<r:submit value="Save Addresses" />
|
110
|
+
BODY
|
111
|
+
|
112
|
+
addresses_config = <<-CONFIG
|
113
|
+
checkout:
|
114
|
+
address:
|
115
|
+
billing: true
|
116
|
+
shipping: true
|
117
|
+
CONFIG
|
118
|
+
|
119
|
+
Forms.create({
|
120
|
+
:title => 'CheckoutAddresses',
|
121
|
+
:redirect_to => '/shop',
|
122
|
+
:body => addresses_body,
|
123
|
+
:config => addresses_config
|
124
|
+
})
|
125
|
+
|
126
|
+
eway_body = <<-BODY
|
127
|
+
<r:shop:cart>
|
128
|
+
<ol class="card">
|
129
|
+
<li>
|
130
|
+
<r:label for='card[type]'>Type of Card</r:label>
|
131
|
+
<r:select name='card[type]'>
|
132
|
+
<r:option value='visa'>Visa</r:option>
|
133
|
+
<r:option value='mastercard'>Master Card</r:option>
|
134
|
+
<r:option value='diners'>Diners Club</r:option>
|
135
|
+
<r:option vlaue='amex'>AMEX</r:option>
|
136
|
+
</r:select>
|
137
|
+
</li>
|
138
|
+
<li>
|
139
|
+
<r:label for='card[name]'>Name on Card</r:label>
|
140
|
+
<r:text name='card[name]' />
|
141
|
+
</li>
|
142
|
+
<li>
|
143
|
+
<r:label for='card[number]'>Card Number</r:label>
|
144
|
+
<r:text name='card[number]' />
|
145
|
+
</li>
|
146
|
+
<li>
|
147
|
+
<r:label for='card[verification]'>Verification Code</r:label>
|
148
|
+
<r:text name='card[verification]' length='4' />
|
149
|
+
</li>
|
150
|
+
<li>
|
151
|
+
<r:label for='card[month]'>Date on Card</r:label>
|
152
|
+
<r:select:card:month />
|
153
|
+
<r:select:card:year />
|
154
|
+
</li>
|
155
|
+
</ol>
|
156
|
+
</r:shop:cart>
|
157
|
+
|
158
|
+
<h3>Special Instructions</h3>
|
159
|
+
|
160
|
+
<p><textarea name="order[message]"></textarea></p>
|
161
|
+
|
162
|
+
<r:shop:cart:address type='billing'>
|
163
|
+
<input type="hidden" name="options[address][address1]" value="<r:street />" />
|
164
|
+
<input type="hidden" name="options[address][city]" value="<r:city />" />
|
165
|
+
<input type="hidden" name="options[address][state]" value="<r:state />" />
|
166
|
+
<input type="hidden" name="options[address][country]" value="<r:country />" />
|
167
|
+
<input type="hidden" name="options[address][zip]" value="<r:postcode />" />
|
168
|
+
<input type="hidden" name="options[email]" value="<r:email />" />
|
169
|
+
<input type="hidden" name="options[description]" value="<r:config:setting key='site.url' /> order #<r:shop:cart:id />" />
|
170
|
+
</r:shop:cart:address>
|
171
|
+
|
172
|
+
<r:submit value="Place Order" />
|
173
|
+
|
174
|
+
<r:snippet name='PaymentResponse' />
|
175
|
+
BODY
|
176
|
+
|
177
|
+
eway_config = <<-CONFIG
|
178
|
+
|
179
|
+
CONFIG
|
@@ -1,9 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
Layout.create({
|
5
|
-
:name => 'Application',
|
6
|
-
:content => <<-CONTENT
|
1
|
+
Layout.create({
|
2
|
+
:name => 'Application',
|
3
|
+
:content => <<-CONTENT
|
7
4
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
8
5
|
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
9
6
|
<head>
|
@@ -15,11 +12,11 @@ class CreateLayouts < ActiveRecord::Migration
|
|
15
12
|
</body>
|
16
13
|
</html>
|
17
14
|
CONTENT
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
})
|
16
|
+
|
17
|
+
Layout.create({
|
18
|
+
:name => Radiant::Config['shop.product_layout'],
|
19
|
+
:content => <<-CONTENT
|
23
20
|
<r:inside_layout name='Application'>
|
24
21
|
<r:shop:product>
|
25
22
|
<div id="shop_product_<r:sku />" class="shop_product">
|
@@ -49,10 +46,11 @@ CONTENT
|
|
49
46
|
</r:shop:product>
|
50
47
|
</r:inside_layout>
|
51
48
|
CONTENT
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
})
|
50
|
+
|
51
|
+
Layout.create({
|
52
|
+
:name => Radiant::Config['shop.category_layout'],
|
53
|
+
:content => <<-CONTENT
|
56
54
|
<r:inside_layout name='Application'>
|
57
55
|
<r:shop:category>
|
58
56
|
<div id="shop_category_<r:handle />" class="shop_category">
|
@@ -81,11 +79,11 @@ CONTENT
|
|
81
79
|
</r:shop:category>
|
82
80
|
</r:inside_layout>
|
83
81
|
CONTENT
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
82
|
+
})
|
83
|
+
|
84
|
+
Layout.create({
|
85
|
+
:name => Radiant::Config['shop.order_layout'],
|
86
|
+
:content => <<-CONTENT
|
89
87
|
<r:inside_layout name='Application'>
|
90
88
|
<r:shop:cart>
|
91
89
|
<r:if_items>
|
@@ -110,10 +108,4 @@ CONTENT
|
|
110
108
|
</r:shop:cart>
|
111
109
|
</r:inside_layout>
|
112
110
|
CONTENT
|
113
|
-
|
114
|
-
end
|
115
|
-
|
116
|
-
def self.down
|
117
|
-
# Won't delete content, that would be cruel
|
118
|
-
end
|
119
|
-
end
|
111
|
+
})
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Snippet.create({
|
2
|
+
:name => 'CartOverview',
|
3
|
+
:content => <<-BEGIN
|
4
|
+
<r:shop:cart>
|
5
|
+
<r:if_items>
|
6
|
+
<span class="quantity"><r:quantity /></span>
|
7
|
+
<span class="price"><r:price /></span>
|
8
|
+
<r:link>checkout</r:link>
|
9
|
+
</r:if_items>
|
10
|
+
<r:unless_items>
|
11
|
+
<p>Your cart is empty</p>
|
12
|
+
</r:unless_items>
|
13
|
+
</r:shop:cart>
|
14
|
+
BEGIN
|
15
|
+
})
|
16
|
+
|
17
|
+
PaymentResponse
|
18
|
+
|
19
|
+
<r:response:checkout:payment:unless_success>
|
20
|
+
<p>We couldn't process your payment: <strong><r:response:get name="results[checkout][payment][message]" /></strong></p>
|
21
|
+
</r:response:checkout:payment:unless_success>
|
22
|
+
|
23
|
+
<r:response:clear />
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Shop
|
2
|
+
module Interface
|
3
|
+
module Customers
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.send :include, InstanceMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
attr_accessor :customers
|
11
|
+
|
12
|
+
protected
|
13
|
+
def load_default_shop_customers_regions
|
14
|
+
returning OpenStruct.new do |customers|
|
15
|
+
customers.edit = Radiant::AdminUI::RegionSet.new do |edit|
|
16
|
+
edit.main.concat %w{header form popups}
|
17
|
+
edit.form.concat %w{name email meta parts}
|
18
|
+
edit.bottom.concat %w{buttons timestamp}
|
19
|
+
end
|
20
|
+
customers.new = customers.edit
|
21
|
+
customers.index = Radiant::AdminUI::RegionSet.new do |index|
|
22
|
+
index.top
|
23
|
+
index.bottom.concat %w{ add }
|
24
|
+
index.thead.concat %w{ name modify }
|
25
|
+
index.customer.concat %w{ name modify }
|
26
|
+
end
|
27
|
+
customers.remove = customers.index
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/shop/tags/address.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Shop
|
2
|
+
module Tags
|
3
|
+
module Card
|
4
|
+
|
5
|
+
TYPES = {
|
6
|
+
'visa' => 'Visa',
|
7
|
+
'mastercard' => 'Master Card',
|
8
|
+
'diners' => 'Diners Club',
|
9
|
+
'amex' => 'American Express'
|
10
|
+
}
|
11
|
+
|
12
|
+
include Radiant::Taggable
|
13
|
+
|
14
|
+
tag 'form:card' do |tag|
|
15
|
+
tag.expand
|
16
|
+
end
|
17
|
+
|
18
|
+
# Outputs a list of credit card types
|
19
|
+
desc %{ Outputs a list of credit card types }
|
20
|
+
tag 'form:card:type' do |tag|
|
21
|
+
content = %{<select name="card[type]" id="card_type">\n}
|
22
|
+
TYPES.sort.each do |k, v|
|
23
|
+
content << %{<option value="#{k}">#{v}</option>\n}
|
24
|
+
end
|
25
|
+
content << %{</select>}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Outputs a list of months for credit cards
|
29
|
+
desc %{ Outputs a list of months for credit cards }
|
30
|
+
tag 'form:card:month' do |tag|
|
31
|
+
content = %{<select name="card[month]" id="card_month">\n}
|
32
|
+
Date::MONTHNAMES[1,12].each_with_index do |name,index|
|
33
|
+
month = sprintf('%02d', index+1)
|
34
|
+
content << %{<option value="#{month}">#{month} - #{name}</option>\n}
|
35
|
+
end
|
36
|
+
content << %{</select>}
|
37
|
+
end
|
38
|
+
|
39
|
+
# Ouputs a list of years for credit cards
|
40
|
+
desc %{ Ouputs a list of years for credit cards }
|
41
|
+
tag 'form:card:year' do |tag|
|
42
|
+
content = %{<select name="card[year]" id="card_year">\n}
|
43
|
+
(Time.new.year ... Time.new.year + 10).each do |year|
|
44
|
+
content << %{<option value="#{year}">#{year}</option>\n}
|
45
|
+
end
|
46
|
+
content << %{</select>}
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/shop/tags/helpers.rb
CHANGED
@@ -6,15 +6,19 @@ module Shop
|
|
6
6
|
def current_categories(tag)
|
7
7
|
result = []
|
8
8
|
|
9
|
-
# Page params are protected, send is used to overcome this
|
10
9
|
if tag.locals.shop_categories.present?
|
11
10
|
result = tag.locals.shop_categories
|
11
|
+
|
12
|
+
# Page params are protected, send is used to overcome this
|
12
13
|
elsif tag.locals.page.send(:params).has_key? 'query'
|
13
|
-
result = ShopCategory.search(tag.locals.page.params['query'])
|
14
|
+
result = ShopCategory.search(tag.locals.page.send(:params)['query'])
|
15
|
+
|
14
16
|
elsif tag.attr['key'] and tag.attr['value']
|
15
17
|
result = ShopCategory.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
18
|
+
|
16
19
|
else
|
17
20
|
result = ShopCategory.all
|
21
|
+
|
18
22
|
end
|
19
23
|
|
20
24
|
result
|
@@ -25,16 +29,22 @@ module Shop
|
|
25
29
|
|
26
30
|
if tag.locals.shop_category.present?
|
27
31
|
result = tag.locals.shop_category
|
32
|
+
|
33
|
+
elsif tag.locals.shop_product.present?
|
34
|
+
result = tag.locals.shop_product.category
|
35
|
+
|
28
36
|
elsif tag.attr['key'] and tag.attr['value']
|
29
37
|
result = ShopCategory.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
38
|
+
|
30
39
|
elsif tag.locals.page.shop_category.present?
|
31
40
|
result = tag.locals.page.shop_category
|
41
|
+
|
32
42
|
elsif tag.locals.page.shop_product.present?
|
33
43
|
result = tag.locals.page.shop_product.category
|
34
|
-
|
35
|
-
result = tag.locals.shop_product.category
|
44
|
+
|
36
45
|
else
|
37
46
|
result = ShopCategory.find_by_handle(tag.locals.page.slug)
|
47
|
+
|
38
48
|
end
|
39
49
|
|
40
50
|
result
|
@@ -45,33 +55,42 @@ module Shop
|
|
45
55
|
|
46
56
|
if tag.locals.shop_products.present?
|
47
57
|
result = tag.locals.shop_products
|
58
|
+
|
59
|
+
elsif tag.locals.shop_category.present?
|
60
|
+
result = tag.locals.shop_category.products
|
61
|
+
|
48
62
|
elsif tag.locals.page.send(:params).has_key? 'query'
|
49
63
|
result = ShopProduct.search(tag.locals.page.params['query'])
|
64
|
+
|
50
65
|
elsif tag.attr['key'] and tag.attr['value']
|
51
66
|
result = ShopProduct.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
67
|
+
|
52
68
|
elsif tag.locals.page.shop_category.present?
|
53
|
-
result = tag.locals.page.shop_category.products
|
54
|
-
|
55
|
-
result = tag.locals.shop_category.products
|
69
|
+
result = tag.locals.page.shop_category.products
|
70
|
+
|
56
71
|
else
|
57
72
|
result = ShopProduct.all
|
73
|
+
|
58
74
|
end
|
59
75
|
|
60
76
|
result
|
61
77
|
end
|
62
78
|
|
63
79
|
def current_product(tag)
|
64
|
-
|
65
80
|
result = nil
|
66
|
-
|
81
|
+
|
67
82
|
if tag.locals.shop_product.present?
|
68
83
|
result = tag.locals.shop_product
|
69
|
-
|
70
|
-
result = tag.locals.page.shop_product
|
84
|
+
|
71
85
|
elsif tag.attr['key'] and tag.attr['value']
|
72
86
|
result = ShopProduct.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
87
|
+
|
88
|
+
elsif tag.locals.page.shop_product.present?
|
89
|
+
result = tag.locals.page.shop_product
|
90
|
+
|
73
91
|
else
|
74
92
|
result = ShopProduct.find_by_sku(tag.locals.page.slug)
|
93
|
+
|
75
94
|
end
|
76
95
|
|
77
96
|
result
|
@@ -80,17 +99,16 @@ module Shop
|
|
80
99
|
def current_order(tag)
|
81
100
|
result = nil
|
82
101
|
|
83
|
-
if
|
102
|
+
if tag.locals.shop_order.present?
|
84
103
|
result = tag.locals.shop_order
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
104
|
+
|
105
|
+
elsif tag.attr['key'] and tag.attr['value']
|
106
|
+
result = ShopOrder.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
107
|
+
|
108
|
+
elsif tag.locals.page.request.session[:shop_order].present?
|
109
|
+
session = tag.locals.page.request.session[:shop_order]
|
110
|
+
result = ShopOrder.find(session)
|
111
|
+
|
94
112
|
end
|
95
113
|
|
96
114
|
result
|
@@ -101,12 +119,10 @@ module Shop
|
|
101
119
|
|
102
120
|
if tag.locals.shop_line_item.present?
|
103
121
|
result = tag.locals.shop_line_item
|
104
|
-
elsif tag.locals.shop_product.present?
|
105
|
-
order = tag.locals.shop_order
|
106
|
-
product = tag.locals.shop_product
|
107
|
-
item = order.line_items.find_by_item_id(product.id)
|
108
122
|
|
109
|
-
|
123
|
+
elsif tag.locals.shop_order.present? and tag.locals.shop_product.present?
|
124
|
+
result = tag.locals.shop_order.line_items.find_by_item_id(tag.locals.shop_product.id)
|
125
|
+
|
110
126
|
end
|
111
127
|
|
112
128
|
result
|
@@ -117,23 +133,22 @@ module Shop
|
|
117
133
|
def current_address(tag)
|
118
134
|
result = nil
|
119
135
|
|
120
|
-
if tag.locals.address.present?
|
136
|
+
if tag.locals.address.present? and tag.locals.address_type == tag.attr['type']
|
121
137
|
result = tag.locals.address
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
result = address # The result is that address
|
129
|
-
end
|
130
|
-
rescue
|
131
|
-
result = nil # Will catch an incorrect address type being send
|
138
|
+
|
139
|
+
elsif tag.locals.shop_order.present?
|
140
|
+
begin
|
141
|
+
address = tag.locals.shop_order.send(tag.attr['type']) # Get the address type (order.billing)
|
142
|
+
if address.present? # If that address exists
|
143
|
+
result = address # The result is that address
|
132
144
|
end
|
145
|
+
rescue
|
146
|
+
result = nil # Will catch an incorrect address type being send
|
133
147
|
end
|
148
|
+
|
134
149
|
end
|
135
150
|
|
136
|
-
result
|
151
|
+
result
|
137
152
|
end
|
138
153
|
|
139
154
|
end
|