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,81 @@
1
+ require 'active_shipping'
2
+ include ActiveMerchant::Shipping
3
+
4
+ module Caboose
5
+ class ShippingCalculator
6
+ def self.rates(order)
7
+ return [] if Caboose::shipping.nil?
8
+
9
+ total = 0.0
10
+ weight = 0.0
11
+
12
+ order.line_items.each do |li|
13
+ total = total + (li.variant.shipping_unit_value.nil? ? 0 : li.variant.shipping_unit_value)
14
+ weight = weight + (li.variant.weight || 0)
15
+ end
16
+
17
+ length = 0
18
+ width = 0
19
+ height = 0
20
+
21
+ if total <= 5
22
+ length = 15.5
23
+ width = 9.5
24
+ height = 6
25
+ elsif total <= 10
26
+ length = 12
27
+ width = 8
28
+ height = 5
29
+ else
30
+ length = 20
31
+ width = 16
32
+ height = 14
33
+ end
34
+
35
+ origin = Location.new(
36
+ :country => Caboose::shipping[:origin][:country],
37
+ :state => Caboose::shipping[:origin][:state],
38
+ :city => Caboose::shipping[:origin][:city],
39
+ :zip => Caboose::shipping[:origin][:zip]
40
+ )
41
+
42
+ destination = Location.new(
43
+ :country => Caboose::shipping[:origin][:country],
44
+ :state => order.shipping_address.state,
45
+ :city => order.shipping_address.city,
46
+ :postal_code => order.shipping_address.zip
47
+ )
48
+
49
+ packages = [Package.new(weight, [length, width, height], :units => :imperial)]
50
+
51
+ ups = UPS.new(
52
+ :key => Caboose::shipping[:ups][:key],
53
+ :login => Caboose::shipping[:ups][:username],
54
+ :password => Caboose::shipping[:ups][:password],
55
+ :origin_account => Caboose::shipping[:ups][:origin_account]
56
+ )
57
+
58
+ ups_response = ups.find_rates(origin, destination, packages)
59
+
60
+ rates = ups_response.rates.collect do |rate|
61
+ next if Caboose::allowed_shipping_method_codes && !Caboose::allowed_shipping_method_codes.index(rate.service_code)
62
+
63
+ {
64
+ :service_code => rate.service_code,
65
+ :service_name => rate.service_name,
66
+ :total_price => rate.total_price.to_d / 100,
67
+ :negotiated_rate => rate.negotiated_rate
68
+ }
69
+ end
70
+
71
+ return rates.compact
72
+ end
73
+
74
+ def self.rate(order)
75
+ return nil if !order.shipping_method_code
76
+ self.rates(order).each { |rate| return rate if rate[:service_code] == order.shipping_method_code }
77
+ return nil
78
+ end
79
+ end
80
+ end
81
+
@@ -1,57 +1,66 @@
1
1
  class Caboose::States
2
2
  def self.all
3
- return {
4
- 'AL' => 'Alabama',
5
- 'AK' => 'Alaska',
6
- 'AZ' => 'Arizona',
7
- 'AR' => 'Arkansas',
8
- 'CA' => 'California',
9
- 'CO' => 'Colorado',
10
- 'CT' => 'Connecticut',
11
- 'DE' => 'Delaware',
12
- 'DC' => 'District of Columbia',
13
- 'FL' => 'Florida',
14
- 'GA' => 'Georgia',
15
- 'HI' => 'Hawaii',
16
- 'ID' => 'Idaho',
17
- 'IL' => 'Illinois',
18
- 'IN' => 'Indiana',
19
- 'IA' => 'Iowa',
20
- 'KS' => 'Kansas',
21
- 'KY' => 'Kentucky',
22
- 'LA' => 'Louisiana',
23
- 'ME' => 'Maine',
24
- 'MT' => 'Montana',
25
- 'NE' => 'Nebraska',
26
- 'NV' => 'Nevada',
27
- 'NH' => 'New Hampshire',
28
- 'NJ' => 'New Jersey',
29
- 'NM' => 'New Mexico',
30
- 'NY' => 'New York',
31
- 'NC' => 'North Carolina',
32
- 'ND' => 'North Dakota',
33
- 'OH' => 'Ohio',
34
- 'OK' => 'Oklahoma',
35
- 'OR' => 'Oregon',
36
- 'MD' => 'Maryland',
37
- 'MA' => 'Massachusetts',
38
- 'MI' => 'Michigan',
39
- 'MN' => 'Minnesota',
40
- 'MS' => 'Mississippi',
41
- 'MO' => 'Missouri',
42
- 'PA' => 'Pennsylvania',
43
- 'RI' => 'Rhode Island',
44
- 'SC' => 'South Carolina',
45
- 'SD' => 'South Dakota',
46
- 'TN' => 'Tennessee',
47
- 'TX' => 'Texas',
48
- 'UT' => 'Utah',
49
- 'VT' => 'Vermont',
50
- 'VA' => 'Virginia',
51
- 'WA' => 'Washington',
52
- 'WV' => 'West Virginia',
53
- 'WI' => 'Wisconsin',
54
- 'WY' => 'Wyoming'
3
+ {
4
+ "AL" => "Alabama",
5
+ "AK" => "Alaska",
6
+ "AS" => "American Samoa",
7
+ "AZ" => "Arizona",
8
+ "AR" => "Arkansas",
9
+ "CA" => "California",
10
+ "CO" => "Colorado",
11
+ "CT" => "Connecticut",
12
+ "DE" => "Delaware",
13
+ "DC" => "District Of Columbia",
14
+ "FM" => "Federated States Of Micronesia",
15
+ "FL" => "Florida",
16
+ "GA" => "Georgia",
17
+ "GU" => "Guam",
18
+ "HI" => "Hawaii",
19
+ "ID" => "Idaho",
20
+ "IL" => "Illinois",
21
+ "IN" => "Indiana",
22
+ "IA" => "Iowa",
23
+ "KS" => "Kansas",
24
+ "KY" => "Kentucky",
25
+ "LA" => "Louisiana",
26
+ "ME" => "Maine",
27
+ "MH" => "Marshall Islands",
28
+ "MD" => "Maryland",
29
+ "MA" => "Massachusetts",
30
+ "MI" => "Michigan",
31
+ "MN" => "Minnesota",
32
+ "MS" => "Mississippi",
33
+ "MO" => "Missouri",
34
+ "MT" => "Montana",
35
+ "NE" => "Nebraska",
36
+ "NV" => "Nevada",
37
+ "NH" => "New Hampshire",
38
+ "NJ" => "New Jersey",
39
+ "NM" => "New Mexico",
40
+ "NY" => "New York",
41
+ "NC" => "North Carolina",
42
+ "ND" => "North Dakota",
43
+ "MP" => "Northern Mariana Islands",
44
+ "OH" => "Ohio",
45
+ "OK" => "Oklahoma",
46
+ "OR" => "Oregon",
47
+ "PW" => "Palau",
48
+ "PA" => "Pennsylvania",
49
+ "PR" => "Puerto Rico",
50
+ "RI" => "Rhode Island",
51
+ "SC" => "South Carolina",
52
+ "SD" => "South Dakota",
53
+ "TN" => "Tennessee",
54
+ "TX" => "Texas",
55
+ "UT" => "Utah",
56
+ "VT" => "Vermont",
57
+ "VI" => "Virgin Islands",
58
+ "VA" => "Virginia",
59
+ "WA" => "Washington",
60
+ "WV" => "West Virginia",
61
+ "WI" => "Wisconsin",
62
+ "WY" => "Wyoming"
55
63
  }
56
64
  end
57
65
  end
66
+
@@ -0,0 +1,23 @@
1
+ module Caboose
2
+ class TaxCalculator
3
+ def self.tax_rate(address)
4
+ ap '--HOOK calculate tax'
5
+ return 0 if address.state.downcase != 'al'
6
+ city = address.city.downcase
7
+ rate = 0.00
8
+ rate = rate + 0.05 if city == 'brookwood'
9
+ rate = rate + 0.05 if city == 'coaling'
10
+ rate = rate + 0.05 if city == 'coker'
11
+ rate = rate + 0.05 if city == 'holt'
12
+ rate = rate + 0.05 if city == 'holt CDP'
13
+ rate = rate + 0.05 if city == 'lake View'
14
+ rate = rate + 0.05 if city == 'moundville'
15
+ rate = rate + 0.05 if city == 'northport'
16
+ rate = rate + 0.05 if city == 'tuscaloosa'
17
+ rate = rate + 0.05 if city == 'vance'
18
+ rate = rate + 0.05 if city == 'woodstock'
19
+ rate = rate + 0.04 if address.state.downcase == 'al' || address.state.downcase == 'alabama'
20
+ return rate.round(2)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ module Caboose
2
+ class TaxLine < ActiveRecord::Base
3
+ attr_accessible :id,
4
+ :title, # The name of the tax, eg. QST or VAT
5
+ :price, # The amount
6
+ :rate, # The rate. It will return 0.175 if it is 17.5%
7
+ :rate_percentage # The tax rate in human readable form. It will return 17.5 if the rate is 0.175
8
+ end
9
+ end
@@ -0,0 +1,99 @@
1
+ #
2
+ # Variant
3
+ #
4
+ # :: Class Methods
5
+ # :: Instance Methods
6
+
7
+ module Caboose
8
+ class Variant < ActiveRecord::Base
9
+ self.table_name = 'store_variants'
10
+
11
+ belongs_to :product
12
+ has_many :product_image_variants
13
+ has_many :product_images, :through => :product_image_variants
14
+
15
+ attr_accessible :id,
16
+ :alternate_id,
17
+ :product_id,
18
+ :barcode, # Returns the barcode value of the variant.
19
+ :price, # Variant’s price.
20
+ :ignore_quantity,
21
+ :quantity,
22
+ :quantity_in_stock,
23
+ :allow_backorder, # Whether to allow items with no inventory to be added to the cart
24
+ :status, # Current status: active, inactive, deleted
25
+ :weight, # The weight of the variant. This will always be in metric grams.
26
+ :length, # Length of variant in inches
27
+ :width, # Width of variant in inches
28
+ :height, # Height of variant in inches
29
+ :option1, # Returns the value of option1 for given variant
30
+ :option2, # If a product has a second option defined, then returns the value of this variant's option2.
31
+ :option3, # If a product has a third option defined, then returns the value of this variant's option3.
32
+ :requires_shipping, # Returns true if the variant is shippable or false if it is a service or a digital good.
33
+ :taxable, # Returns true if the variant is taxable or false if it is not.
34
+ :sku,
35
+ :available,
36
+ :cylinder,
37
+ :shipping_unit_value
38
+
39
+ #
40
+ # Class Methods
41
+ #
42
+
43
+ def self.find_by_options(product_id, option1=nil, option2=nil, option3=nil)
44
+
45
+ # Create the vars that will become the full conditions statement
46
+ where = ['product_id=?']
47
+ values = [product_id.to_i]
48
+
49
+ # Append option values if they exist
50
+
51
+ if option1
52
+ where << 'option1=?'
53
+ values << option1
54
+ end
55
+
56
+ if option2
57
+ where << 'option2=?'
58
+ values << option2
59
+ end
60
+
61
+ if option3
62
+ where << 'option3=?'
63
+ values << option3
64
+ end
65
+
66
+ # Combine all the options into a single conditions statement
67
+ conditions = [ where.join(' AND ') ].concat(values)
68
+
69
+ # Return whatever is found
70
+ return Variant.where(conditions).first
71
+ end
72
+
73
+ #
74
+ # Instance Methods
75
+ #
76
+
77
+ def as_json(options={})
78
+ self.attributes.merge({
79
+ :images => if self.product_images.any?
80
+ self.product_images
81
+ else
82
+ [self.product.product_images.first]
83
+ end
84
+ })
85
+ end
86
+
87
+ def title
88
+ return self.options.join(' / ')
89
+ end
90
+
91
+ def options
92
+ arr = []
93
+ arr << self.option1 if self.option1 && self.option1.strip.length > 0
94
+ arr << self.option2 if self.option2 && self.option2.strip.length > 0
95
+ arr << self.option3 if self.option3 && self.option3.strip.length > 0
96
+ return arr
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,22 @@
1
+
2
+ module Caboose
3
+ class Vendor < ActiveRecord::Base
4
+ self.table_name = 'store_vendors'
5
+
6
+ has_many :products
7
+ attr_accessible :id, :name, :status, :sort_order
8
+ after_save :clear_filters
9
+
10
+ def self.active
11
+ where(:status => 'Active')
12
+ end
13
+
14
+ def update_products
15
+ self.products.each { |product| product.update_attribute(:vendor_status, self.status) }
16
+ end
17
+
18
+ def clear_filters
19
+ SearchFilter.delete_all
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,8 @@
1
+ <div class="wrapper">
2
+ <div id="cart"></div>
3
+ </div>
4
+
5
+ <% content_for :caboose_js do %>
6
+ <%= javascript_include_tag 'caboose/modules/cart' %>
7
+ <%= javascript_include_tag 'caboose/modules/product' %>
8
+ <% end %>
@@ -0,0 +1,79 @@
1
+ <h1>Edit Category</h1>
2
+
3
+ <p><div class="push-below" id="category_<%= @category.id %>_name"></div></p>
4
+ <p><div class="push-below" id="category_<%= @category.id %>_slug"></div></p>
5
+ <p><div class="push-below" id="category_<%= @category.id %>_status"></div></p>
6
+ <p><div class="push-below" id="category_<%= @category.id %>_image"></div></p>
7
+
8
+ <h2>Products</h2>
9
+
10
+ <% if @category.products.any? %>
11
+ <ul>
12
+ <% @category.products.each do |product| %>
13
+ <li><a href="/admin/products/<%= product.id %>/general"><%= product.title %></a></li>
14
+ <% end %>
15
+ </ul>
16
+ <% else %>
17
+ <p>This category has no associated products.</p>
18
+ <% end %>
19
+
20
+ <div id="message"></div>
21
+ <input type="button" value="< Back" onclick="window.location='/admin/categories'" />
22
+ <input type="button" value="Delete Category" onclick="delete_category(<%= @category.id %>)" />
23
+
24
+ <% content_for :caboose_css do %>
25
+ <style>
26
+ .push-below { margin-bottom: 24px; }
27
+ </style>
28
+ <% end %>
29
+
30
+ <% content_for :caboose_js do %>
31
+ <%= javascript_include_tag "caboose/model/all" %>
32
+
33
+ <script type='text/javascript'>
34
+ var modal = false;
35
+
36
+ $(window).load(function() {
37
+ modal = new CabooseModal(800);
38
+ });
39
+
40
+ $(document).ready(function() {
41
+ m = new ModelBinder({
42
+ name: 'Category',
43
+ id: <%= @category.id %>,
44
+ update_url: '/admin/categories/<%= @category.id %>',
45
+ authenticity_token: '<%= form_authenticity_token %>',
46
+ attributes: [
47
+ { name: 'name' , nice_name: 'Name' , type: 'text' , value: <%= raw Caboose.json(@category.name) %> , width: 400 },
48
+ { name: 'slug' , nice_name: 'Slug' , type: 'text' , value: <%= raw Caboose.json(@category.slug) %> , width: 400 },
49
+ { name: 'status', nice_name: 'Status', type: 'select', value: <%= raw Caboose.json(@category.status) %> , width: 400 , text: <%= raw Caboose.json(@category.status) %>, options_url: '/admin/categories/status-options' },
50
+ { name: 'image' , nice_name: 'Image' , type: 'image' , value: <%= raw Caboose.json(@category.image.url(:medium)) %> , width: 200 }
51
+ ]
52
+ });
53
+ });
54
+
55
+ function delete_category(cat_id, confirm) {
56
+ if (!confirm) {
57
+ var p = $('<p/>').addClass('note error').css('margin-bottom', '10px')
58
+ .append("Are you sure you want to delete the category?<br />This can't be undone.<br /><br />")
59
+ .append($('<input/>').attr('type', 'button').val('Yes').click(function() { delete_category(cat_id, true); })).append(' ')
60
+ .append($('<input/>').attr('type', 'button').val('No').click(function() { $('#message').empty(); modal.autosize(); }));
61
+
62
+ modal.autosize(p, 'message');
63
+
64
+ return;
65
+ }
66
+
67
+ modal.autosize("<p class='loading'>Deleting the category...</p>");
68
+
69
+ $.ajax({
70
+ url: '/admin/categories/' + cat_id,
71
+ type: 'delete',
72
+ success: function(resp) {
73
+ if (resp.error) modal.autosize("<p class='note error'>" + resp.error + "</p>");
74
+ if (resp.redirect) window.location = resp.redirect;
75
+ }
76
+ });
77
+ }
78
+ </script>
79
+ <% end %>