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,137 @@
|
|
1
|
+
class Admin::Shop::CustomersController < Admin::ResourceController
|
2
|
+
model_class ShopCustomer
|
3
|
+
|
4
|
+
# GET /admin/shop/customers
|
5
|
+
# GET /admin/shop/customers.js
|
6
|
+
# GET /admin/shop/customers.xml
|
7
|
+
# GET /admin/shop/customers.json AJAX and HTML
|
8
|
+
#----------------------------------------------------------------------------
|
9
|
+
def index
|
10
|
+
@shop_customers = ShopCustomer.scoped_by_access("front").all
|
11
|
+
@shop_customer = ShopCustomer.scoped_by_access("front").new
|
12
|
+
attr_hash = {}
|
13
|
+
respond_to do |format|
|
14
|
+
format.html { render }
|
15
|
+
format.js { render :partial => '/admin/shop/customers/excerpt', :collection => @shop_customers }
|
16
|
+
format.xml { render :xml => @shop_customers.to_xml(attr_hash) }
|
17
|
+
format.json { render :json => @shop_customers.to_json(attr_hash) }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
# GET /admin/shop/customers/1
|
22
|
+
# GET /admin/shop/customers/1.js
|
23
|
+
# GET /admin/shop/customers/1.xml
|
24
|
+
# GET /admin/shop/customers/1.json AJAX and HTML
|
25
|
+
#----------------------------------------------------------------------------
|
26
|
+
def show
|
27
|
+
@shop_customer = ShopCustomer.scoped_by_access("front").find(params[:id])
|
28
|
+
attr_hash = {
|
29
|
+
:include => {:orders => {:only => [:id, :balance, :status, :created_at, :updated_at, :payment_id]} },
|
30
|
+
:only => [:id, :email, :reference, :created_at, :updated_at, :organization, :notes, :name, :login, :access]
|
31
|
+
}
|
32
|
+
respond_to do |format|
|
33
|
+
format.html { render }
|
34
|
+
format.js { render :partial => '/admin/shop/customers/customer', :locals => { :customer => @shop_customer } }
|
35
|
+
format.xml { render :xml => @shop_customer.to_xml(attr_hash) }
|
36
|
+
format.json { render :json => @shop_customer.to_json(attr_hash) }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /admin/shop/customers
|
41
|
+
# POST /admin/shop/customers.js
|
42
|
+
# POST /admin/shop/customers.xml
|
43
|
+
# POST /admin/shop/customers.json AJAX and HTML
|
44
|
+
#----------------------------------------------------------------------------
|
45
|
+
def create
|
46
|
+
@shop_customer = ShopCustomer.new(params[:shop_customer])
|
47
|
+
|
48
|
+
if @shop_customer.save!
|
49
|
+
respond_to do |format|
|
50
|
+
format.html {
|
51
|
+
flash[:notice] = "Customer created successfully."
|
52
|
+
redirect_to admin_shop_customers_path
|
53
|
+
}
|
54
|
+
format.js { render :partial => '/admin/shop/customers/excerpt', :locals => { :excerpt => @shop_customer } }
|
55
|
+
format.xml { redirect_to "/admin/shop/customers/#{@shop_customer.id}.xml" }
|
56
|
+
format.json { redirect_to "/admin/shop/customers/#{@shop_customer.id}.json" }
|
57
|
+
end
|
58
|
+
else
|
59
|
+
respond_to do |format|
|
60
|
+
format.html {
|
61
|
+
flash[:error] = "Unable to create new customer."
|
62
|
+
render
|
63
|
+
}
|
64
|
+
format.js { render :text => @shop_customer.errors.to_json, :status => :unprocessable_entity }
|
65
|
+
format.xml { render :xml => @shop_customer.errors.to_xml, :status => :unprocessable_entity }
|
66
|
+
format.json { render :json => @shop_customer.errors.to_json, :status => :unprocessable_entity }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# PUT /admin/shop/customers/1
|
72
|
+
# PUT /admin/shop/customers/1.js
|
73
|
+
# PUT /admin/shop/customers/1.xml
|
74
|
+
# PUT /admin/shop/customers/1.json AJAX and HTML
|
75
|
+
#----------------------------------------------------------------------------
|
76
|
+
def update
|
77
|
+
@shop_customer = ShopCustomer.find(params[:id])
|
78
|
+
if @shop_customer.update_attributes!(params[:shop_customer])
|
79
|
+
respond_to do |format|
|
80
|
+
format.html {
|
81
|
+
flash[:notice] = "Customer updated successfully."
|
82
|
+
redirect_to admin_shop_customers_path
|
83
|
+
}
|
84
|
+
format.js { render :partial => '/admin/shop/customers/excerpt', :locals => { :excerpt => @shop_customer } }
|
85
|
+
format.xml { redirect_to "/admin/shop/customers/#{@shop_customer.id}.xml" }
|
86
|
+
format.json { redirect_to "/admin/shop/customers/#{@shop_customer.id}.json" }
|
87
|
+
end
|
88
|
+
else
|
89
|
+
respond_to do |format|
|
90
|
+
format.html {
|
91
|
+
flash[:error] = "Unable to update customer."
|
92
|
+
render
|
93
|
+
}
|
94
|
+
format.js { render :text => @shop_customer.errors.to_s, :status => :unprocessable_entity }
|
95
|
+
format.xml { render :xml => @shop_customer.errors.to_xml, :status => :unprocessable_entity }
|
96
|
+
format.json { render :json => @shop_customer.errors.to_json, :status => :unprocessable_entity }
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# DELETE /admin/shop/customers/1
|
102
|
+
# DELETE /admin/shop/customers/1.js
|
103
|
+
# DELETE /admin/shop/customers/1.xml
|
104
|
+
# DELETE /admin/shop/customers/1.json AJAX and HTML
|
105
|
+
#----------------------------------------------------------------------------
|
106
|
+
def destroy
|
107
|
+
# Need to rewrite this method to check for errors and return xml or json.
|
108
|
+
# For some reason the answer isn't obvious to me.
|
109
|
+
@shop_customer = ShopCustomer.find(params[:id])
|
110
|
+
|
111
|
+
if (@shop_customer && @shop_customer.orders.empty?)
|
112
|
+
@message = "Category deleted successfully."
|
113
|
+
@shop_customer.destroy
|
114
|
+
|
115
|
+
respond_to do |format|
|
116
|
+
format.html {
|
117
|
+
flash[:notice] = @message
|
118
|
+
redirect_to admin_shop_categories_path
|
119
|
+
}
|
120
|
+
format.js { render :text => @message, :status => 200 }
|
121
|
+
format.xml { render :xml => {:message => @message}, :status => 200 }
|
122
|
+
format.json { render :json => {:message => @message}, :status => 200 }
|
123
|
+
end
|
124
|
+
else
|
125
|
+
@message = "Unable to delete category."
|
126
|
+
respond_to do |format|
|
127
|
+
format.html {
|
128
|
+
flash[:error] = @message
|
129
|
+
}
|
130
|
+
format.js { render :text => @message, :status => :unprocessable_entity }
|
131
|
+
format.xml { render :xml => {:message => @message}, :status => :unprocessable_entity }
|
132
|
+
format.json { render :json => {:message => @message}, :status => :unprocessable_entity }
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,171 @@
|
|
1
|
+
class Admin::Shop::OrdersController < Admin::ResourceController
|
2
|
+
model_class ShopOrder
|
3
|
+
|
4
|
+
# GET /admin/shop/orders
|
5
|
+
# GET /admin/shop/orders.js
|
6
|
+
# GET /admin/shop/orders.xml
|
7
|
+
# GET /admin/shop/orders.json AJAX and HTML
|
8
|
+
#----------------------------------------------------------------------------
|
9
|
+
def index
|
10
|
+
@shop_orders = ShopOrder.search(params[:search], params[:filter], params[:page])
|
11
|
+
@shop_order = ShopOrder.new
|
12
|
+
@shop_order.line_items.build
|
13
|
+
attr_hash = {
|
14
|
+
:methods => [:sub_total, :balance],
|
15
|
+
:include => {
|
16
|
+
:customer => {
|
17
|
+
:include => {
|
18
|
+
:addresses => {:only => [ :street, :city, :state, :zip, :country, :unit, :atype ]}
|
19
|
+
},
|
20
|
+
:only => [:id, :name, :email, :organization]
|
21
|
+
},
|
22
|
+
:line_items => {
|
23
|
+
:methods => [:total],
|
24
|
+
:include => {
|
25
|
+
:product => {:only => [:id, :sku, :description, :handle, :price, :title]},
|
26
|
+
},
|
27
|
+
:only => [:id, :quantity]
|
28
|
+
}
|
29
|
+
},
|
30
|
+
:only => [:id, :status, :created_at, :updated_at]
|
31
|
+
}
|
32
|
+
|
33
|
+
respond_to do |format|
|
34
|
+
format.html { render }
|
35
|
+
format.js { render :partial => '/admin/shop/orders/excerpt', :collection => @shop_orders }
|
36
|
+
format.xml { render :xml => @shop_orders.to_xml(attr_hash) }
|
37
|
+
format.json { render :json => @shop_orders.to_json(attr_hash) }
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# GET /admin/shop/orders/1
|
42
|
+
# GET /admin/shop/orders/1.js
|
43
|
+
# GET /admin/shop/orders/1.xml
|
44
|
+
# GET /admin/shop/orders/1.json AJAX and HTML
|
45
|
+
#----------------------------------------------------------------------------
|
46
|
+
def show
|
47
|
+
@shop_order = ShopOrder.find(params[:id])
|
48
|
+
attr_hash = {
|
49
|
+
:methods => [:sub_total, :balance],
|
50
|
+
:include => {
|
51
|
+
:customer => {
|
52
|
+
:include => {
|
53
|
+
:addresses => {:only => [ :street, :city, :state, :zip, :country, :unit, :atype ]}
|
54
|
+
},
|
55
|
+
:only => [:id, :name, :email, :organization]
|
56
|
+
},
|
57
|
+
:line_items => {
|
58
|
+
:methods => [:total],
|
59
|
+
:include => {
|
60
|
+
:product => {:only => [:id, :sku, :description, :handle, :price, :title]},
|
61
|
+
},
|
62
|
+
:only => [:id, :quantity]
|
63
|
+
}
|
64
|
+
},
|
65
|
+
:only => [:id, :status, :created_at, :updated_at]
|
66
|
+
}
|
67
|
+
respond_to do |format|
|
68
|
+
format.html { render }
|
69
|
+
format.js { render :partial => '/admin/shop/orders/order', :locals => { :order => @shop_order } }
|
70
|
+
format.xml { render :xml => @shop_order.to_xml(attr_hash) }
|
71
|
+
format.json { render :json => @shop_order.to_json(attr_hash) }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
# POST /admin/shop/orders
|
76
|
+
# POST /admin/shop/orders.js
|
77
|
+
# POST /admin/shop/orders.xml
|
78
|
+
# POST /admin/shop/orders.json AJAX and HTML
|
79
|
+
#----------------------------------------------------------------------------
|
80
|
+
def create
|
81
|
+
@shop_order = ShopOrder.new(params[:shop_order])
|
82
|
+
|
83
|
+
if @shop_order.save!
|
84
|
+
respond_to do |format|
|
85
|
+
format.html {
|
86
|
+
flash[:notice] = "Order created successfully."
|
87
|
+
redirect_to admin_shop_orders_path
|
88
|
+
}
|
89
|
+
format.js { render :partial => '/admin/shop/orders/excerpt', :locals => { :excerpt => @shop_order } }
|
90
|
+
format.xml { redirect_to "/admin/shop/orders/#{@shop_order.id}.xml" }
|
91
|
+
format.json { redirect_to "/admin/shop/orders/#{@shop_order.id}.json" }
|
92
|
+
end
|
93
|
+
else
|
94
|
+
respond_to do |format|
|
95
|
+
format.html {
|
96
|
+
flash[:error] = "Unable to create new customer."
|
97
|
+
render
|
98
|
+
}
|
99
|
+
format.js { render :text => @shop_order.errors.to_json, :status => :unprocessable_entity }
|
100
|
+
format.xml { render :xml => @shop_order.errors.to_xml, :status => :unprocessable_entity }
|
101
|
+
format.json { render :json => @shop_order.errors.to_json, :status => :unprocessable_entity }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
# PUT /shop/orders/1
|
107
|
+
# PUT /shop/orders/1.xml
|
108
|
+
# PUT /shop/orders/1.json AJAX and HTML
|
109
|
+
#-----------------------------------------------------------------------------
|
110
|
+
def update
|
111
|
+
@shop_order = ShopOrder.find(params[:id])
|
112
|
+
if @shop_order.update_attributes!(params[:shop_order])
|
113
|
+
respond_to do |format|
|
114
|
+
format.html {
|
115
|
+
flash[:notice] = "Order updated successfully."
|
116
|
+
redirect_to admin_shop_customers_path
|
117
|
+
}
|
118
|
+
format.js { render :partial => '/admin/shop/orders/excerpt', :locals => { :excerpt => @shop_order } }
|
119
|
+
format.xml { redirect_to "/admin/shop/orders/#{@shop_order.id}.xml" }
|
120
|
+
format.json { redirect_to "/admin/shop/orders/#{@shop_order.id}.json" }
|
121
|
+
end
|
122
|
+
else
|
123
|
+
respond_to do |format|
|
124
|
+
format.html {
|
125
|
+
flash[:error] = "Unable to update order."
|
126
|
+
render
|
127
|
+
}
|
128
|
+
format.js { render :text => @shop_order.errors.to_s, :status => :unprocessable_entity }
|
129
|
+
format.xml { render :xml => @shop_order.errors.to_xml, :status => :unprocessable_entity }
|
130
|
+
format.json { render :json => @shop_order.errors.to_json, :status => :unprocessable_entity }
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
# DELETE /admin/shop/orders/1
|
136
|
+
# DELETE /admin/shop/orders/1.js
|
137
|
+
# DELETE /admin/shop/orders/1.xml
|
138
|
+
# DELETE /admin/shop/orders/1.json AJAX and HTML
|
139
|
+
#----------------------------------------------------------------------------
|
140
|
+
def destroy
|
141
|
+
# Need to rewrite this method to check for errors and return xml or json.
|
142
|
+
# For some reason the answer isn't obvious to me.
|
143
|
+
@shop_order = ShopOrder.find(params[:id])
|
144
|
+
|
145
|
+
if @shop_order
|
146
|
+
@message = "Order deleted successfully."
|
147
|
+
@shop_order.destroy
|
148
|
+
|
149
|
+
respond_to do |format|
|
150
|
+
format.html {
|
151
|
+
flash[:notice] = @message
|
152
|
+
redirect_to admin_shop_orders_path
|
153
|
+
}
|
154
|
+
format.js { render :text => @message, :status => 200 }
|
155
|
+
format.xml { render :xml => {:message => @message}, :status => 200 }
|
156
|
+
format.json { render :json => {:message => @message}, :status => 200 }
|
157
|
+
end
|
158
|
+
else
|
159
|
+
@message = "Unable to delete order."
|
160
|
+
respond_to do |format|
|
161
|
+
format.html {
|
162
|
+
flash[:error] = @message
|
163
|
+
}
|
164
|
+
format.js { render :text => @message, :status => :unprocessable_entity }
|
165
|
+
format.xml { render :xml => {:message => @message}, :status => :unprocessable_entity }
|
166
|
+
format.json { render :json => {:message => @message}, :status => :unprocessable_entity }
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
class Admin::Shop::Products::ImagesController < Admin::ResourceController
|
2
|
+
|
3
|
+
model_class ShopProductAttachment
|
4
|
+
|
5
|
+
# GET /admin/shop/products/1/images
|
6
|
+
# GET /admin/shop/products/1/images.js
|
7
|
+
# GET /admin/shop/products/1/images.json AJAX and HTML
|
8
|
+
#----------------------------------------------------------------------------
|
9
|
+
def index
|
10
|
+
error = 'This Product has no Images.'
|
11
|
+
attr_hash = ShopProductAttachment.params
|
12
|
+
|
13
|
+
@shop_product = ShopProduct.find(params[:product_id])
|
14
|
+
@shop_product_images = @shop_product.images
|
15
|
+
|
16
|
+
unless @shop_product_images.empty?
|
17
|
+
respond_to do |format|
|
18
|
+
format.html { redirect_to edit_admin_shop_product_path(@shop_product) }
|
19
|
+
format.js { render :partial => '/admin/shop/products/edit/image', :collection => @shop_product_images }
|
20
|
+
format.json { render :json => @shop_product_images.to_json(attr_hash) }
|
21
|
+
end
|
22
|
+
else
|
23
|
+
respond_to do |format|
|
24
|
+
format.html {
|
25
|
+
flash[:error] = error
|
26
|
+
redirect_to edit_admin_shop_product_path(@shop_product)
|
27
|
+
}
|
28
|
+
format.js { render :text => error, :status => :unprocessable_entity }
|
29
|
+
format.json { render :json => { :error => error }, :status => :unprocessable_entity }
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# PUT /admin/shop/products/1/images/sort
|
35
|
+
# PUT /admin/shop/products/1/images/sort.js
|
36
|
+
# PUT /admin/shop/products/1/images/sort.json AJAX and HTML
|
37
|
+
#----------------------------------------------------------------------------
|
38
|
+
def sort
|
39
|
+
error = 'Could not sort Images.'
|
40
|
+
notice = 'Successfully sorted Images.'
|
41
|
+
attr_hash = ShopProductAttachment.params
|
42
|
+
|
43
|
+
begin
|
44
|
+
@shop_product = ShopProduct.find(params[:product_id])
|
45
|
+
|
46
|
+
@images = CGI::parse(params[:attachments])['product_attachments[]']
|
47
|
+
@images.each_with_index do |id, index|
|
48
|
+
ShopProductAttachment.find(id).update_attributes!({ :position => index+1 })
|
49
|
+
end
|
50
|
+
|
51
|
+
respond_to do |format|
|
52
|
+
format.html {
|
53
|
+
flash[:notice] = notice
|
54
|
+
redirect_to edit_admin_shop_product_path(@shop_product)
|
55
|
+
}
|
56
|
+
format.js { render :partial => '/admin/shop/products/edit/image', :collection => @shop_product.images }
|
57
|
+
format.json { render :json => @shop_product.images.to_json(attr_hash) }
|
58
|
+
end
|
59
|
+
rescue
|
60
|
+
respond_to do |format|
|
61
|
+
format.html {
|
62
|
+
flash[:error] = error
|
63
|
+
redirect_to edit_admin_shop_product_path(@shop_product)
|
64
|
+
}
|
65
|
+
format.js { render :text => error, :status => :unprocessable_entity }
|
66
|
+
format.json { render :json => { :error => error }, :status => :unprocessable_entity }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
# POST /admin/shop/products/1/images
|
72
|
+
# POST /admin/shop/products/1/images.js
|
73
|
+
# POST /admin/shop/products/1/images.json AJAX and HTML
|
74
|
+
#----------------------------------------------------------------------------
|
75
|
+
def create
|
76
|
+
notice = 'Successfully created Image.'
|
77
|
+
error = 'Unable to create Image.'
|
78
|
+
attr_hash = ShopProductAttachment.params
|
79
|
+
|
80
|
+
begin
|
81
|
+
@shop_product = ShopProduct.find(params[:product_id])
|
82
|
+
|
83
|
+
if params[:image]
|
84
|
+
@image = Image.create!(params[:image])
|
85
|
+
elsif params[:attachment]
|
86
|
+
@image = Image.find(params[:attachment][:image_id])
|
87
|
+
end
|
88
|
+
|
89
|
+
@shop_product_attachment = @shop_product.attachments.create!({ :image => @image })
|
90
|
+
|
91
|
+
respond_to do |format|
|
92
|
+
format.html {
|
93
|
+
flash[:notice] = notice
|
94
|
+
redirect_to edit_admin_shop_product_path(@shop_product)
|
95
|
+
}
|
96
|
+
format.js { render :partial => '/admin/shop/products/edit/image', :locals => { :image => @shop_product_attachment } }
|
97
|
+
format.json { render :json => @shop_product_attachment.to_json(attr_hash) }
|
98
|
+
end
|
99
|
+
rescue
|
100
|
+
respond_to do |format|
|
101
|
+
format.html {
|
102
|
+
flash[:error] = error
|
103
|
+
redirect_to edit_admin_shop_product_path(@shop_product)
|
104
|
+
}
|
105
|
+
format.js { render :text => error, :status => :unprocessable_entity }
|
106
|
+
format.json { render :json => { :error => error }, :status => :unprocessable_entity }
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# DELETE /admin/shop/products/1/images/1
|
112
|
+
# DELETE /admin/shop/products/1/images/1.js
|
113
|
+
# DELETE /admin/shop/products/1/images/1.json AJAX and HTML
|
114
|
+
#----------------------------------------------------------------------------
|
115
|
+
def destroy
|
116
|
+
notice = 'Image deleted successfully.'
|
117
|
+
error = 'Unable to delete Image.'
|
118
|
+
|
119
|
+
begin
|
120
|
+
@shop_product = ShopProduct.find(params[:product_id])
|
121
|
+
@image = @shop_product_attachment.image
|
122
|
+
@shop_product_attachment.destroy
|
123
|
+
|
124
|
+
respond_to do |format|
|
125
|
+
format.html {
|
126
|
+
flash[:notice] = notice
|
127
|
+
redirect_to edit_admin_shop_product_path(@shop_product)
|
128
|
+
}
|
129
|
+
format.js { render :partial => '/admin/shop/products/edit/image', :locals => { :excerpt => @image } }
|
130
|
+
format.json { render :json => { :notice => notice }, :status => :ok }
|
131
|
+
end
|
132
|
+
rescue
|
133
|
+
respond_to do |format|
|
134
|
+
format.html {
|
135
|
+
flash[:error] = error
|
136
|
+
render :remove
|
137
|
+
}
|
138
|
+
format.js { render :text => error, :status => :unprocessable_entity }
|
139
|
+
format.json { render :json => { :error => error }, :status => :unprocessable_entity }
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|