caboose-cms 0.4.151 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (166) hide show
  1. checksums.yaml +8 -8
  2. data/app/assets/javascripts/caboose/admin_products.js +79 -0
  3. data/app/assets/javascripts/caboose/application.js +2 -1
  4. data/app/assets/javascripts/caboose/cart.js +168 -0
  5. data/app/assets/javascripts/caboose/checkout.js +151 -0
  6. data/app/assets/javascripts/caboose/checkout_module.js +312 -0
  7. data/app/assets/javascripts/caboose/checkout_step1.js +179 -0
  8. data/app/assets/javascripts/caboose/checkout_step2.js +39 -0
  9. data/app/assets/javascripts/caboose/checkout_step3.js +34 -0
  10. data/app/assets/javascripts/caboose/checkout_step4.js +97 -0
  11. data/app/assets/javascripts/caboose/main.js +99 -8
  12. data/app/assets/javascripts/caboose/product.js +284 -0
  13. data/app/assets/stylesheets/caboose/admin_products.css +86 -0
  14. data/app/assets/templates/caboose/cart/add_to_cart.jst.ejs +7 -0
  15. data/app/assets/templates/caboose/cart/line_items.jst.ejs +41 -0
  16. data/app/assets/templates/caboose/checkout/address.jst.ejs +53 -0
  17. data/app/assets/templates/caboose/checkout/forms/guest.jst.ejs +8 -0
  18. data/app/assets/templates/caboose/checkout/forms/register.jst.ejs +11 -0
  19. data/app/assets/templates/caboose/checkout/forms/signin.jst.ejs +7 -0
  20. data/app/assets/templates/caboose/checkout/line_items.jst.ejs +31 -0
  21. data/app/assets/templates/caboose/checkout/login.jst.ejs +21 -0
  22. data/app/assets/templates/caboose/checkout/payment.jst.ejs +5 -0
  23. data/app/assets/templates/caboose/checkout/shipping.jst.ejs +18 -0
  24. data/app/assets/templates/caboose/product/images.jst.ejs +8 -0
  25. data/app/assets/templates/caboose/product/options.jst.ejs +19 -0
  26. data/app/controllers/caboose/application_controller.rb +29 -1
  27. data/app/controllers/caboose/cart_controller.rb +52 -0
  28. data/app/controllers/caboose/categories_controller.rb +108 -0
  29. data/app/controllers/caboose/checkout_controller.rb +325 -0
  30. data/app/controllers/caboose/orders_controller.rb +439 -0
  31. data/app/controllers/caboose/product_images_controller.rb +38 -0
  32. data/app/controllers/caboose/products_controller.rb +737 -0
  33. data/app/controllers/caboose/reviews_controller.rb +15 -0
  34. data/app/controllers/caboose/variants_controller.rb +218 -0
  35. data/app/controllers/caboose/vendors_controller.rb +73 -0
  36. data/app/helpers/caboose/application_helper.rb +4 -0
  37. data/app/helpers/caboose/categories_helper.rb +82 -0
  38. data/app/helpers/caboose/checkout_helper.rb +20 -0
  39. data/app/helpers/caboose/products_helper.rb +8 -0
  40. data/app/mailers/caboose/orders_mailer.rb +30 -0
  41. data/app/models/caboose/address.rb +26 -0
  42. data/app/models/caboose/category.rb +89 -0
  43. data/app/models/caboose/category_membership.rb +10 -0
  44. data/app/models/caboose/core_plugin.rb +15 -37
  45. data/app/models/caboose/customization_membership.rb +10 -0
  46. data/app/models/caboose/discount.rb +16 -0
  47. data/app/models/caboose/line_item.rb +81 -0
  48. data/app/models/caboose/message.rb +20 -0
  49. data/app/models/caboose/order.rb +191 -0
  50. data/app/models/caboose/order_discount.rb +10 -0
  51. data/app/models/caboose/order_pdf.rb +78 -0
  52. data/app/models/caboose/payment_processors/authorizenet.rb +53 -0
  53. data/app/models/caboose/payment_processors/base.rb +39 -0
  54. data/app/models/caboose/payment_processors/payscape.rb +94 -0
  55. data/app/models/caboose/product.rb +145 -0
  56. data/app/models/caboose/product_image.rb +62 -0
  57. data/app/models/caboose/product_image_variant.rb +10 -0
  58. data/app/models/caboose/review.rb +13 -0
  59. data/app/models/caboose/schema.rb +205 -1
  60. data/app/models/caboose/search_filter.rb +191 -0
  61. data/app/models/caboose/shipping_calculator.rb +81 -0
  62. data/app/models/caboose/states.rb +61 -52
  63. data/app/models/caboose/tax_calculator.rb +23 -0
  64. data/app/models/caboose/tax_line.rb +9 -0
  65. data/app/models/caboose/variant.rb +99 -0
  66. data/app/models/caboose/vendor.rb +22 -0
  67. data/app/views/caboose/cart/index.html.erb +8 -0
  68. data/app/views/caboose/categories/admin_edit.html.erb +79 -0
  69. data/app/views/caboose/categories/admin_index.html.erb +11 -0
  70. data/app/views/caboose/categories/admin_new.html.erb +62 -0
  71. data/app/views/caboose/checkout/_address_form.html.erb +111 -0
  72. data/app/views/caboose/checkout/_billing_form.html.erb +47 -0
  73. data/app/views/caboose/checkout/_cart.html.erb +52 -0
  74. data/app/views/caboose/checkout/_confirm.html.erb +61 -0
  75. data/app/views/caboose/checkout/_order_discount.html.erb +40 -0
  76. data/app/views/caboose/checkout/_shipping_address.html.erb +10 -0
  77. data/app/views/caboose/checkout/_shipping_method.html.erb +2 -0
  78. data/app/views/caboose/checkout/_shipping_method_form.html.erb +21 -0
  79. data/app/views/caboose/checkout/billing.html.erb +11 -0
  80. data/app/views/caboose/checkout/discount.html.erb +11 -0
  81. data/app/views/caboose/checkout/empty.html.erb +2 -0
  82. data/app/views/caboose/checkout/error.html.erb +2 -0
  83. data/app/views/caboose/checkout/index.html.erb +43 -0
  84. data/app/views/caboose/checkout/login.html.erb +2 -0
  85. data/app/views/caboose/checkout/payment.html.erb +79 -0
  86. data/app/views/caboose/checkout/relay.html.erb +23 -0
  87. data/app/views/caboose/checkout/relay_old.html.erb +12 -0
  88. data/app/views/caboose/checkout/relay_postMessage.html.erb +19 -0
  89. data/app/views/caboose/checkout/shipping.html.erb +15 -0
  90. data/app/views/caboose/checkout/step_four.html.erb +93 -0
  91. data/app/views/caboose/checkout/step_one.html.erb +56 -0
  92. data/app/views/caboose/checkout/step_one_old.html.erb +13 -0
  93. data/app/views/caboose/checkout/step_three.html.erb +23 -0
  94. data/app/views/caboose/checkout/step_two.html.erb +52 -0
  95. data/app/views/caboose/checkout/step_two_old.html.erb +14 -0
  96. data/app/views/caboose/checkout/thanks.html.erb +5 -0
  97. data/app/views/caboose/orders/_admin_footer.html.erb +2 -0
  98. data/app/views/caboose/orders/_admin_header.html.erb +31 -0
  99. data/app/views/caboose/orders/_quickbooks_order.html.erb +0 -0
  100. data/app/views/caboose/orders/admin_delete_form.html.erb +21 -0
  101. data/app/views/caboose/orders/admin_edit.html.erb +271 -0
  102. data/app/views/caboose/orders/admin_index.html.erb +89 -0
  103. data/app/views/caboose/orders/admin_new.html.erb +42 -0
  104. data/app/views/caboose/orders/admin_print.html.erb +72 -0
  105. data/app/views/caboose/orders_mailer/customer_new_order.html.erb +1 -0
  106. data/app/views/caboose/orders_mailer/customer_status_updated.html.erb +1 -0
  107. data/app/views/caboose/orders_mailer/fulfillment_new_order.html.erb +1 -0
  108. data/app/views/caboose/orders_mailer/shipping_order_ready.html.erb +1 -0
  109. data/app/views/caboose/products/_admin_footer.html.erb +2 -0
  110. data/app/views/caboose/products/_admin_header.html.erb +32 -0
  111. data/app/views/caboose/products/_sort_options.html.erb +19 -0
  112. data/app/views/caboose/products/admin_add_upcs.html.erb +58 -0
  113. data/app/views/caboose/products/admin_delete_form.html.erb +21 -0
  114. data/app/views/caboose/products/admin_edit_categories.html.erb +73 -0
  115. data/app/views/caboose/products/admin_edit_category_images.html.erb +233 -0
  116. data/app/views/caboose/products/admin_edit_description.html.erb +38 -0
  117. data/app/views/caboose/products/admin_edit_general.html.erb +104 -0
  118. data/app/views/caboose/products/admin_edit_images.html.erb +236 -0
  119. data/app/views/caboose/products/admin_edit_options.html.erb +51 -0
  120. data/app/views/caboose/products/admin_edit_seo.html.erb +37 -0
  121. data/app/views/caboose/products/admin_edit_variant_columns.html.erb +75 -0
  122. data/app/views/caboose/products/admin_edit_variant_sort_order.html.erb +63 -0
  123. data/app/views/caboose/products/admin_edit_variants.html.erb +171 -0
  124. data/app/views/caboose/products/admin_edit_variants_single.html.erb +68 -0
  125. data/app/views/caboose/products/admin_group_variants.html.erb +433 -0
  126. data/app/views/caboose/products/admin_index.html.erb +95 -0
  127. data/app/views/caboose/products/admin_new.html.erb +41 -0
  128. data/app/views/caboose/products/admin_sort.html copy.erb +155 -0
  129. data/app/views/caboose/products/admin_sort.html.erb +254 -0
  130. data/app/views/caboose/products/details.html.erb +438 -0
  131. data/app/views/caboose/products/index.html.erb +46 -0
  132. data/app/views/caboose/products/not_available.html.erb +35 -0
  133. data/app/views/caboose/variants/admin_edit.html.erb +82 -0
  134. data/app/views/caboose/variants/admin_group.html.erb +184 -0
  135. data/app/views/caboose/variants/admin_new.html.erb +59 -0
  136. data/app/views/caboose/vendors/admin_edit.html.erb +24 -0
  137. data/app/views/caboose/vendors/admin_index.html.erb +30 -0
  138. data/app/views/caboose/vendors/admin_new.html.erb +34 -0
  139. data/app/views/layouts/caboose/store/_banner.html.erb +10 -0
  140. data/app/views/layouts/caboose/store/_banner2.html.erb +10 -0
  141. data/app/views/layouts/caboose/store/_footer.html.erb +55 -0
  142. data/app/views/layouts/caboose/store/_header.html.erb +69 -0
  143. data/app/views/layouts/caboose/store/_sidebar.html.erb +27 -0
  144. data/app/views/layouts/caboose/store/application.html.erb +33 -0
  145. data/app/views/layouts/caboose/store/authorize_net.erb +18 -0
  146. data/app/views/layouts/caboose/store/layout_about.html.erb +42 -0
  147. data/app/views/layouts/caboose/store/layout_blog.html.erb +159 -0
  148. data/app/views/layouts/caboose/store/layout_confirm.html.erb +85 -0
  149. data/app/views/layouts/caboose/store/layout_contact.html.erb +38 -0
  150. data/app/views/layouts/caboose/store/layout_default.html.erb +10 -0
  151. data/app/views/layouts/caboose/store/layout_detail.html.erb +114 -0
  152. data/app/views/layouts/caboose/store/layout_order.html.erb +77 -0
  153. data/app/views/layouts/caboose/store/layout_pricing.html.erb +182 -0
  154. data/app/views/layouts/caboose/store/layout_product.html.erb +110 -0
  155. data/app/views/layouts/caboose/store/layout_profile.html.erb +55 -0
  156. data/app/views/layouts/caboose/store/layout_single.html.erb +3 -0
  157. data/app/views/layouts/caboose/store/layout_testimonial.html.erb +110 -0
  158. data/app/views/layouts/caboose/store/layout_testing.html.erb +4 -0
  159. data/config/routes.rb +126 -0
  160. data/lib/caboose.rb +46 -1
  161. data/lib/caboose/engine.rb +39 -1
  162. data/lib/caboose/version.rb +1 -1
  163. data/lib/tasks/caboose.rake +12 -0
  164. metadata +151 -4
  165. data/app/assets/javascripts/caboose/admin_page_edit_content_bak.js +0 -164
  166. data/app/assets/javascripts/caboose/model/#Untitled-1# +0 -2
@@ -0,0 +1,8 @@
1
+ <div class="wrapper">
2
+ <form action="/checkout/attach-guest" method="post">
3
+ <input name="email" type="text" placeholder="Email" />
4
+ <input name="confirm_email" type="email" placeholder="Confirm email" />
5
+ <input type="submit" value="Submit" />
6
+ </form>
7
+ </div>
8
+
@@ -0,0 +1,11 @@
1
+ <div class="wrapper">
2
+ <form action="/register" method="post">
3
+ <input name="first_name" type="text" placeholder="First Name" />
4
+ <input name="last_name" type="text" placeholder="Last Name" />
5
+ <input name="email" type="text" placeholder="Email" />
6
+ <input name="phone" type="text" placeholder="Phone" />
7
+ <input name="pass1" type="password" placeholder="Password" />
8
+ <input name="pass2" type="password" placeholder="Confirm Password" />
9
+ <input type="submit" value="Submit" />
10
+ </form>
11
+ </div>
@@ -0,0 +1,7 @@
1
+ <div class="wrapper">
2
+ <form action="/login" method="post">
3
+ <input name="username" type="text" placeholder="Email" />
4
+ <input name="password" type="password" placeholder="Password" />
5
+ <input type="submit" value="Submit" />
6
+ </form>
7
+ </div>
@@ -0,0 +1,31 @@
1
+ <p class="wrapper">Your Cart:</p>
2
+
3
+ <ul>
4
+ <% _.each(order.line_items, function(lineItem) { %>
5
+ <li data-id="<%= lineItem.id %>">
6
+ <div class="wrapper">
7
+ <aside>
8
+ <figure style="background-image: url(<%= lineItem.variant.images[0].urls.thumb %>)"></figure>
9
+ <p><%= lineItem.title %><br />Qty: <%= lineItem.quantity %><br /><span class="price">$<%= ((parseFloat(lineItem.price) * 100) / 100).toFixed(2) %></span></p>
10
+ </aside>
11
+ <section>
12
+ <p>$<%= ((parseFloat(lineItem.price) * 100) / 100).toFixed(2) %></p>
13
+ </section>
14
+ </div>
15
+ </li>
16
+ <% }); %>
17
+ </ul>
18
+
19
+
20
+ <p class="wrapper subtotal"><span>Subtotal:</span> <span>$<%= ((parseFloat(order.subtotal) * 100) / 100).toFixed(2) %></span></p>
21
+
22
+ <% if (order.shipping > 0) { %>
23
+ <p class="wrapper shipping"><span>Shipping & Handling:</span> <span>$<%= (((parseFloat(order.shipping) + parseFloat(order.handling)) * 100) / 100).toFixed(2) %></span></p>
24
+ <% } %>
25
+
26
+ <% if (order.tax > 0 && order.billing_address.state == 'AL') { %>
27
+ <p class="wrapper tax"><span>Tax <small>(if in Alabama)</small>:</span> <span>$<%= parseFloat(Math.round(order.tax * 100) / 100).toFixed(2) %></span></p>
28
+ <% } %>
29
+
30
+ <p class="wrapper total"><span>Total:</span> <span>$<%= parseFloat(Math.round(order.total * 100) / 100).toFixed(2) %></span></p>
31
+
@@ -0,0 +1,21 @@
1
+ <div class="wrapper" class='login-choices'>
2
+ <ul>
3
+ <li>
4
+ <p>Already a member<p>
5
+ <button data-login-action="signin" id='signin_button'>Sign in</button>
6
+ </li>
7
+
8
+ <li>
9
+ <p>Sign up for all of our member benefits</p>
10
+ <button data-login-action="register" id='register_button'>New Customer</button>
11
+ </li>
12
+
13
+ <li>
14
+ <p>No thanks</p>
15
+ <button data-login-action="continue" id='continue_button'>Continue As Guest</button>
16
+ </li>
17
+ </ul>
18
+ </div>
19
+
20
+ <section></section>
21
+
@@ -0,0 +1,5 @@
1
+ <div class="wrapper">
2
+ <h3>Complete my purchase</h3>
3
+ <%= form %>
4
+ </div>
5
+
@@ -0,0 +1,18 @@
1
+ <% if (rates) { %>
2
+ <section>
3
+ <div class="wrapper">
4
+ <h3>Shipping Method</h3>
5
+ <p>Please select how you would like your products to be delivered</p>
6
+
7
+ <select name="shipping">
8
+ <option value="">Choose a shipping method</option>
9
+
10
+ <% _.each(rates, function(rate) { %>
11
+ <option value="<%= rate.service_code %>" <% if (selectedRate && selectedRate.service_code == rate.service_code) { %>selected<% } %>>
12
+ <%= '$' + parseFloat(rate.total_price).toFixed(2) + ' - ' + rate.service_name %>
13
+ </option>
14
+ <% }); %>
15
+ </select>
16
+ </div>
17
+ </section>
18
+ <% } %>
@@ -0,0 +1,8 @@
1
+ <figure></figure>
2
+
3
+ <ul>
4
+ <% _.each(images, function(image) { %>
5
+ <li data-id="<%= image.id %>"><figure style="background-image: url(<%= image.urls.thumb %>)" data-url-large="<%= image.urls.large %>"></figure></li>
6
+ <% }); %>
7
+ </ul>
8
+
@@ -0,0 +1,19 @@
1
+ <!--<% _.each(options, function(option, index) { %>
2
+ <select id="<%= 'option' + (index + 1) %>" name="<%= option.name %>">
3
+ <option value="">Choose an Option</option>
4
+
5
+ <% _.each(option.values, function(value) { %>
6
+ <option value="<%= value %>"><%= value %></option>
7
+ <% }); %>
8
+ </select>
9
+ <% }); %>-->
10
+
11
+ <% _.each(options, function(option, index) { %>
12
+ <h3><%= option.name %></h3>
13
+ <ul id="<%= 'option' + (index + 1) %>" data-name="<%= option.name %>">
14
+ <% _.each(_.sortBy(option.values, function(option) { return parseFloat(option) }), function(value) { %>
15
+ <li data-value="<%= value %>"><%= value %></li>
16
+ <% }); %>
17
+ </ul>
18
+ <% }); %>
19
+
@@ -4,6 +4,7 @@ module Caboose
4
4
  protect_from_forgery
5
5
  before_filter :before_before_action
6
6
  helper_method :logged_in?
7
+ helper :all
7
8
 
8
9
  @find_page = true
9
10
 
@@ -42,11 +43,38 @@ module Caboose
42
43
  #end
43
44
 
44
45
  # Sets an instance variable of the logged in user
45
- @logged_in_user = logged_in_user
46
+ @logged_in_user = logged_in_user
47
+
48
+ # Initialize the card
49
+ init_cart if Caboose::use_store
46
50
 
47
51
  before_action
48
52
  end
49
53
 
54
+ # Initialize the cart in the session
55
+ def init_cart
56
+ # Check if the cart ID is defined and that it exists in the database
57
+ if !session[:cart_id] || !Order.exists?(session[:cart_id])
58
+
59
+ # Create an order to associate with the session
60
+ order = Order.create(
61
+ :status => 'cart',
62
+ :financial_status => 'pending',
63
+ :date_created => DateTime.now,
64
+ :referring_site => request.env['HTTP_REFERER'],
65
+ :landing_page => request.fullpath,
66
+ :landing_page_ref => params[:ref] || nil
67
+ )
68
+ order.update_attribute(:shipping_method_code, Caboose::store_shipping[:default_shipping_method_code]) if Caboose::store_shipping[:default_shipping_method_code]
69
+
70
+ # Define the cart ID
71
+ session[:cart_id] = order.id
72
+ end
73
+
74
+ # Log the order and set an instance variable up
75
+ @order = Order.find(session[:cart_id])
76
+ end
77
+
50
78
  # Parses any parameters in the URL and adds them to the params
51
79
  def parse_url_params
52
80
  return if !Caboose.use_url_params
@@ -0,0 +1,52 @@
1
+ module Caboose
2
+ class CartController < Caboose::ApplicationController
3
+ before_filter :get_line_item, :only => [:update, :remove]
4
+
5
+ def get_line_item
6
+ @line_item = @order.line_items.find(params[:id])
7
+ end
8
+
9
+ # GET /cart
10
+ def index
11
+
12
+ end
13
+
14
+ # GET /cart/items
15
+ def list
16
+ render :json => { :order => @order }
17
+ end
18
+
19
+ # GET /cart/item-count
20
+ def item_count
21
+ render :json => { :item_count => @order.line_items.count }
22
+ end
23
+
24
+ # POST /cart/add
25
+ def add
26
+ if @order.line_items.exists?(:variant_id => params[:variant_id])
27
+ @line_item = @order.line_items.find_by_variant_id(params[:variant_id])
28
+ @line_item.quantity += params[:quantity] ? params[:quantity].to_i : 1
29
+ else
30
+ @line_item = LineItem.new
31
+ @line_item.variant_id = params[:variant_id]
32
+ @line_item.order_id = @order.id
33
+ @line_item.status = 'pending'
34
+ @line_item.quantity = params[:quantity] ? params[:quantity].to_i : 1
35
+ end
36
+
37
+ render :json => { :success => @line_item.save, :errors => @line_item.errors.full_messages, :item_count => @order.line_items.count }
38
+ end
39
+
40
+ # PUT cart/update
41
+ def update
42
+ @line_item.quantity = params[:quantity].to_i
43
+ render :json => { :success => @line_item.save, :errors => @line_item.errors.full_messages, :line_item => @line_item, :order_subtotal => @order.calculate_subtotal }
44
+ end
45
+
46
+ # DELETE cart/delete
47
+ def remove
48
+ render :json => { :success => !!@order.line_items.delete(@line_item), :item_count => @order.line_items.count }
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,108 @@
1
+ module Caboose
2
+ class CategoriesController < Caboose::ApplicationController
3
+
4
+ #=============================================================================
5
+ # Admin actions
6
+ #=============================================================================
7
+
8
+ # GET /admin/categories
9
+ def admin_index
10
+ return unless user_is_allowed('categories', 'view')
11
+ render layout: 'caboose/admin'
12
+ end
13
+
14
+ # GET /admin/categories/new
15
+ def admin_new
16
+ return unless user_is_allowed('categories', 'add')
17
+ render layout: 'caboose/admin'
18
+ end
19
+
20
+ # POST /admin/categories
21
+ def admin_add
22
+ return unless user_is_allowed('categories', 'add')
23
+
24
+ if params[:parent_id].nil? or params[:parent_id].empty?
25
+ render :json => { :error => 'Please select a parent category.' }
26
+ elsif params[:name].nil? or params[:name].empty?
27
+ render :json => { :error => 'This title cannot be empty' }
28
+ else
29
+ category = Category.new
30
+ category.parent_id = params[:parent_id]
31
+ category.name = params[:name]
32
+ category.slug = category.generate_slug
33
+ category.url = "#{Category.find(params[:parent_id]).url}/#{category.slug}"
34
+
35
+ if category.save
36
+ render :json => { :success => true, :redirect => "/admin/categories/#{category.id}/edit" }
37
+ else
38
+ render :json => { :error => 'There was an error saving the category.' }
39
+ end
40
+ end
41
+ end
42
+
43
+ # GET /admin/categories/:id/edit
44
+ def admin_edit
45
+ return unless user_is_allowed('categories', 'edit')
46
+ @category = Category.find(params[:id])
47
+ render layout: 'caboose/admin'
48
+ end
49
+
50
+ # PUT /admin/categories/:id
51
+ def admin_update
52
+ return unless user_is_allowed('categories', 'edit')
53
+
54
+ # Define category and initialize response
55
+ category = Category.find(params[:id])
56
+ response = { attributes: Hash.new }
57
+
58
+ # Iterate over params and update relevant attributes
59
+ params.each do |key, value|
60
+ case key
61
+ when 'name' then category.name = value
62
+ when 'slug' then category.slug = value
63
+ when 'status' then category.status = value
64
+ when 'image' then category.image = value
65
+ end
66
+ end
67
+
68
+ # Try and save category
69
+ response[:success] = category.save
70
+
71
+ # If an image is passed, return the url
72
+ response[:attributes][:image] = { value: category.image.url(:medium) } if params[:image]
73
+
74
+ # Respond to update request
75
+ render :json => response
76
+ end
77
+
78
+ # DELETE /admin/categories/:id
79
+ def admin_delete
80
+ return unless user_is_allowed('categories', 'delete')
81
+
82
+ category = Category.find(params[:id])
83
+
84
+ if category.products.any?
85
+ render :json => { :error => "Can't delete a category that has products in it." }
86
+ elsif category.children.any?
87
+ render :json => { :error => "You can't delete a category that has child categories." }
88
+ else
89
+ render :json => { :success => category.destroy, :redirect => '/admin/categories' }
90
+ end
91
+ end
92
+
93
+
94
+ # GET /admin/products/status-options
95
+ def admin_status_options
96
+ arr = ['Active', 'Inactive', 'Deleted']
97
+ options = []
98
+ arr.each do |status|
99
+ options << {
100
+ :value => status,
101
+ :text => status
102
+ }
103
+ end
104
+ render :json => options
105
+ end
106
+ end
107
+ end
108
+
@@ -0,0 +1,325 @@
1
+ module Caboose
2
+ class CheckoutController < Caboose::ApplicationController
3
+ helper :authorize_net
4
+ before_filter :ensure_line_items, :only => [:step_one, :step_two]
5
+ protect_from_forgery :except => :relay
6
+
7
+ def ensure_line_items
8
+ redirect_to '/checkout/empty' if @order.line_items.empty?
9
+ end
10
+
11
+ # GET /checkout
12
+ def index
13
+ redirect_to '/checkout/step-one'
14
+ end
15
+
16
+ # GET /checkout/step-one
17
+ def step_one
18
+ if logged_in?
19
+ if @order.customer_id.nil?
20
+ @order.customer_id = logged_in_user.id
21
+ @order.save
22
+ end
23
+ redirect_to '/checkout/step-two'
24
+ return
25
+ end
26
+ end
27
+
28
+ # GET /checkout/step-two
29
+ def step_two
30
+ #redirect_to '/checkout/step-one' if !@order.shipping_address || !@order.billing_address
31
+ redirect_to '/checkout/step-one' if !logged_in?
32
+ end
33
+
34
+ # GET /checkout/step-three
35
+ def step_three
36
+ redirect_to '/checkout/step-one' and return if !logged_in?
37
+ redirect_to '/checkout/step-two' and return if @order.shipping_address.nil? || @order.billing_address.nil?
38
+ @rates = ShippingCalculator.rates(@order)
39
+ @selected_rate = ShippingCalculator.rate(@order)
40
+ end
41
+
42
+ # GET /checkout/step-four
43
+ def step_four
44
+ redirect_to '/checkout/step-one' and return if !logged_in?
45
+ redirect_to '/checkout/step-two' and return if @order.shipping_address.nil? || @order.billing_address.nil?
46
+ redirect_to '/checkout/step-three' and return if @order.shipping_method_code.nil?
47
+
48
+ # Make sure all the variants still exist
49
+ @order.line_items.each do |li|
50
+ v = Variant.where(:id => li.variant_id).first
51
+ if v.nil? || v.status == 'Deleted'
52
+ render :file => 'caboose/checkout/deleted_variant'
53
+ return
54
+ end
55
+ end
56
+
57
+ case Caboose::payment_processor
58
+ when 'authorize.net'
59
+ @sim_transaction = AuthorizeNet::SIM::Transaction.new(
60
+ Caboose::authorize_net_login_id,
61
+ Caboose::authorize_net_transaction_key,
62
+ @order.total,
63
+ :relay_url => "#{Caboose::store_url}/checkout/relay/#{@order.id}",
64
+ :transaction_type => 'AUTH_ONLY',
65
+ :test => true
66
+ )
67
+ when 'payscape'
68
+ @form_url = Caboose::PaymentProcessor.form_url(@order)
69
+ end
70
+ end
71
+
72
+ # GET /checkout/thanks
73
+ def thanks
74
+ end
75
+
76
+ #===========================================================================
77
+
78
+ # GET /checkout/address
79
+ def address
80
+ render :json => {
81
+ :shipping_address => @order.shipping_address,
82
+ :billing_address => @order.billing_address
83
+ }
84
+ end
85
+
86
+ # PUT /checkout/address
87
+ def update_address
88
+
89
+ # Grab or create addresses
90
+ shipping_address = if @order.shipping_address then @order.shipping_address else Address.new end
91
+ billing_address = if @order.billing_address then @order.billing_address else Address.new end
92
+
93
+ # Shipping address
94
+ shipping_address.first_name = params[:shipping][:first_name]
95
+ shipping_address.last_name = params[:shipping][:last_name]
96
+ shipping_address.company = params[:shipping][:company]
97
+ shipping_address.address1 = params[:shipping][:address1]
98
+ shipping_address.address2 = params[:shipping][:address2]
99
+ shipping_address.city = params[:shipping][:city]
100
+ shipping_address.state = params[:shipping][:state]
101
+ shipping_address.zip = params[:shipping][:zip]
102
+
103
+ # Billing address
104
+ if params[:use_as_billing]
105
+ billing_address.update_attributes(shipping_address.attributes)
106
+ else
107
+ billing_address.first_name = params[:billing][:first_name]
108
+ billing_address.last_name = params[:billing][:last_name]
109
+ billing_address.company = params[:billing][:company]
110
+ billing_address.address1 = params[:billing][:address1]
111
+ billing_address.address2 = params[:billing][:address2]
112
+ billing_address.city = params[:billing][:city]
113
+ billing_address.state = params[:billing][:state]
114
+ billing_address.zip = params[:billing][:zip]
115
+ end
116
+
117
+ # Save address info; generate ids
118
+ render :json => { :success => false, :errors => shipping_address.errors.full_messages, :address => 'shipping' } and return if !shipping_address.save
119
+ render :json => { :success => false, :errors => billing_address.errors.full_messages, :address => 'billing' } and return if !billing_address.save
120
+
121
+ # Associate address info with order
122
+ @order.shipping_address_id = shipping_address.id
123
+ @order.billing_address_id = billing_address.id
124
+
125
+ #render :json => { :redirect => 'checkout/shipping' }
126
+ render :json => { :success => @order.save, :errors => @order.errors.full_messages }
127
+ end
128
+
129
+ # POST /checkout/attach-user
130
+ def attach_user
131
+ render :json => { :success => false, :errors => ['User is not logged in'] } and return if !logged_in?
132
+ @order.customer_id = logged_in_user.id
133
+ render :json => { :success => @order.save, :errors => @order.errors.full_messages, :logged_in => logged_in? }
134
+ end
135
+
136
+ # POST /checkout/guest
137
+ def attach_guest
138
+ resp = Caboose::StdClass.new
139
+ email = params[:email]
140
+
141
+ if email != params[:confirm_email]
142
+ resp.error = "Emails do not match."
143
+ elsif Caboose::User.where(:email => email, :is_guest => false).exists?
144
+ resp.error = "A user with that email address already exists."
145
+ else
146
+ user = Caboose::User.where(:email => email, :is_guest => true).first
147
+ if user.nil?
148
+ user = Caboose::User.create(:email => email)
149
+ user.is_guest = true
150
+ user.save
151
+ user = Caboose::User.where(:email => email).first
152
+ end
153
+ @order.customer_id = user.id
154
+ login_user(user)
155
+
156
+ if !@order.valid?
157
+ resp.errors = @order.errors.full_messages
158
+ else
159
+ @order.save
160
+ resp.redirect = '/checkout/step-two'
161
+ end
162
+ end
163
+ render :json => resp
164
+ end
165
+
166
+ ## GET /checkout/shipping
167
+ #def shipping
168
+ # render :json => { :rates => ShippingCalculator.rates(@order), :selected_rate => ShippingCalculator.rate(@order) }
169
+ #end
170
+
171
+ # PUT /checkout/shipping
172
+ def update_shipping
173
+ @order.shipping_method = params[:shipping_method]
174
+ @order.shipping_method_code = params[:shipping_method_code]
175
+ render :json => {
176
+ :success => @order.save,
177
+ :errors => @order.errors.full_messages
178
+ #:order => @order,
179
+ #:selected_rate => ShippingCalculator.rate(@order)
180
+ }
181
+ end
182
+
183
+ # GET /checkout/payment
184
+ #def payment
185
+ # case Caboose::payment_processor
186
+ # when 'authorize.net'
187
+ # @sim_transaction = AuthorizeNet::SIM::Transaction.new(
188
+ # Caboose::authorize_net_login_id,
189
+ # Caboose::authorize_net_transaction_key,
190
+ # @order.total,
191
+ # :relay_url => "#{Caboose::root_url}/checkout/relay/#{@order.id}",
192
+ # :transaction_type => 'AUTH_ONLY',
193
+ # :test => true
194
+ # )
195
+ # when 'payscape'
196
+ # @form_url = Caboose::PaymentProcessor.form_url(@order)
197
+ # end
198
+ # render :layout => false
199
+ #end
200
+
201
+ # POST /checkout/relay/:order_id
202
+ def relay
203
+ ap '--HOOK RELAY'
204
+ @order = Caboose::Order.find(params[:order_id])
205
+ @success = Caboose::PaymentProcessor.authorize(@order, params)
206
+ @message = @success ? 'Payment processed successfully' : 'There was a problem processing your payment'
207
+
208
+ #case Caboose::payment_processor
209
+ # when 'authorize.net'
210
+ # @success = params[:x_response_code] == '1'
211
+ # @message = jarams[:x_response_reason_text]
212
+ # @order.transaction_id = params[:x_trans_id] if params[:x_trans_id]
213
+ # when 'payscape'
214
+ # @success = Caboose::PaymentProcessor.authorize(@order, params)
215
+ # @message = @success ? 'Payment processed successfully' : 'There was a problem processing your payment'
216
+ # @order.transaction_id = params['transaction-id'] if params['transaction-id']
217
+ #end
218
+
219
+ if @success
220
+ @order.financial_status = 'authorized'
221
+ @order.status = 'pending'
222
+ @order.date_authorized = DateTime.now
223
+ @order.auth_amount = @order.total
224
+
225
+ # Clear cart
226
+ session[:cart_id] = nil
227
+
228
+ # Send out emails
229
+ OrdersMailer.customer_new_order(@order).deliver
230
+ OrdersMailer.fulfillment_new_order(@order).deliver
231
+
232
+ # Emit order event
233
+ Caboose.plugin_hook('order_authorized', @order)
234
+ else
235
+ @order.financial_status = 'unauthorized'
236
+ end
237
+
238
+ @order.save
239
+ render :layout => false
240
+ end
241
+
242
+ # GET /checkout/discount
243
+ #def discount
244
+ # # TODO make it possible to use multiple discounts
245
+ #
246
+ # @gift_card = @order.discounts.first
247
+ #end
248
+
249
+ # POST /checkout/update-discount
250
+ #def add_discount
251
+ # gift_card = Discount.find_by_code(params[:gift_card_number])
252
+ #
253
+ # render :json => { :error => true, :message => 'Gift card not found.' } and return if gift_card.nil?
254
+ # render :json => { :error => true, :message => 'Gift card has no remaining funds.' } and return if gift_card.amount_current <= 0
255
+ #
256
+ # @order.discounts.delete_all if @order.discounts.any?
257
+ # @order.discounts << gift_card
258
+ # @order.calculate_total
259
+ #
260
+ # render :json => { :success => true, :message => 'Gift card added successfully.' }
261
+ #end
262
+
263
+ #def relay
264
+ #
265
+ # # Check to see that the order has a valid total and was authorized
266
+ # if @order.total > 0 && PaymentProcessor.authorize(@order, params)
267
+ #
268
+ # # Update order
269
+ # @order.date_authorized = DateTime.now
270
+ # @order.auth_amount = @order.total
271
+ # @order.financial_status = 'authorized'
272
+ # @order.status = if @order.test? then 'testing' else 'pending' end
273
+ #
274
+ # # Send out notifications
275
+ # OrdersMailer.customer_new_order(@order).deliver
276
+ # OrdersMailer.fulfillment_new_order(@order).deliver
277
+ #
278
+ # # Clear everything
279
+ # session[:cart_id] = nil
280
+ #
281
+ # # Emit order event
282
+ # Caboose.plugin_hook('order_authorized', @order)
283
+ #
284
+ # # Decrement quantities of variants
285
+ # @order.decrement_quantities
286
+ # else
287
+ # @order.financial_status = 'unauthorized'
288
+ # end
289
+ #
290
+ # @order.save
291
+ #end
292
+
293
+ # GET /checkout/authorize-by-gift-card
294
+ #def authorize_by_gift_card
295
+ # if @order.total < @order.discounts.first.amount_current
296
+ #
297
+ # # Update order
298
+ # @order.date_authorized = DateTime.now
299
+ # @order.auth_amount = @order.total
300
+ # @order.financial_status = 'authorized'
301
+ # @order.status = if @order.test? then 'testing' else 'pending' end
302
+ #
303
+ # # Send out notifications
304
+ # OrdersMailer.customer_new_order(@order).deliver
305
+ # OrdersMailer.fulfillment_new_order(@order).deliver
306
+ #
307
+ # # Clear everything
308
+ # session[:cart_id] = nil
309
+ #
310
+ # # Emit order event
311
+ # Caboose.plugin_hook('order_authorized', @order)
312
+ #
313
+ # # Decrement quantities of variants
314
+ # @order.decrement_quantities
315
+ #
316
+ # @order.save
317
+ #
318
+ # redirect_to '/checkout/thanks'
319
+ # else
320
+ # redirect_to '/checkout/error'
321
+ # end
322
+ #end
323
+
324
+ end
325
+ end