radiant-shop-extension 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +26 -0
- data/Gemfile.lock +75 -0
- data/HISTORY.md +77 -0
- data/MIT-LICENSE +20 -0
- data/README.md +26 -0
- data/Rakefile +141 -0
- data/VERSION +1 -0
- data/app/.DS_Store +0 -0
- data/app/controllers/admin/shop/categories_controller.rb +206 -0
- data/app/controllers/admin/shop/customers_controller.rb +137 -0
- data/app/controllers/admin/shop/orders_controller.rb +171 -0
- data/app/controllers/admin/shop/products/images_controller.rb +144 -0
- data/app/controllers/admin/shop/products_controller.rb +217 -0
- data/app/controllers/admin/shops_controller.rb +9 -0
- data/app/controllers/shop/categories_controller.rb +49 -0
- data/app/controllers/shop/line_items_controller.rb +165 -0
- data/app/controllers/shop/orders_controller.rb +16 -0
- data/app/controllers/shop/products_controller.rb +48 -0
- data/app/models/form_checkout.rb +245 -0
- data/app/models/shop_address.rb +13 -0
- data/app/models/shop_addressable.rb +11 -0
- data/app/models/shop_category.rb +85 -0
- data/app/models/shop_category_page.rb +7 -0
- data/app/models/shop_customer.rb +27 -0
- data/app/models/shop_line_item.rb +32 -0
- data/app/models/shop_order.rb +108 -0
- data/app/models/shop_payment.rb +6 -0
- data/app/models/shop_payment_method.rb +5 -0
- data/app/models/shop_product.rb +87 -0
- data/app/models/shop_product_attachment.rb +30 -0
- data/app/models/shop_product_page.rb +7 -0
- data/app/views/.DS_Store +0 -0
- data/app/views/admin/.DS_Store +0 -0
- data/app/views/admin/pages/_shop_category.html.haml +4 -0
- data/app/views/admin/pages/_shop_product.html.haml +4 -0
- data/app/views/admin/shop/categories/edit.html.haml +12 -0
- data/app/views/admin/shop/categories/edit/_fields.html.haml +28 -0
- data/app/views/admin/shop/categories/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/categories/edit/_meta.html.haml +7 -0
- data/app/views/admin/shop/categories/edit/_part.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/_popup.html.haml +3 -0
- data/app/views/admin/shop/categories/edit/meta/_handle.html.haml +5 -0
- data/app/views/admin/shop/categories/edit/meta/_layouts.html.haml +10 -0
- data/app/views/admin/shop/categories/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/categories/index/_category.html.haml +16 -0
- data/app/views/admin/shop/categories/new.html.haml +10 -0
- data/app/views/admin/shop/categories/remove.html.haml +12 -0
- data/app/views/admin/shop/customers/index.html.haml +36 -0
- data/app/views/admin/shop/orders/index.html.haml +33 -0
- data/app/views/admin/shop/products/edit.html.haml +14 -0
- data/app/views/admin/shop/products/edit/_fields.html.haml +38 -0
- data/app/views/admin/shop/products/edit/_head.html.haml +2 -0
- data/app/views/admin/shop/products/edit/_image.html.haml +12 -0
- data/app/views/admin/shop/products/edit/_meta.html.haml +8 -0
- data/app/views/admin/shop/products/edit/_part.html.haml +3 -0
- data/app/views/admin/shop/products/edit/_popup.html.haml +3 -0
- data/app/views/admin/shop/products/edit/buttons/_browse_images.html.haml +1 -0
- data/app/views/admin/shop/products/edit/buttons/_new_image.html.haml +1 -0
- data/app/views/admin/shop/products/edit/meta/_category.html.haml +5 -0
- data/app/views/admin/shop/products/edit/meta/_sku.html.haml +5 -0
- data/app/views/admin/shop/products/edit/parts/_description.html.haml +1 -0
- data/app/views/admin/shop/products/edit/parts/_images.html.haml +5 -0
- data/app/views/admin/shop/products/edit/popups/_browse_images.html.haml +6 -0
- data/app/views/admin/shop/products/edit/popups/_new_image.html.haml +18 -0
- data/app/views/admin/shop/products/index.html.haml +10 -0
- data/app/views/admin/shop/products/index/_bottom.html.haml +5 -0
- data/app/views/admin/shop/products/index/_product.html.haml +13 -0
- data/app/views/admin/shop/products/new.html.haml +10 -0
- data/app/views/admin/shop/products/remove.html.haml +12 -0
- data/app/views/shop/categories/show.html.haml +1 -0
- data/app/views/shop/orders/show.html.haml +1 -0
- data/app/views/shop/products/index.html.haml +1 -0
- data/app/views/shop/products/show.html.haml +1 -0
- data/config/locales/en.yml +50 -0
- data/config/routes.rb +38 -0
- data/config/shop_cart.yml +16 -0
- data/cucumber.yml +1 -0
- data/db/migrate/20100311053701_initial.rb +153 -0
- data/db/migrate/20100520033059_create_layouts.rb +119 -0
- data/db/migrate/20100903122123_create_forms.rb +44 -0
- data/db/migrate/20100908063639_create_snippets.rb +22 -0
- data/features/support/env.rb +16 -0
- data/features/support/paths.rb +14 -0
- data/lib/shop/controllers/application_controller.rb +39 -0
- data/lib/shop/controllers/site_controller.rb +12 -0
- data/lib/shop/interface/products.rb +49 -0
- data/lib/shop/models/image.rb +14 -0
- data/lib/shop/models/page.rb +14 -0
- data/lib/shop/tags/address.rb +40 -0
- data/lib/shop/tags/cart.rb +49 -0
- data/lib/shop/tags/category.rb +83 -0
- data/lib/shop/tags/core.rb +12 -0
- data/lib/shop/tags/helpers.rb +142 -0
- data/lib/shop/tags/item.rb +109 -0
- data/lib/shop/tags/product.rb +109 -0
- data/lib/shop/tags/responses.rb +34 -0
- data/lib/tasks/shop_extension_tasks.rake +54 -0
- data/mockups/balsamiq/products-retro_fun_tshirt-more.bmml +0 -0
- data/mockups/balsamiq/products-retro_fun_tshirt.bmml +0 -0
- data/public/images/admin/extensions/shop/products/sort.png +0 -0
- data/public/javascripts/admin/extensions/shop/products/edit.js +115 -0
- data/public/javascripts/admin/extensions/shop/products/index.js +65 -0
- data/public/stylesheets/sass/admin/extensions/shop/edit.sass +86 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/edit.sass +158 -0
- data/public/stylesheets/sass/admin/extensions/shop/products/index.sass +129 -0
- data/radiant-shop-extension.gemspec +245 -0
- data/shop_extension.rb +62 -0
- data/spec/controllers/admin/shop/categories_controller_spec.rb +443 -0
- data/spec/controllers/admin/shop/products/images_controller_spec.rb +477 -0
- data/spec/controllers/admin/shop/products_controller_spec.rb +394 -0
- data/spec/controllers/admin/shops_controller_spec.rb +19 -0
- data/spec/controllers/shop/categories_controller_spec.rb +42 -0
- data/spec/controllers/shop/line_items_controller_spec.rb +256 -0
- data/spec/controllers/shop/orders_controller_specs.rb +37 -0
- data/spec/controllers/shop/products_controller_spec.rb +51 -0
- data/spec/datasets/forms.rb +153 -0
- data/spec/datasets/images.rb +13 -0
- data/spec/datasets/shop_addresses.rb +27 -0
- data/spec/datasets/shop_categories.rb +13 -0
- data/spec/datasets/shop_line_items.rb +9 -0
- data/spec/datasets/shop_orders.rb +21 -0
- data/spec/datasets/shop_products.rb +34 -0
- data/spec/helpers/nested_tag_helper.rb +33 -0
- data/spec/lib/shop/models/image_spec.rb +28 -0
- data/spec/lib/shop/models/page_spec.rb +38 -0
- data/spec/lib/shop/tags/address_spec.rb +196 -0
- data/spec/lib/shop/tags/cart_spec.rb +169 -0
- data/spec/lib/shop/tags/category_spec.rb +201 -0
- data/spec/lib/shop/tags/core_spec.rb +16 -0
- data/spec/lib/shop/tags/helpers_spec.rb +381 -0
- data/spec/lib/shop/tags/item_spec.rb +313 -0
- data/spec/lib/shop/tags/product_spec.rb +334 -0
- data/spec/matchers/comparison.rb +72 -0
- data/spec/matchers/render_matcher.rb +33 -0
- data/spec/models/form_checkout_spec.rb +376 -0
- data/spec/models/shop_category_page_spec.rb +10 -0
- data/spec/models/shop_category_spec.rb +58 -0
- data/spec/models/shop_line_item_spec.rb +42 -0
- data/spec/models/shop_order_spec.rb +228 -0
- data/spec/models/shop_product_attachment_spec.rb +72 -0
- data/spec/models/shop_product_page_spec.rb +10 -0
- data/spec/models/shop_product_spec.rb +135 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +22 -0
- data/vendor/plugins/acts_as_list/README +23 -0
- data/vendor/plugins/acts_as_list/init.rb +3 -0
- data/vendor/plugins/acts_as_list/lib/active_record/acts/list.rb +256 -0
- data/vendor/plugins/acts_as_list/test/list_test.rb +332 -0
- data/vendor/plugins/json_fields/.gitignore +3 -0
- data/vendor/plugins/json_fields/MIT-LICENSE +20 -0
- data/vendor/plugins/json_fields/README.rdoc +65 -0
- data/vendor/plugins/json_fields/Rakefile +55 -0
- data/vendor/plugins/json_fields/init.rb +2 -0
- data/vendor/plugins/json_fields/lib/json_fields.rb +99 -0
- data/vendor/plugins/json_fields/spec/lib/json_fields_spec.rb +124 -0
- data/vendor/plugins/json_fields/spec/spec.opts +6 -0
- data/vendor/plugins/json_fields/spec/spec_helper.rb +29 -0
- data/vendor/plugins/json_fields/spec/test_models.rb +12 -0
- metadata +324 -0
@@ -0,0 +1,83 @@
|
|
1
|
+
module Shop
|
2
|
+
module Tags
|
3
|
+
module Category
|
4
|
+
include Radiant::Taggable
|
5
|
+
|
6
|
+
desc %{ expands if there are shop categories within the context }
|
7
|
+
tag 'shop:if_categories' do |tag|
|
8
|
+
tag.expand if Helpers.current_categories(tag).present?
|
9
|
+
end
|
10
|
+
|
11
|
+
desc %{ expands if there are not shop categories within the context }
|
12
|
+
tag 'shop:unless_categories' do |tag|
|
13
|
+
tag.expand unless Helpers.current_categories(tag).present?
|
14
|
+
end
|
15
|
+
|
16
|
+
tag 'shop:categories' do |tag|
|
17
|
+
tag.locals.shop_categories = Helpers.current_categories(tag)
|
18
|
+
tag.expand if tag.locals.shop_categories.present?
|
19
|
+
end
|
20
|
+
|
21
|
+
desc %{ iterates through each product category }
|
22
|
+
tag 'shop:categories:each' do |tag|
|
23
|
+
content = ''
|
24
|
+
categories = tag.locals.shop_categories
|
25
|
+
|
26
|
+
categories.each do |category|
|
27
|
+
tag.locals.shop_category = category
|
28
|
+
content << tag.expand
|
29
|
+
end
|
30
|
+
|
31
|
+
content
|
32
|
+
end
|
33
|
+
|
34
|
+
tag 'shop:category' do |tag|
|
35
|
+
tag.locals.shop_category = Helpers.current_category(tag)
|
36
|
+
tag.expand unless tag.locals.shop_category.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
tag 'shop:category:if_current' do |tag|
|
40
|
+
|
41
|
+
if tag.locals.shop_category.handle == tag.locals.page.slug
|
42
|
+
# Looking at the shop_category generated page
|
43
|
+
tag.expand
|
44
|
+
elsif tag.locals.page.shop_category_id == tag.locals.shop_category.id
|
45
|
+
# A category page which is using this category
|
46
|
+
tag.expand
|
47
|
+
elsif tag.locals.shop_product
|
48
|
+
# A product page
|
49
|
+
if tag.locals.shop_product.category == tag.locals.shop_category
|
50
|
+
# Where the products category is this category
|
51
|
+
tag.expand
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
[:id, :name, :handle, :slug].each do |symbol|
|
58
|
+
desc %{ outputs the #{symbol} of the current shop category }
|
59
|
+
tag "shop:category:#{symbol}" do |tag|
|
60
|
+
tag.locals.shop_category.send(symbol)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc %{ outputs the description of the current shop category }
|
65
|
+
tag "shop:category:description" do |tag|
|
66
|
+
parse(TextileFilter.filter(tag.locals.shop_category.description))
|
67
|
+
end
|
68
|
+
|
69
|
+
desc %{ returns a link to the current category }
|
70
|
+
tag 'shop:category:link' do |tag|
|
71
|
+
category = tag.locals.shop_category
|
72
|
+
options = tag.attr.dup
|
73
|
+
attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip
|
74
|
+
attributes = " #{attributes}" unless attributes.empty?
|
75
|
+
|
76
|
+
text = tag.double? ? tag.expand : category.name
|
77
|
+
|
78
|
+
%{<a href="#{category.slug}"#{attributes}>#{text}</a>}
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
module Shop
|
2
|
+
module Tags
|
3
|
+
class Helpers
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def current_categories(tag)
|
7
|
+
result = []
|
8
|
+
|
9
|
+
# Page params are protected, send is used to overcome this
|
10
|
+
if tag.locals.shop_categories.present?
|
11
|
+
result = tag.locals.shop_categories
|
12
|
+
elsif tag.locals.page.send(:params).has_key? 'query'
|
13
|
+
result = ShopCategory.search(tag.locals.page.params['query'])
|
14
|
+
elsif tag.attr['key'] and tag.attr['value']
|
15
|
+
result = ShopCategory.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
16
|
+
else
|
17
|
+
result = ShopCategory.all
|
18
|
+
end
|
19
|
+
|
20
|
+
result
|
21
|
+
end
|
22
|
+
|
23
|
+
def current_category(tag)
|
24
|
+
result = nil
|
25
|
+
|
26
|
+
if tag.locals.shop_category.present?
|
27
|
+
result = tag.locals.shop_category
|
28
|
+
elsif tag.attr['key'] and tag.attr['value']
|
29
|
+
result = ShopCategory.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
30
|
+
elsif tag.locals.page.shop_category.present?
|
31
|
+
result = tag.locals.page.shop_category
|
32
|
+
elsif tag.locals.page.shop_product.present?
|
33
|
+
result = tag.locals.page.shop_product.category
|
34
|
+
elsif tag.locals.shop_product.present?
|
35
|
+
result = tag.locals.shop_product.category
|
36
|
+
else
|
37
|
+
result = ShopCategory.find_by_handle(tag.locals.page.slug)
|
38
|
+
end
|
39
|
+
|
40
|
+
result
|
41
|
+
end
|
42
|
+
|
43
|
+
def current_products(tag)
|
44
|
+
result = nil
|
45
|
+
|
46
|
+
if tag.locals.shop_products.present?
|
47
|
+
result = tag.locals.shop_products
|
48
|
+
elsif tag.locals.page.send(:params).has_key? 'query'
|
49
|
+
result = ShopProduct.search(tag.locals.page.params['query'])
|
50
|
+
elsif tag.attr['key'] and tag.attr['value']
|
51
|
+
result = ShopProduct.all(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
52
|
+
elsif tag.locals.page.shop_category.present?
|
53
|
+
result = tag.locals.page.shop_category.products
|
54
|
+
elsif tag.locals.shop_category.present?
|
55
|
+
result = tag.locals.shop_category.products
|
56
|
+
else
|
57
|
+
result = ShopProduct.all
|
58
|
+
end
|
59
|
+
|
60
|
+
result
|
61
|
+
end
|
62
|
+
|
63
|
+
def current_product(tag)
|
64
|
+
|
65
|
+
result = nil
|
66
|
+
|
67
|
+
if tag.locals.shop_product.present?
|
68
|
+
result = tag.locals.shop_product
|
69
|
+
elsif tag.locals.page.shop_product.present?
|
70
|
+
result = tag.locals.page.shop_product
|
71
|
+
elsif tag.attr['key'] and tag.attr['value']
|
72
|
+
result = ShopProduct.first(:conditions => { tag.attr['key'].downcase.to_sym => tag.attr['value'] })
|
73
|
+
else
|
74
|
+
result = ShopProduct.find_by_sku(tag.locals.page.slug)
|
75
|
+
end
|
76
|
+
|
77
|
+
result
|
78
|
+
end
|
79
|
+
|
80
|
+
def current_order(tag)
|
81
|
+
result = nil
|
82
|
+
|
83
|
+
if !tag.locals.shop_order.nil?
|
84
|
+
result = tag.locals.shop_order
|
85
|
+
elsif tag.attr['id']
|
86
|
+
result = ShopOrder.find(tag.attr['id'])
|
87
|
+
elsif tag.locals.page.request.session[:shop_order]
|
88
|
+
begin
|
89
|
+
result = ShopOrder.find(tag.locals.page.request.session[:shop_order])
|
90
|
+
rescue
|
91
|
+
result = ShopOrder.create
|
92
|
+
tag.locals.page.request.session[:shop_order] = result.id
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
result
|
97
|
+
end
|
98
|
+
|
99
|
+
def current_line_item(tag)
|
100
|
+
result = nil
|
101
|
+
|
102
|
+
if tag.locals.shop_line_item.present?
|
103
|
+
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
|
+
|
109
|
+
result = item
|
110
|
+
end
|
111
|
+
|
112
|
+
result
|
113
|
+
end
|
114
|
+
|
115
|
+
# Return the current address for the current order
|
116
|
+
# @tag['attr]['type'] = the address type (billing|shippin)
|
117
|
+
def current_address(tag)
|
118
|
+
result = nil
|
119
|
+
|
120
|
+
if tag.locals.address.present?
|
121
|
+
result = tag.locals.address
|
122
|
+
else
|
123
|
+
order = current_order(tag) # we need the current order
|
124
|
+
if order.present? # if it exists
|
125
|
+
begin
|
126
|
+
address = order.send(tag.attr['type']) # Get the address type (order.billing)
|
127
|
+
if address.present? # If that address exists
|
128
|
+
result = address # The result is that address
|
129
|
+
end
|
130
|
+
rescue
|
131
|
+
result = nil # Will catch an incorrect address type being send
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
result # Return result
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Shop
|
2
|
+
module Tags
|
3
|
+
module Item
|
4
|
+
include Radiant::Taggable
|
5
|
+
include ActionView::Helpers::NumberHelper
|
6
|
+
|
7
|
+
# Expand if items are in cart
|
8
|
+
desc %{ Expand if the user has added items to their cart }
|
9
|
+
tag 'shop:cart:if_items' do |tag|
|
10
|
+
tag.expand unless tag.locals.shop_order.line_items.empty?
|
11
|
+
end
|
12
|
+
|
13
|
+
# Expand in no items are in cart
|
14
|
+
desc %{ Expand unless a user has added items to their cart }
|
15
|
+
tag 'shop:cart:unless_items' do |tag|
|
16
|
+
tag.expand if tag.locals.shop_order.line_items.empty?
|
17
|
+
end
|
18
|
+
|
19
|
+
# Expand to line items
|
20
|
+
tag 'shop:cart:items' do |tag|
|
21
|
+
tag.expand
|
22
|
+
end
|
23
|
+
|
24
|
+
# Iterate through each item in the cart
|
25
|
+
desc %{ Iterate through each item in the cart }
|
26
|
+
tag 'shop:cart:items:each' do |tag|
|
27
|
+
content = ''
|
28
|
+
items = tag.locals.shop_order.line_items
|
29
|
+
|
30
|
+
items.each do |line_item|
|
31
|
+
tag.locals.shop_line_item = line_item
|
32
|
+
tag.locals.shop_product = line_item.item
|
33
|
+
|
34
|
+
content << tag.expand
|
35
|
+
end
|
36
|
+
|
37
|
+
content
|
38
|
+
end
|
39
|
+
|
40
|
+
# Assigns the line item and expands the context
|
41
|
+
desc %{ Expand the current line item }
|
42
|
+
tag 'shop:cart:item' do |tag|
|
43
|
+
tag.locals.shop_line_item = Helpers.current_line_item(tag)
|
44
|
+
|
45
|
+
unless tag.locals.shop_line_item.nil?
|
46
|
+
line_item = tag.locals.shop_line_item
|
47
|
+
tag.locals.shop_product = line_item.item
|
48
|
+
|
49
|
+
tag.expand
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# Output the line item id/quantity/weight
|
54
|
+
[:id, :quantity].each do |symbol|
|
55
|
+
desc %{ outputs the #{symbol} of the current cart item }
|
56
|
+
tag "shop:cart:item:#{symbol}" do |tag|
|
57
|
+
tag.locals.shop_line_item.send(symbol)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Output the related elements attributes
|
62
|
+
[:name, :price, :weight].each do |symbol|
|
63
|
+
desc %{ outputs the #{symbol} of the current cart item }
|
64
|
+
tag "shop:cart:item:#{symbol}" do |tag|
|
65
|
+
tag.locals.shop_line_item.item.send(symbol)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
desc %{ generates a link to the items generated page }
|
70
|
+
tag 'shop:cart:item:link' do |tag|
|
71
|
+
item = tag.locals.shop_line_item.item
|
72
|
+
options = tag.attr.dup
|
73
|
+
attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip
|
74
|
+
attributes = " #{attributes}" unless attributes.empty?
|
75
|
+
|
76
|
+
text = tag.double? ? tag.expand : item.name
|
77
|
+
|
78
|
+
%{<a href="#{item.slug}"#{attributes}>#{text}</a>}
|
79
|
+
end
|
80
|
+
|
81
|
+
# Output the price of the line item
|
82
|
+
desc %{ outputs the total price of the current cart item }
|
83
|
+
tag 'shop:cart:item:price' do |tag|
|
84
|
+
attr = tag.attr.symbolize_keys
|
85
|
+
item = tag.locals.shop_line_item
|
86
|
+
|
87
|
+
number_to_currency(item.price.to_f,
|
88
|
+
:precision =>(attr[:precision] || Radiant::Config['shop.price_precision']).to_i,
|
89
|
+
:unit => attr[:unit] || Radiant::Config['shop.price_unit'],
|
90
|
+
:separator => attr[:separator] || Radiant::Config['shop.price_seperator'],
|
91
|
+
:delimiter => attr[:delimiter] || Radiant::Config['shop.price_delimiter'])
|
92
|
+
end
|
93
|
+
|
94
|
+
# Output a link to remove the item from the cart
|
95
|
+
desc %{ outputs a link to remove the item from the cart }
|
96
|
+
tag 'shop:cart:item:remove' do |tag|
|
97
|
+
item = tag.locals.shop_line_item
|
98
|
+
options = tag.attr.dup
|
99
|
+
attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip
|
100
|
+
attributes = " #{attributes}" unless attributes.empty?
|
101
|
+
|
102
|
+
text = tag.double? ? tag.expand : 'remove'
|
103
|
+
|
104
|
+
%{<a href="/#{Radiant::Config['shop.url_prefix']}/cart/items/#{item.id}/destroy"#{attributes}>#{text}</a>}
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
module Shop
|
2
|
+
module Tags
|
3
|
+
module Product
|
4
|
+
include Radiant::Taggable
|
5
|
+
include ActionView::Helpers::NumberHelper
|
6
|
+
|
7
|
+
desc %{ expands if there are products within the context }
|
8
|
+
tag 'shop:if_products' do |tag|
|
9
|
+
tag.expand unless Helpers.current_products(tag).empty?
|
10
|
+
end
|
11
|
+
|
12
|
+
desc %{ expands if there are no products within the context }
|
13
|
+
tag 'shop:unless_products' do |tag|
|
14
|
+
tag.expand if Helpers.current_products(tag).empty?
|
15
|
+
end
|
16
|
+
|
17
|
+
tag 'shop:products' do |tag|
|
18
|
+
tag.expand
|
19
|
+
end
|
20
|
+
|
21
|
+
desc %{ iterates through each product within the scope }
|
22
|
+
tag 'shop:products:each' do |tag|
|
23
|
+
content = ''
|
24
|
+
products = Helpers.current_products(tag)
|
25
|
+
|
26
|
+
products.each do |product|
|
27
|
+
tag.locals.shop_product = product
|
28
|
+
content << tag.expand
|
29
|
+
end
|
30
|
+
|
31
|
+
content
|
32
|
+
end
|
33
|
+
|
34
|
+
tag 'shop:product' do |tag|
|
35
|
+
tag.locals.shop_product = Helpers.current_product(tag)
|
36
|
+
tag.expand unless tag.locals.shop_product.nil?
|
37
|
+
end
|
38
|
+
|
39
|
+
[:id, :name, :sku, :slug].each do |symbol|
|
40
|
+
desc %{ outputs the #{symbol} of the current shop product }
|
41
|
+
tag "shop:product:#{symbol}" do |tag|
|
42
|
+
tag.locals.shop_product.send(symbol)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
desc %{ outputs the description of the current shop product}
|
47
|
+
tag "shop:product:description" do |tag|
|
48
|
+
parse(TextileFilter.filter(tag.locals.shop_product.description))
|
49
|
+
end
|
50
|
+
|
51
|
+
desc %{ generates a link to the products generated page }
|
52
|
+
tag 'shop:product:link' do |tag|
|
53
|
+
product = tag.locals.shop_product
|
54
|
+
options = tag.attr.dup
|
55
|
+
attributes = options.inject('') { |s, (k, v)| s << %{#{k.downcase}="#{v}" } }.strip
|
56
|
+
attributes = " #{attributes}" unless attributes.empty?
|
57
|
+
|
58
|
+
text = tag.double? ? tag.expand : product.name
|
59
|
+
|
60
|
+
%{<a href="#{product.slug}"#{attributes}>#{text}</a>}
|
61
|
+
end
|
62
|
+
|
63
|
+
desc %{ outputs the slug to the products generated page }
|
64
|
+
tag 'shop:product:slug' do |tag|
|
65
|
+
product = tag.locals.shop_product
|
66
|
+
product.slug unless product.nil?
|
67
|
+
end
|
68
|
+
|
69
|
+
desc %{ output price of product }
|
70
|
+
tag 'shop:product:price' do |tag|
|
71
|
+
attr = tag.attr.symbolize_keys
|
72
|
+
product = tag.locals.shop_product
|
73
|
+
|
74
|
+
number_to_currency(product.price,
|
75
|
+
:precision =>(attr[:precision] || Radiant::Config['shop.price_precision']).to_i,
|
76
|
+
:unit => attr[:unit] || Radiant::Config['shop.price_unit'],
|
77
|
+
:separator => attr[:separator] || Radiant::Config['shop.price_seperator'],
|
78
|
+
:delimiter => attr[:delimiter] || Radiant::Config['shop.price_delimiter'])
|
79
|
+
end
|
80
|
+
|
81
|
+
desc %{ expands if the product has a valid image }
|
82
|
+
tag 'shop:product:if_images' do |tag|
|
83
|
+
tag.expand unless tag.locals.shop_product.images.empty?
|
84
|
+
end
|
85
|
+
|
86
|
+
desc %{ expands if the product does not have a valid image }
|
87
|
+
tag 'shop:product:unless_images' do |tag|
|
88
|
+
tag.expand if tag.locals.shop_product.images.empty?
|
89
|
+
end
|
90
|
+
|
91
|
+
tag 'shop:product:images' do |tag|
|
92
|
+
tag.expand
|
93
|
+
end
|
94
|
+
|
95
|
+
desc %{ iterates through each of the products images }
|
96
|
+
tag 'shop:product:images:each' do |tag|
|
97
|
+
content = ''
|
98
|
+
|
99
|
+
tag.locals.shop_product.images.each do |image|
|
100
|
+
tag.locals.image = image
|
101
|
+
content << tag.expand
|
102
|
+
end
|
103
|
+
|
104
|
+
content
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|