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,119 @@
|
|
1
|
+
class CreateLayouts < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
# Will only create a layout if it doesn't exist
|
4
|
+
Layout.create({
|
5
|
+
:name => 'Application',
|
6
|
+
:content => <<-CONTENT
|
7
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
8
|
+
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
|
9
|
+
<head>
|
10
|
+
<title><r:title /></title>
|
11
|
+
</head>
|
12
|
+
<body>
|
13
|
+
<r:snippet name='CartOverview' />
|
14
|
+
<r:content_for_layout />
|
15
|
+
</body>
|
16
|
+
</html>
|
17
|
+
CONTENT
|
18
|
+
})
|
19
|
+
|
20
|
+
Layout.create({
|
21
|
+
:name => Radiant::Config['shop.product_layout'],
|
22
|
+
:content => <<-CONTENT
|
23
|
+
<r:inside_layout name='Application'>
|
24
|
+
<r:shop:product>
|
25
|
+
<div id="shop_product_<r:sku />" class="shop_product">
|
26
|
+
<h2><r:title /></h2>
|
27
|
+
<h3><r:price /></h3>
|
28
|
+
<dl id="shop_product_details">
|
29
|
+
<dd>Description</dt>
|
30
|
+
<dd class="body"><r:description /></dd>
|
31
|
+
<dd>Add To Cart</dt>
|
32
|
+
<dd class="add"><r:form name="AddCartItem" /></dd>
|
33
|
+
</dl>
|
34
|
+
<r:if_images>
|
35
|
+
<ul id="shop_product_images">
|
36
|
+
<r:images:each>
|
37
|
+
<li class="shop_product_image" id="shop_product_image_<r:sku />">
|
38
|
+
<a href="<r:image style='normal' />" title="<r:title />"">
|
39
|
+
<img id="shop_product_image_<r:position />" class="shop_product_image" src="<r:image style='thumbnail'/>" alt="<r:title />" />
|
40
|
+
</a>
|
41
|
+
</li>
|
42
|
+
</r:images:each>
|
43
|
+
</ul>
|
44
|
+
</r:if_images>
|
45
|
+
<r:unless_images>
|
46
|
+
<p class="error" id="shop_no_product_images_error">We don't have any images for this product yet.</p>
|
47
|
+
</r:unless_images>
|
48
|
+
</div>
|
49
|
+
</r:shop:product>
|
50
|
+
</r:inside_layout>
|
51
|
+
CONTENT
|
52
|
+
})
|
53
|
+
Layout.create({
|
54
|
+
:name => Radiant::Config['shop.category_layout'],
|
55
|
+
:content => <<-CONTENT
|
56
|
+
<r:inside_layout name='Application'>
|
57
|
+
<r:shop:category>
|
58
|
+
<div id="shop_category_<r:handle />" class="shop_category">
|
59
|
+
<h2 class="shop_category_title"><r:title /></h2>
|
60
|
+
<div id="shop_category_description">
|
61
|
+
<h3>Description</h3>
|
62
|
+
<div class="body"><r:description /></div>
|
63
|
+
</div>
|
64
|
+
<r:if_products>
|
65
|
+
<ul class="shop_products" id="shop_products_<r:handle/>" >
|
66
|
+
<r:products:each:product>
|
67
|
+
<li class="shop_product" id="shop_product_<r:sku />">
|
68
|
+
<r:image position='1'>
|
69
|
+
<r:link><img src="<r:url style='preview' />" alt="<r:handle />" class="shop_product_image" /></r:link>
|
70
|
+
</r:image>
|
71
|
+
<h3 class="shop_product_name"><r:link><r:name /> <small><r:price /></small></r:link></h3>
|
72
|
+
<div class="shop_product_description"><r:description /></div>
|
73
|
+
</li>
|
74
|
+
</r:products:each:product>
|
75
|
+
</ul>
|
76
|
+
</r:if_products>
|
77
|
+
<r:unless_products>
|
78
|
+
<p class="error" id="shop_no_products_error">We don't have any products available here yet.</p>
|
79
|
+
</r:unless_products>
|
80
|
+
</div>
|
81
|
+
</r:shop:category>
|
82
|
+
</r:inside_layout>
|
83
|
+
CONTENT
|
84
|
+
})
|
85
|
+
|
86
|
+
Layout.create({
|
87
|
+
:name => Radiant::Config['shop.order_layout'],
|
88
|
+
:content => <<-CONTENT
|
89
|
+
<r:inside_layout name='Application'>
|
90
|
+
<r:shop:cart>
|
91
|
+
<r:if_items>
|
92
|
+
<ol class="items">
|
93
|
+
<r:items:each>
|
94
|
+
<r:item>
|
95
|
+
<li class="item" id="item_<r:id />">
|
96
|
+
<span class="quantity"><r:quantity /></span>
|
97
|
+
<span class="name"><r:link><r:name /></r:link></name></span>
|
98
|
+
<span class="update"><r:form name="UpdateCartItem" /></span>
|
99
|
+
<span class="price"><r:price /></span>
|
100
|
+
<span class="remove"><r:remove /></span>
|
101
|
+
</li>
|
102
|
+
</r:item>
|
103
|
+
</r:items:each>
|
104
|
+
</ol>
|
105
|
+
<span class="total"><r:price /></span>
|
106
|
+
</r:if_items>
|
107
|
+
<r:unless_items>
|
108
|
+
<p>Your cart is currently empty</p>
|
109
|
+
</r:unless_items>
|
110
|
+
</r:shop:cart>
|
111
|
+
</r:inside_layout>
|
112
|
+
CONTENT
|
113
|
+
})
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.down
|
117
|
+
# Won't delete content, that would be cruel
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class CreateForms < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
# Will only create a layout if it doesn't exist
|
4
|
+
Form.create({
|
5
|
+
:title => 'AddCartItem',
|
6
|
+
:action => '/shop/cart/items',
|
7
|
+
:body => <<-CONTENT
|
8
|
+
<r:shop>
|
9
|
+
<r: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]' /> <!-- 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:product>
|
18
|
+
</r:shop>
|
19
|
+
CONTENT
|
20
|
+
})
|
21
|
+
|
22
|
+
Form.create({
|
23
|
+
:title => 'UpdateCartItem',
|
24
|
+
:action => '/shop/cart/items/x',
|
25
|
+
:body => <<-CONTENT
|
26
|
+
<r:shop:cart>
|
27
|
+
<r:item>
|
28
|
+
<input type="hidden" name="_method" value="put" />
|
29
|
+
<input type="hidden" name="line_item[id]" value="<r:item:id />" />
|
30
|
+
<!-- Your Customisation Below -->
|
31
|
+
|
32
|
+
<input type="text" name="line_item[quantity]" value="" />
|
33
|
+
<input type="submit" name="add_to_cart" id="update_<r:id />" value="Update" />
|
34
|
+
|
35
|
+
<!-- Your Customisation Above -->
|
36
|
+
</r:item>
|
37
|
+
</r:shop:cart>
|
38
|
+
CONTENT
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.down
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
class CreateSnippets < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
Snippet.create({
|
4
|
+
:name => 'CartOverview',
|
5
|
+
:content => <<-BEGIN
|
6
|
+
<r:shop:cart>
|
7
|
+
<r:if_items>
|
8
|
+
<span class="quantity"><r:quantity /></span>
|
9
|
+
<span class="price"><r:price /></span>
|
10
|
+
<r:link>checkout</r:link>
|
11
|
+
</r:if_items>
|
12
|
+
<r:unless_items>
|
13
|
+
<p>Your cart is empty</p>
|
14
|
+
</r:unless_items>
|
15
|
+
</r:shop:cart>
|
16
|
+
BEGIN
|
17
|
+
})
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.down
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# Sets up the Rails environment for Cucumber
|
2
|
+
ENV["RAILS_ENV"] = "test"
|
3
|
+
# Extension root
|
4
|
+
extension_env = File.expand_path(File.dirname(__FILE__) + '/../../../../../config/environment')
|
5
|
+
require extension_env+'.rb'
|
6
|
+
|
7
|
+
Dir.glob(File.join(RADIANT_ROOT, "features", "**", "*.rb")).each {|step| require step}
|
8
|
+
|
9
|
+
Cucumber::Rails::World.class_eval do
|
10
|
+
include Dataset
|
11
|
+
datasets_directory "#{RADIANT_ROOT}/spec/datasets"
|
12
|
+
Dataset::Resolver.default = Dataset::DirectoryResolver.new("#{RADIANT_ROOT}/spec/datasets", File.dirname(__FILE__) + '/../../spec/datasets', File.dirname(__FILE__) + '/../datasets')
|
13
|
+
self.datasets_database_dump_path = "#{Rails.root}/tmp/dataset"
|
14
|
+
|
15
|
+
# dataset :shop_cart
|
16
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Shop
|
2
|
+
module Controllers
|
3
|
+
module ApplicationController
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
def current_shop_order
|
8
|
+
return @current_shop_order if defined?(@current_shop_order)
|
9
|
+
@current_shop_order = find_shop_order
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_shop_order
|
13
|
+
shop_order = nil
|
14
|
+
|
15
|
+
if request.session[:shop_order]
|
16
|
+
shop_order = ShopOrder.find(request.session[:shop_order])
|
17
|
+
end
|
18
|
+
|
19
|
+
shop_order
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_or_create_shop_order
|
23
|
+
shop_order = nil
|
24
|
+
|
25
|
+
if find_shop_order and find_shop_order.status != 'paid'
|
26
|
+
shop_order = find_shop_order
|
27
|
+
else
|
28
|
+
shop_order = ShopOrder.create
|
29
|
+
request.session[:shop_order] = shop_order.id
|
30
|
+
end
|
31
|
+
|
32
|
+
shop_order
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Shop
|
2
|
+
module Interface
|
3
|
+
module Products
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.send :include, InstanceMethods
|
7
|
+
end
|
8
|
+
|
9
|
+
module InstanceMethods
|
10
|
+
attr_accessor :products, :categories
|
11
|
+
|
12
|
+
protected
|
13
|
+
def load_default_shop_products_regions
|
14
|
+
returning OpenStruct.new do |products|
|
15
|
+
products.edit = Radiant::AdminUI::RegionSet.new do |edit|
|
16
|
+
edit.main.concat %w{edit_header edit_form edit_popups}
|
17
|
+
edit.sidebar
|
18
|
+
edit.form.concat %w{edit_name edit_price edit_extended_metadata edit_content}
|
19
|
+
edit.form_bottom.concat %w{edit_buttons edit_timestamp}
|
20
|
+
end
|
21
|
+
products.new = products.edit
|
22
|
+
products.index = Radiant::AdminUI::RegionSet.new do |index|
|
23
|
+
index.top
|
24
|
+
index.bottom.concat %w{ add_category }
|
25
|
+
index.thead.concat %w{ name_header description_header modify_header }
|
26
|
+
index.category_attributes.concat %w{ category_name category_description category_modify }
|
27
|
+
index.category_products.concat %w{ category_products }
|
28
|
+
index.product.concat %w{ product_name product_modify }
|
29
|
+
end
|
30
|
+
products.remove = products.index
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def load_default_shop_categories_regions
|
35
|
+
returning OpenStruct.new do |categories|
|
36
|
+
categories.edit = Radiant::AdminUI::RegionSet.new do |edit|
|
37
|
+
edit.main.concat %w{edit_header edit_form edit_popups}
|
38
|
+
edit.form.concat %w{edit_name edit_extended_metadata edit_content}
|
39
|
+
edit.form_bottom.concat %w{edit_buttons edit_timestamp}
|
40
|
+
end
|
41
|
+
categories.new = categories.edit
|
42
|
+
categories.remove = categories.index
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Shop
|
2
|
+
module Models
|
3
|
+
module Image
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
has_many :shop_product_attachments, :dependent => :destroy
|
8
|
+
has_many :shop_products, :through => :shop_product_attachments, :source => :product
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Shop
|
2
|
+
module Models
|
3
|
+
module Page
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.class_eval do
|
7
|
+
belongs_to :shop_category, :class_name => 'ShopCategory', :foreign_key => 'shop_category_id'
|
8
|
+
belongs_to :shop_product, :class_name => 'ShopProduct', :foreign_key => 'shop_product_id'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Shop
|
2
|
+
module Tags
|
3
|
+
module Address
|
4
|
+
include Radiant::Taggable
|
5
|
+
|
6
|
+
# Expand if the address has been assigned to the order
|
7
|
+
desc %{
|
8
|
+
Expand if an address has been assigned to the order
|
9
|
+
|
10
|
+
@type@ = (billing)|(shipping)
|
11
|
+
}
|
12
|
+
tag 'shop:cart:address' do |tag|
|
13
|
+
Forms::Tags::Helpers.require!(tag,'shop:cart:address','type')
|
14
|
+
|
15
|
+
tag.locals.address = Shop::Tags::Helpers.current_address(tag)
|
16
|
+
|
17
|
+
tag.expand
|
18
|
+
end
|
19
|
+
|
20
|
+
# Expand if an address has been assigned to the order
|
21
|
+
desc %{ Expand if an address has been assigned to the order }
|
22
|
+
tag 'shop:cart:address:if_address' do |tag|
|
23
|
+
tag.expand if tag.locals.address.present?
|
24
|
+
end
|
25
|
+
|
26
|
+
# Expand if an address has not been assigned to the order
|
27
|
+
desc %{ Expand if an address has not been assigned to the order }
|
28
|
+
tag 'shop:cart:address:unless_address' do |tag|
|
29
|
+
tag.expand unless tag.locals.address.present?
|
30
|
+
end
|
31
|
+
|
32
|
+
[:id, :name, :email, :unit, :street, :city, :state, :country, :postcode].each do |method|
|
33
|
+
tag "shop:cart:address:#{method}" do |tag|
|
34
|
+
tag.locals.address.send(method) rescue nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Shop
|
2
|
+
module Tags
|
3
|
+
module Cart
|
4
|
+
include Radiant::Taggable
|
5
|
+
include ActionView::Helpers::NumberHelper
|
6
|
+
|
7
|
+
# Expand if a user has started a cart
|
8
|
+
desc %{ Expand if a user has started a cart }
|
9
|
+
tag 'shop:if_cart' do |tag|
|
10
|
+
tag.expand if Helpers.current_order(tag)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Expand unless a user has started a cart
|
14
|
+
desc %{ Expand unless a user has started a cart }
|
15
|
+
tag 'shop:unless_cart' do |tag|
|
16
|
+
tag.expand unless Helpers.current_order(tag)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Expand the shopping cart instance
|
20
|
+
# @param [Integer] id Id of the shopping cart (ShopOrder)
|
21
|
+
tag 'shop:cart' do |tag|
|
22
|
+
tag.locals.shop_order = Helpers.current_order(tag)
|
23
|
+
tag.expand unless tag.locals.shop_order.nil?
|
24
|
+
end
|
25
|
+
|
26
|
+
# Display the cart id / status
|
27
|
+
[:id, :status, :quantity, :weight].each do |symbol|
|
28
|
+
desc %{ outputs the #{symbol} to the cart }
|
29
|
+
tag "shop:cart:#{symbol}" do |tag|
|
30
|
+
tag.locals.shop_order.send(symbol)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# Display the total price of the items in the shopping basket.
|
35
|
+
desc %{ Output the total price of the items in the shopping basket. }
|
36
|
+
tag 'shop:cart:price' do |tag|
|
37
|
+
attr = tag.attr.symbolize_keys
|
38
|
+
order = tag.locals.shop_order
|
39
|
+
|
40
|
+
number_to_currency(order.price.to_f,
|
41
|
+
:precision =>(attr[:precision] || Radiant::Config['shop.price_precision']).to_i,
|
42
|
+
:unit => attr[:unit] || Radiant::Config['shop.price_unit'],
|
43
|
+
:separator => attr[:separator] || Radiant::Config['shop.price_seperator'],
|
44
|
+
:delimiter => attr[:delimiter] || Radiant::Config['shop.price_delimiter'])
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|