spina-shop 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (263) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +28 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/spina_shop_manifest.js +0 -0
  6. data/app/assets/fonts/montserrat-bold.ttf +0 -0
  7. data/app/assets/fonts/montserrat-italic.ttf +0 -0
  8. data/app/assets/fonts/montserrat-medium.ttf +0 -0
  9. data/app/assets/fonts/montserrat-regular.ttf +0 -0
  10. data/app/assets/fonts/montserrat-semibold.ttf +0 -0
  11. data/app/assets/images/spina/shop/delete-big-confirm.png +0 -0
  12. data/app/assets/images/spina/shop/delete-big.png +0 -0
  13. data/app/assets/javascripts/spina/shop/admin/app.infinitescroll.js.coffee +23 -0
  14. data/app/assets/javascripts/spina/shop/admin/customers.coffee +27 -0
  15. data/app/assets/javascripts/spina/shop/admin/orders.coffee +18 -0
  16. data/app/assets/javascripts/spina/shop/admin/product_bundles.coffee +15 -0
  17. data/app/assets/javascripts/spina/shop/admin/product_categories.coffee +15 -0
  18. data/app/assets/javascripts/spina/shop/admin/products.coffee +88 -0
  19. data/app/assets/javascripts/spina/shop/admin/shop.js +10 -0
  20. data/app/assets/stylesheets/spina/shop/admin/_customers.sass +10 -0
  21. data/app/assets/stylesheets/spina/shop/admin/_forms.sass +191 -0
  22. data/app/assets/stylesheets/spina/shop/admin/_product_bundles.sass +12 -0
  23. data/app/assets/stylesheets/spina/shop/admin/_status_dots.sass +16 -0
  24. data/app/assets/stylesheets/spina/shop/admin/_tables.sass +2 -0
  25. data/app/assets/stylesheets/spina/shop/admin/_tooltips.sass +31 -0
  26. data/app/assets/stylesheets/spina/shop/admin/shop.css.sass +11 -0
  27. data/app/controllers/spina/shop/admin/admin_controller.rb +8 -0
  28. data/app/controllers/spina/shop/admin/customer_accounts_controller.rb +38 -0
  29. data/app/controllers/spina/shop/admin/customers_controller.rb +67 -0
  30. data/app/controllers/spina/shop/admin/discounts_controller.rb +65 -0
  31. data/app/controllers/spina/shop/admin/gift_cards_controller.rb +65 -0
  32. data/app/controllers/spina/shop/admin/invoices_controller.rb +12 -0
  33. data/app/controllers/spina/shop/admin/order_items_controller.rb +36 -0
  34. data/app/controllers/spina/shop/admin/orders/packing_slips_controller.rb +27 -0
  35. data/app/controllers/spina/shop/admin/orders/shipping_labels_controller.rb +19 -0
  36. data/app/controllers/spina/shop/admin/orders_controller.rb +123 -0
  37. data/app/controllers/spina/shop/admin/product_reviews_controller.rb +17 -0
  38. data/app/controllers/spina/shop/admin/products/product_bundles_controller.rb +62 -0
  39. data/app/controllers/spina/shop/admin/products/stock_forecasts_controller.rb +15 -0
  40. data/app/controllers/spina/shop/admin/products/stock_level_adjustments_controller.rb +33 -0
  41. data/app/controllers/spina/shop/admin/products_controller.rb +135 -0
  42. data/app/controllers/spina/shop/admin/reports_controller.rb +33 -0
  43. data/app/controllers/spina/shop/admin/settings/product_categories_controller.rb +45 -0
  44. data/app/controllers/spina/shop/admin/settings/product_category_properties_controller.rb +49 -0
  45. data/app/controllers/spina/shop/admin/settings/sales_categories_controller.rb +14 -0
  46. data/app/controllers/spina/shop/admin/settings/shop_controller.rb +9 -0
  47. data/app/controllers/spina/shop/admin/settings/tax_groups_controller.rb +47 -0
  48. data/app/controllers/spina/shop/admin/variants_controller.rb +8 -0
  49. data/app/jobs/spina/shop/in_stock_reminder_job.rb +17 -0
  50. data/app/jobs/spina/shop/invoice_report_job.rb +23 -0
  51. data/app/jobs/spina/shop/payments_report_job.rb +23 -0
  52. data/app/mailers/spina/shop/customer_account_mailer.rb +32 -0
  53. data/app/mailers/spina/shop/export_mailer.rb +22 -0
  54. data/app/mailers/spina/shop/in_stock_reminder_mailer.rb +22 -0
  55. data/app/mailers/spina/shop/order_mailer.rb +32 -0
  56. data/app/models/concerns/spina/shop/preferable.rb +27 -0
  57. data/app/models/concerns/spina/shop/tax_rateable.rb +11 -0
  58. data/app/models/spina/shop/address.rb +19 -0
  59. data/app/models/spina/shop/application_record.rb +5 -0
  60. data/app/models/spina/shop/bundled_product.rb +6 -0
  61. data/app/models/spina/shop/campaign.rb +4 -0
  62. data/app/models/spina/shop/collectable.rb +8 -0
  63. data/app/models/spina/shop/country.rb +5 -0
  64. data/app/models/spina/shop/customer.rb +60 -0
  65. data/app/models/spina/shop/customer_account.rb +15 -0
  66. data/app/models/spina/shop/customer_group.rb +9 -0
  67. data/app/models/spina/shop/delivery_option.rb +27 -0
  68. data/app/models/spina/shop/discount.rb +39 -0
  69. data/app/models/spina/shop/discount_action.rb +16 -0
  70. data/app/models/spina/shop/discount_rule.rb +17 -0
  71. data/app/models/spina/shop/discounts/actions/percent_off.rb +17 -0
  72. data/app/models/spina/shop/discounts/rules/all_orders.rb +13 -0
  73. data/app/models/spina/shop/discounts/rules/collection.rb +14 -0
  74. data/app/models/spina/shop/discounts/rules/order_total.rb +17 -0
  75. data/app/models/spina/shop/discounts_order.rb +6 -0
  76. data/app/models/spina/shop/favorite.rb +8 -0
  77. data/app/models/spina/shop/gift_card.rb +53 -0
  78. data/app/models/spina/shop/gift_cards_order.rb +6 -0
  79. data/app/models/spina/shop/in_stock_reminder.rb +7 -0
  80. data/app/models/spina/shop/invoice.rb +49 -0
  81. data/app/models/spina/shop/invoice_line.rb +13 -0
  82. data/app/models/spina/shop/number_sequence.rb +19 -0
  83. data/app/models/spina/shop/order.rb +222 -0
  84. data/app/models/spina/shop/order/billing.rb +85 -0
  85. data/app/models/spina/shop/order/state_machine_transitions.rb +106 -0
  86. data/app/models/spina/shop/order_attachment.rb +9 -0
  87. data/app/models/spina/shop/order_item.rb +101 -0
  88. data/app/models/spina/shop/order_transition.rb +5 -0
  89. data/app/models/spina/shop/product.rb +227 -0
  90. data/app/models/spina/shop/product_bundle.rb +51 -0
  91. data/app/models/spina/shop/product_bundle_part.rb +13 -0
  92. data/app/models/spina/shop/product_category.rb +18 -0
  93. data/app/models/spina/shop/product_category_property.rb +14 -0
  94. data/app/models/spina/shop/product_collection.rb +8 -0
  95. data/app/models/spina/shop/product_image.rb +18 -0
  96. data/app/models/spina/shop/product_item.rb +93 -0
  97. data/app/models/spina/shop/product_part.rb +13 -0
  98. data/app/models/spina/shop/product_relation.rb +6 -0
  99. data/app/models/spina/shop/product_review.rb +22 -0
  100. data/app/models/spina/shop/property_option.rb +16 -0
  101. data/app/models/spina/shop/sales_category.rb +43 -0
  102. data/app/models/spina/shop/sales_category_code.rb +20 -0
  103. data/app/models/spina/shop/shop_review.rb +19 -0
  104. data/app/models/spina/shop/stock_level_adjustment.rb +17 -0
  105. data/app/models/spina/shop/tax_group.rb +62 -0
  106. data/app/models/spina/shop/tax_rate.rb +20 -0
  107. data/app/models/spina/shop/zone.rb +11 -0
  108. data/app/pdfs/spina/shop/invoice_pdf.rb +114 -0
  109. data/app/pdfs/spina/shop/packing_slip_pdf.rb +74 -0
  110. data/app/presenters/spina/shop/invoice_presenter.rb +30 -0
  111. data/app/services/spina/shop/allocate_stock.rb +42 -0
  112. data/app/services/spina/shop/cache_order.rb +47 -0
  113. data/app/services/spina/shop/change_stock_level.rb +38 -0
  114. data/app/services/spina/shop/country_importer.rb +14 -0
  115. data/app/services/spina/shop/customer_generator.rb +32 -0
  116. data/app/services/spina/shop/deallocate_stock.rb +17 -0
  117. data/app/services/spina/shop/invoice_generator.rb +72 -0
  118. data/app/services/spina/shop/invoice_number_generator.rb +10 -0
  119. data/app/services/spina/shop/invoices_pdfs_exporter.rb +22 -0
  120. data/app/services/spina/shop/order_number_generator.rb +10 -0
  121. data/app/services/spina/shop/payments_excel_exporter.rb +41 -0
  122. data/app/services/spina/shop/store_address.rb +23 -0
  123. data/app/state_machines/spina/shop/order_state_machine.rb +116 -0
  124. data/app/uploaders/spina/shop/exports_uploader.rb +9 -0
  125. data/app/views/layouts/spina/shop/admin/settings/shop.html.haml +16 -0
  126. data/app/views/layouts/spina/shop/mail.html.erb +1 -0
  127. data/app/views/spina/admin/hooks/shop/_head.html.haml +2 -0
  128. data/app/views/spina/admin/hooks/shop/_primary_navigation.html.haml +31 -0
  129. data/app/views/spina/admin/hooks/shop/_settings_secondary_navigation.html.haml +2 -0
  130. data/app/views/spina/admin/page_partables/shop/product_bundle_parts/_form.html.haml +6 -0
  131. data/app/views/spina/admin/page_partables/shop/product_parts/_form.html.haml +6 -0
  132. data/app/views/spina/admin/structure_partables/shop/product_parts/_form.html.haml +3 -0
  133. data/app/views/spina/shop/admin/customer_accounts/_form.html.haml +32 -0
  134. data/app/views/spina/shop/admin/customer_accounts/edit.html.haml +1 -0
  135. data/app/views/spina/shop/admin/customers/_address_fields.html.haml +46 -0
  136. data/app/views/spina/shop/admin/customers/_customer.html.haml +11 -0
  137. data/app/views/spina/shop/admin/customers/_form.html.haml +67 -0
  138. data/app/views/spina/shop/admin/customers/edit.html.haml +1 -0
  139. data/app/views/spina/shop/admin/customers/index.html.haml +52 -0
  140. data/app/views/spina/shop/admin/customers/index.js.erb +4 -0
  141. data/app/views/spina/shop/admin/customers/new.html.haml +1 -0
  142. data/app/views/spina/shop/admin/customers/show.html.haml +121 -0
  143. data/app/views/spina/shop/admin/discounts/_form.html.haml +60 -0
  144. data/app/views/spina/shop/admin/discounts/edit.html.haml +1 -0
  145. data/app/views/spina/shop/admin/discounts/fields/_all_orders.html.haml +0 -0
  146. data/app/views/spina/shop/admin/discounts/fields/_discount_action_fields.html.haml +8 -0
  147. data/app/views/spina/shop/admin/discounts/fields/_discount_rule_fields.html.haml +0 -0
  148. data/app/views/spina/shop/admin/discounts/index.html.haml +36 -0
  149. data/app/views/spina/shop/admin/discounts/new.html.haml +1 -0
  150. data/app/views/spina/shop/admin/gift_cards/_form.html.haml +28 -0
  151. data/app/views/spina/shop/admin/gift_cards/_gift_card.html.haml +17 -0
  152. data/app/views/spina/shop/admin/gift_cards/index.html.haml +37 -0
  153. data/app/views/spina/shop/admin/gift_cards/index.js.erb +4 -0
  154. data/app/views/spina/shop/admin/gift_cards/new.html.haml +1 -0
  155. data/app/views/spina/shop/admin/gift_cards/show.html.haml +46 -0
  156. data/app/views/spina/shop/admin/order_items/_modal.html.haml +18 -0
  157. data/app/views/spina/shop/admin/order_items/new.js.erb +2 -0
  158. data/app/views/spina/shop/admin/orders/_form.html.haml +159 -0
  159. data/app/views/spina/shop/admin/orders/_order.html.haml +22 -0
  160. data/app/views/spina/shop/admin/orders/edit.html.haml +1 -0
  161. data/app/views/spina/shop/admin/orders/index.html.haml +78 -0
  162. data/app/views/spina/shop/admin/orders/index.js.erb +4 -0
  163. data/app/views/spina/shop/admin/orders/new.html.haml +1 -0
  164. data/app/views/spina/shop/admin/orders/show.html.haml +338 -0
  165. data/app/views/spina/shop/admin/product_reviews/_product_review.html.haml +22 -0
  166. data/app/views/spina/shop/admin/product_reviews/index.html.haml +29 -0
  167. data/app/views/spina/shop/admin/product_reviews/index.js.erb +4 -0
  168. data/app/views/spina/shop/admin/products/_form.html.haml +259 -0
  169. data/app/views/spina/shop/admin/products/_new_product_modal.html.haml +15 -0
  170. data/app/views/spina/shop/admin/products/_price_exception_fields.html.haml +11 -0
  171. data/app/views/spina/shop/admin/products/_product.html.haml +36 -0
  172. data/app/views/spina/shop/admin/products/edit.html.haml +1 -0
  173. data/app/views/spina/shop/admin/products/index.html.haml +73 -0
  174. data/app/views/spina/shop/admin/products/index.js.erb +4 -0
  175. data/app/views/spina/shop/admin/products/new.html.haml +1 -0
  176. data/app/views/spina/shop/admin/products/new_by_category.js.erb +1 -0
  177. data/app/views/spina/shop/admin/products/product_bundles/_bundled_products_fields.html.haml +11 -0
  178. data/app/views/spina/shop/admin/products/product_bundles/_form.html.haml +64 -0
  179. data/app/views/spina/shop/admin/products/product_bundles/edit.html.haml +1 -0
  180. data/app/views/spina/shop/admin/products/product_bundles/index.html.haml +42 -0
  181. data/app/views/spina/shop/admin/products/product_bundles/new.html.haml +1 -0
  182. data/app/views/spina/shop/admin/products/properties/_property_fields.html.haml +37 -0
  183. data/app/views/spina/shop/admin/products/stock_forecasts/_product.html.haml +49 -0
  184. data/app/views/spina/shop/admin/products/stock_forecasts/show.html.haml +47 -0
  185. data/app/views/spina/shop/admin/products/stock_forecasts/show.js.erb +4 -0
  186. data/app/views/spina/shop/admin/products/stock_level_adjustments/_form.html.haml +37 -0
  187. data/app/views/spina/shop/admin/products/stock_level_adjustments/_history.html.haml +30 -0
  188. data/app/views/spina/shop/admin/products/stock_level_adjustments/index.js.erb +1 -0
  189. data/app/views/spina/shop/admin/products/stock_level_adjustments/new.js.erb +1 -0
  190. data/app/views/spina/shop/admin/reports/index.html.haml +23 -0
  191. data/app/views/spina/shop/admin/settings/product_categories/_form.html.haml +18 -0
  192. data/app/views/spina/shop/admin/settings/product_categories/_product_category.html.haml +3 -0
  193. data/app/views/spina/shop/admin/settings/product_categories/_property_fields.html.haml +77 -0
  194. data/app/views/spina/shop/admin/settings/product_categories/edit.html.haml +1 -0
  195. data/app/views/spina/shop/admin/settings/product_categories/index.html.haml +3 -0
  196. data/app/views/spina/shop/admin/settings/product_categories/show.html.haml +24 -0
  197. data/app/views/spina/shop/admin/settings/product_category_properties/_property_options_fields.html.haml +11 -0
  198. data/app/views/spina/shop/admin/settings/product_category_properties/edit_options.html.haml +16 -0
  199. data/app/views/spina/shop/admin/settings/sales_categories/_sales_category.html.haml +17 -0
  200. data/app/views/spina/shop/admin/settings/sales_categories/index.html.haml +1 -0
  201. data/app/views/spina/shop/admin/settings/tax_groups/_form.html.haml +19 -0
  202. data/app/views/spina/shop/admin/settings/tax_groups/_tax_group.html.haml +21 -0
  203. data/app/views/spina/shop/admin/settings/tax_groups/index.html.haml +1 -0
  204. data/app/views/spina/shop/admin/settings/tax_groups/new.js.erb +1 -0
  205. data/app/views/spina/shop/admin/shared/_locale_switcher.html.haml +9 -0
  206. data/app/views/spina/shop/customer_account_mailer/forgot_password.html.erb +1 -0
  207. data/app/views/spina/shop/customer_account_mailer/forgot_password.txt.erb +1 -0
  208. data/app/views/spina/shop/export_mailer/exported.html.erb +2 -0
  209. data/app/views/spina/shop/in_stock_reminder_mailer/reminder.html.erb +1 -0
  210. data/app/views/spina/shop/in_stock_reminder_mailer/reminder.txt.erb +1 -0
  211. data/app/views/spina/shop/order_mailer/confirmation.html.erb +5 -0
  212. data/app/views/spina/shop/order_mailer/confirmation.txt.erb +5 -0
  213. data/app/views/spina/shop/order_mailer/shipped.html.erb +1 -0
  214. data/app/views/spina/shop/order_mailer/shipped.txt.erb +1 -0
  215. data/config/initializers/kaminari_monkey_patch.rb +15 -0
  216. data/config/locales/en.yml +214 -0
  217. data/config/locales/nl.yml +452 -0
  218. data/config/routes.rb +92 -0
  219. data/db/countries.txt +252 -0
  220. data/db/migrate/10_create_spina_shop_products_without_items.rb +23 -0
  221. data/db/migrate/1_create_spina_shop_tables.rb +518 -0
  222. data/db/migrate/20170701135207_create_spina_shop_bundled_products.rb +11 -0
  223. data/db/migrate/20170717125930_add_stock_enabled_to_spina_shop_products.rb +5 -0
  224. data/db/migrate/20170718084146_add_editable_sku_to_spina_shop_products.rb +5 -0
  225. data/db/migrate/20170718084626_add_deletable_to_spina_shop_products.rb +5 -0
  226. data/db/migrate/20170719082531_rename_column_order_picked_at_in_spina_shop_orders.rb +5 -0
  227. data/db/migrate/20170719112920_create_spina_shop_order_attachments.rb +15 -0
  228. data/db/migrate/20170719184125_add_price_exceptions_to_spina_shop_products.rb +5 -0
  229. data/db/migrate/20170720133304_add_vat_id_to_spina_shop_customers.rb +5 -0
  230. data/db/migrate/20170731082027_add_price_includes_tax_to_spina_shop_products.rb +5 -0
  231. data/db/migrate/20170731132620_add_reverse_charge_vat_to_spina_shop_tax_rates.rb +5 -0
  232. data/db/migrate/20170731150630_add_vat_id_to_spina_shop_invoices.rb +5 -0
  233. data/db/migrate/20170801093935_add_price_includes_tax_to_spina_shop_delivery_options.rb +5 -0
  234. data/db/migrate/20170814092924_add_business_to_spina_shop_orders.rb +6 -0
  235. data/db/migrate/20170815080839_rename_vat_reverse_charge_column_on_tax_rates.rb +5 -0
  236. data/db/migrate/20170815081018_add_business_to_spina_shop_tax_rates.rb +5 -0
  237. data/db/migrate/20170817075706_add_archived_to_spina_shop_products.rb +5 -0
  238. data/db/migrate/20170824175231_add_metadata_to_photos.rb +7 -0
  239. data/db/migrate/20170829085402_add_business_to_spina_shop_sales_category_codes.rb +5 -0
  240. data/db/migrate/20170911121034_add_trend_to_spina_shop_products.rb +5 -0
  241. data/db/migrate/20171106122225_add_editable_fields_to_spina_shop_product_category_properties.rb +6 -0
  242. data/db/migrate/20171106122537_create_property_options.rb +19 -0
  243. data/db/migrate/20171118110256_add_promotional_price_to_spina_shop_products.rb +6 -0
  244. data/db/migrate/2_create_spina_shop_tax_rates.rb +15 -0
  245. data/db/migrate/3_create_spina_shop_zones.rb +9 -0
  246. data/db/migrate/4_add_tax_rateable_to_spina_shop_tax_rates.rb +9 -0
  247. data/db/migrate/5_add_type_to_spina_shop_zones.rb +5 -0
  248. data/db/migrate/6_add_code_to_spina_shop_zones.rb +5 -0
  249. data/db/migrate/7_create_spina_shop_product_collections.rb +16 -0
  250. data/db/migrate/8_create_spina_shop_sales_category_codes.rb +13 -0
  251. data/db/migrate/9_create_spina_shop_customer_groups.rb +11 -0
  252. data/lib/generators/spina/shop/install_generator.rb +44 -0
  253. data/lib/spina/shop.rb +24 -0
  254. data/lib/spina/shop/admin_helpers.rb +49 -0
  255. data/lib/spina/shop/engine.rb +27 -0
  256. data/lib/spina/shop/errors/empty_order.rb +6 -0
  257. data/lib/spina/shop/errors/order_already_received.rb +6 -0
  258. data/lib/spina/shop/railtie.rb +31 -0
  259. data/lib/spina/shop/simple_linear_regression.rb +36 -0
  260. data/lib/spina/shop/version.rb +5 -0
  261. data/lib/spina/shop/view_helpers.rb +11 -0
  262. data/lib/tasks/spina/shop.rake +32 -0
  263. metadata +627 -0
@@ -0,0 +1,17 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ class ProductReviewsController < AdminController
4
+
5
+ def index
6
+ @product_reviews = ProductReview.sorted.page(params[:page]).per(25)
7
+ add_breadcrumb ProductReview.model_name.human(count: :other)
8
+ end
9
+
10
+ def delete_multiple
11
+ ProductReview.where(id: params[:product_review_ids]).destroy_all
12
+ redirect_to spina.shop_admin_product_reviews_path
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,62 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ module Products
4
+ class ProductBundlesController < AdminController
5
+ before_action :set_breadcrumbs
6
+
7
+ def show
8
+ @product_bundle = ProductBundle.find(params[:id])
9
+ redirect_to spina.edit_shop_admin_product_bundle_path(@product_bundle)
10
+ end
11
+
12
+ def new
13
+ @product_bundle = ProductBundle.new
14
+ add_breadcrumb t('spina.shop.product_bundles.new')
15
+ end
16
+
17
+ def create
18
+ @product_bundle = ProductBundle.new(product_bundle_params)
19
+ if @product_bundle.save
20
+ redirect_to spina.shop_admin_product_bundles_path
21
+ else
22
+ render :new
23
+ end
24
+ end
25
+
26
+ def edit
27
+ @product_bundle = ProductBundle.find(params[:id])
28
+ add_breadcrumb @product_bundle.name
29
+ end
30
+
31
+ def index
32
+ @product_bundles = ProductBundle.all
33
+ end
34
+
35
+ def update
36
+ @product_bundle = ProductBundle.find(params[:id])
37
+ if @product_bundle.update_attributes(product_bundle_params)
38
+ redirect_to spina.shop_admin_product_bundles_path
39
+ else
40
+ render :edit
41
+ end
42
+ end
43
+
44
+ def destroy
45
+ @product_bundle = ProductBundle.find(params[:id])
46
+ @product_bundle.destroy
47
+ redirect_to spina.shop_admin_product_bundles_path
48
+ end
49
+
50
+ private
51
+
52
+ def set_breadcrumbs
53
+ add_breadcrumb ProductBundle.model_name.human(count: 2), spina.shop_admin_product_bundles_path
54
+ end
55
+
56
+ def product_bundle_params
57
+ params.require(:product_bundle).permit(:name, :price, :tax_group_id, :sales_category_id, product_images_attributes: [:id, :position, :_destroy], product_images_files: [], bundled_products_attributes: [:id, :quantity, :product_id, :_destroy]).delocalize({price: :number})
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,15 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ module Products
4
+ class StockForecastsController < AdminController
5
+
6
+ def show
7
+ add_breadcrumb "Producten"
8
+ @products = Product.select('current_date + (floor((stock_level - 4) / trend) :: integer) as restock_date, (ceil(trend * 30) :: integer) as coming_30_days, *').where('trend > ?', 0).active.where(stock_enabled: true, archived: false).includes(:product_images, :translations).where('sales_count > ?', 5).order("#{params[:order] || 'restock_date'} #{params[:direction]}")
9
+ @products = @products.page(params[:page]).per(20)
10
+ end
11
+
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,33 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ module Products
4
+ class StockLevelAdjustmentsController < AdminController
5
+ before_action :set_product
6
+
7
+ def index
8
+ @stock_level_adjustments = @product.stock_level_adjustments
9
+ end
10
+
11
+ def new
12
+ @stock_level_adjustment = @product.stock_level_adjustments.build
13
+ end
14
+
15
+ def create
16
+ change = ChangeStockLevel.new(@product, stock_level_adjustment_params, send_in_stock_reminders: params[:send_in_stock_reminders])
17
+ change.save
18
+ redirect_to spina.shop_admin_product_path(@product)
19
+ end
20
+
21
+ private
22
+
23
+ def set_product
24
+ @product = Product.find(params[:product_id])
25
+ end
26
+
27
+ def stock_level_adjustment_params
28
+ params.require(:stock_level_adjustment).permit(:adjustment, :description, :expiration_month, :expiration_year).merge(actor: current_spina_user.name)
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,135 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ class ProductsController < AdminController
4
+ before_action :set_breadcrumbs
5
+ before_action :set_locale
6
+
7
+ def index
8
+ @q = Product.where(archived: false).filtered(filters).order(created_at: :desc).includes(:product_images).joins(:translations).where(spina_shop_product_translations: {locale: I18n.locale}).ransack(params[:q])
9
+ @products = @q.result.page(params[:page]).per(25)
10
+ @product_category_properties = Spina::Shop::ProductCategoryProperty.includes(property_options: :translations)
11
+
12
+ respond_to do |format|
13
+ format.html
14
+ format.js
15
+ format.json do
16
+ results = @products.includes(:product_images).map do |product|
17
+ { id: product.id,
18
+ name: product.name,
19
+ image_url: view_context.attachment_url(product.product_images.first, :file, :fit, 30, 30),
20
+ price: view_context.number_to_currency(product.price) }
21
+ end
22
+ render inline: {results: results, total_count: @q.result.count}.to_json
23
+ end
24
+ end
25
+ end
26
+
27
+ def archived
28
+ @q = Product.where(archived: true).filtered(filters).order(created_at: :desc).includes(:product_images).joins(:translations).where(spina_shop_product_translations: {locale: I18n.locale}).ransack(params[:q])
29
+ @products = @q.result.page(params[:page]).per(25)
30
+ @product_category_properties = Spina::Shop::ProductCategoryProperty.includes(property_options: :translations)
31
+ render :index
32
+ end
33
+
34
+ def show
35
+ @product = Product.find(params[:id])
36
+ redirect_to spina.edit_shop_admin_product_path(@product)
37
+ end
38
+
39
+ def new_by_category
40
+ @product_categories = ProductCategory.all
41
+ end
42
+
43
+ def new
44
+ @product = Product.new
45
+ add_breadcrumb t('spina.shop.products.new'), spina.new_shop_admin_product_path
46
+
47
+ @product_category = ProductCategory.where(id: params[:product_category_id]).first
48
+
49
+ # Always build at least one product item
50
+ @product.product_category = @product_category
51
+ end
52
+
53
+ def create
54
+ @product = Product.new(product_params)
55
+ if @product.save
56
+ redirect_to spina.edit_shop_admin_product_path(@product, params: {locale: @locale})
57
+ else
58
+ render :new
59
+ end
60
+ end
61
+
62
+ def edit
63
+ @product = Product.find(params[:id])
64
+ add_breadcrumb @product.name
65
+
66
+ @product_category = @product.product_category
67
+ end
68
+
69
+ def update
70
+ @product = Product.find(params[:id])
71
+ if I18n.with_locale(@locale) { @product.update_attributes(product_params) }
72
+ redirect_to spina.edit_shop_admin_product_path(@product, params: {locale: @locale})
73
+ else
74
+ render :edit
75
+ end
76
+ end
77
+
78
+ def destroy
79
+ @product = Product.find(params[:id])
80
+ @product.destroy
81
+ redirect_to spina.shop_admin_products_path
82
+ rescue ActiveRecord::DeleteRestrictionError
83
+ flash[:alert] = t('spina.shop.products.delete_restriction_error', name: @product.name)
84
+ flash[:alert_small] = t('spina.shop.products.delete_restriction_error_explanation')
85
+ redirect_to spina.shop_admin_product_path(@product)
86
+ end
87
+
88
+ def archive
89
+ @product = Product.find(params[:id])
90
+ @product.update_attributes(archived: true)
91
+ redirect_to spina.shop_admin_product_path(@product)
92
+ end
93
+
94
+ def unarchive
95
+ @product = Product.find(params[:id])
96
+ @product.update_attributes(archived: false)
97
+ redirect_to spina.shop_admin_product_path(@product)
98
+ end
99
+
100
+ private
101
+
102
+ def filters
103
+ filter_params.to_h.map do |property, value|
104
+ value.present? ? {field_type: ProductCategoryProperty.find_by(name: property).field_type, property: property, value: value} : {}
105
+ end
106
+ end
107
+
108
+ def filter_params
109
+ params.require(:filters).permit! if params[:filters]
110
+ end
111
+
112
+ def product_params
113
+ I18n.with_locale I18n.default_locale do
114
+ product_params = params.require(:product).permit!.merge(locale: @locale).delocalize(base_price: :number, promotional_price: :number, cost_price: :number, weight: :number)
115
+ if product_params[:price_exceptions].present?
116
+ product_params[:price_exceptions].try(:[], :customer_groups).try(:each) do |price_exception|
117
+ price_exception["price"] = Delocalize::Parsers::Number.new.parse(price_exception["price"])
118
+ end
119
+ else
120
+ product_params[:price_exceptions] = "{}"
121
+ end
122
+ product_params
123
+ end
124
+ end
125
+
126
+ def set_breadcrumbs
127
+ add_breadcrumb Product.model_name.human(count: 2), spina.shop_admin_products_path
128
+ end
129
+
130
+ def set_locale
131
+ @locale = params[:locale] || I18n.default_locale
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,33 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ class ReportsController < AdminController
4
+ before_action :set_breadcrumbs
5
+
6
+ def index
7
+ end
8
+
9
+ def create
10
+ start_date = Date.parse(params[:start_date])
11
+ end_date = Date.parse(params[:end_date])
12
+ case params[:report_type]
13
+ when "invoices"
14
+ invoice_ids = Invoice.where(date: start_date..end_date).ids
15
+ InvoiceReportJob.perform_later(invoice_ids, params[:email])
16
+ when "payments"
17
+ order_ids = Order.paid.where(paid_at: start_date..end_date).ids
18
+ PaymentsReportJob.perform_later(order_ids, params[:email])
19
+ end
20
+
21
+ flash[:success] = t('spina.shop.reports.start_exporting_html')
22
+ redirect_to spina.shop_admin_reports_path
23
+ end
24
+
25
+ private
26
+
27
+ def set_breadcrumbs
28
+ add_breadcrumb t('spina.shop.reports.title'), spina.shop_admin_reports_path
29
+ end
30
+
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,45 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ module Settings
4
+ class ProductCategoriesController < ShopController
5
+ layout 'spina/admin/admin', except: [:index]
6
+
7
+ before_action :set_breadcrumbs, except: [:index]
8
+
9
+ def index
10
+ @product_categories = ProductCategory.all
11
+ end
12
+
13
+ def show
14
+ @product_category = ProductCategory.find(params[:id])
15
+ add_breadcrumb @product_category.name
16
+ end
17
+
18
+ def new
19
+ end
20
+
21
+ def edit
22
+ @product_category = ProductCategory.find(params[:id])
23
+ add_breadcrumb @product_category.name, [:admin, :settings, @product_category]
24
+ add_breadcrumb t('spina.edit')
25
+ end
26
+
27
+ def create
28
+ end
29
+
30
+ def update
31
+ end
32
+
33
+ def destroy
34
+ end
35
+
36
+ private
37
+
38
+ def set_breadcrumbs
39
+ add_breadcrumb ProductCategory.model_name.human(count: 2), spina.shop_admin_settings_product_categories_path
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,49 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ module Settings
4
+ class ProductCategoryPropertiesController < ShopController
5
+ layout 'spina/admin/admin'
6
+
7
+ before_action :set_product_category
8
+ before_action :set_breadcrumbs, except: [:index]
9
+ before_action :set_locale
10
+
11
+ def edit
12
+ @product_category_property = @product_category.properties.find(params[:id])
13
+ add_breadcrumb @product_category_property.label
14
+ end
15
+
16
+ def edit_options
17
+ @product_category_property = @product_category.properties.find(params[:id])
18
+ add_breadcrumb @product_category_property.label
19
+ end
20
+
21
+ def update
22
+ @product_category_property = @product_category.properties.find(params[:id])
23
+ @product_category_property.update_attributes(product_category_property_params)
24
+ redirect_to spina.shop_admin_settings_product_category_path(@product_category)
25
+ end
26
+
27
+ private
28
+
29
+ def set_locale
30
+ @locale = params[:locale] || I18n.default_locale
31
+ end
32
+
33
+ def set_product_category
34
+ @product_category = ProductCategory.find(params[:product_category_id])
35
+ end
36
+
37
+ def set_breadcrumbs
38
+ add_breadcrumb ProductCategory.model_name.human(count: 2), spina.shop_admin_settings_product_categories_path
39
+ add_breadcrumb @product_category.name, spina.shop_admin_settings_product_category_path(@product_category)
40
+ end
41
+
42
+ def product_category_property_params
43
+ params.require(:product_category_property).permit(property_options_attributes: [:id, :name, :label, :_destroy])
44
+ end
45
+
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,14 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ module Settings
4
+ class SalesCategoriesController < ShopController
5
+ layout 'spina/admin/admin', except: [:index]
6
+
7
+ def index
8
+ @sales_categories = SalesCategory.all
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ module Settings
4
+ class ShopController < AdminController
5
+ before_action -> { add_breadcrumb t('spina.shop.settings') }, only: [:index]
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,47 @@
1
+ module Spina::Shop
2
+ module Admin
3
+ module Settings
4
+ class TaxGroupsController < ShopController
5
+ layout 'spina/admin/admin', except: [:index]
6
+
7
+ def new
8
+ @tax_group = TaxGroup.new
9
+ @tax_group.tax_rates.build
10
+ end
11
+
12
+ def create
13
+ @tax_group = TaxGroup.new(tax_group_params)
14
+ unless @tax_group.save
15
+ flash[:alert] = "Failed to save"
16
+ end
17
+ redirect_to spina.shop_admin_settings_tax_groups_path
18
+ end
19
+
20
+ def index
21
+ @tax_groups = TaxGroup.all
22
+ end
23
+
24
+ def edit
25
+ @tax_group = TaxGroup.find(params[:id])
26
+ add_breadcrumb @tax_group.name
27
+ end
28
+
29
+ def update
30
+ @tax_group = TaxGroup.find(params[:id])
31
+ if @tax_group.update_attributes(tax_group_params)
32
+ redirect_to spina.shop_admin_settings_tax_groups_path
33
+ else
34
+ render :edit
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def tax_group_params
41
+ params.require(:tax_group).permit(:name, tax_rates_attributes: [:rate, :code])
42
+ end
43
+
44
+ end
45
+ end
46
+ end
47
+ end