opensteam 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +78 -0
- data/LICENSE +345 -0
- data/{README.txt → README.rdoc} +20 -17
- data/Rakefile +40 -0
- data/generators/opensteam/opensteam_generator.rb +95 -194
- data/generators/opensteam/templates/{controllers/administration → app/controllers/admin}/inventories_controller.rb +4 -4
- data/generators/opensteam/templates/app/controllers/admin/invoices_controller.rb +106 -0
- data/generators/opensteam/templates/app/controllers/admin/orders_controller.rb +113 -0
- data/generators/opensteam/templates/app/controllers/admin/search_controller.rb +17 -0
- data/generators/opensteam/templates/app/controllers/admin/shipments_controller.rb +106 -0
- data/generators/opensteam/templates/app/controllers/admin/users_controller.rb +99 -0
- data/generators/opensteam/templates/app/controllers/admin_controller.rb +40 -0
- data/generators/opensteam/templates/app/controllers/cart_controller.rb +94 -0
- data/generators/opensteam/templates/app/controllers/checkout_controller.rb +139 -0
- data/generators/opensteam/templates/app/controllers/profile/infos_controller.rb +52 -0
- data/generators/opensteam/templates/app/controllers/profile/orders_controller.rb +105 -0
- data/generators/opensteam/templates/app/controllers/profile_controller.rb +37 -0
- data/generators/opensteam/templates/app/controllers/searches_controller.rb +23 -0
- data/generators/opensteam/templates/app/controllers/user_sessions_controller.rb +38 -0
- data/generators/opensteam/templates/app/controllers/users_controller.rb +40 -0
- data/generators/opensteam/templates/{controllers → app/controllers}/webshop_controller.rb +35 -13
- data/generators/opensteam/templates/app/helpers/admin_helper.rb +40 -0
- data/generators/opensteam/templates/app/helpers/users_helper.rb +53 -0
- data/generators/opensteam/templates/app/helpers/webshop_helper.rb +91 -0
- data/generators/opensteam/templates/app/models/search.rb +36 -0
- data/generators/opensteam/templates/{views/administration → app/views/admin}/_address.html.erb +0 -0
- data/generators/opensteam/templates/app/views/admin/_nav.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/catalog.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/index.html.erb +21 -0
- data/generators/opensteam/templates/{views/administration → app/views/admin}/inventories/edit.html.erb +10 -9
- data/generators/opensteam/templates/{views/administration → app/views/admin}/inventories/index.html.erb +3 -3
- data/generators/opensteam/templates/{views/administration → app/views/admin}/inventories/new.html.erb +3 -3
- data/generators/opensteam/templates/app/views/admin/inventories/show.html.erb +46 -0
- data/generators/opensteam/templates/app/views/admin/invoices/_invoice.html.erb +12 -0
- data/generators/opensteam/templates/app/views/admin/invoices/_invoices.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/invoices/index.html.erb +6 -0
- data/generators/opensteam/templates/app/views/admin/invoices/new.html.erb +54 -0
- data/generators/opensteam/templates/app/views/admin/invoices/show.html.erb +55 -0
- data/generators/opensteam/templates/app/views/admin/orders/_event.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/orders/_order.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/orders/_order_item.html.erb +10 -0
- data/generators/opensteam/templates/app/views/admin/orders/_orders.html.erb +19 -0
- data/generators/opensteam/templates/app/views/admin/orders/index.html.erb +14 -0
- data/generators/opensteam/templates/app/views/admin/orders/livesearch.rjs +6 -0
- data/generators/opensteam/templates/app/views/admin/orders/show.html.erb +58 -0
- data/generators/opensteam/templates/app/views/admin/products.html.erb +8 -0
- data/generators/opensteam/templates/app/views/admin/properties.html.erb +7 -0
- data/generators/opensteam/templates/app/views/admin/sales.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/shipments/_shipment.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/shipments/_shipments.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/shipments/index.html.erb +6 -0
- data/generators/opensteam/templates/app/views/admin/shipments/new.html.erb +51 -0
- data/generators/opensteam/templates/app/views/admin/shipments/show.html.erb +55 -0
- data/generators/opensteam/templates/app/views/admin/users/_admins.html.erb +26 -0
- data/generators/opensteam/templates/app/views/admin/users/_admins_header.html.erb +10 -0
- data/generators/opensteam/templates/app/views/admin/users/_customer.html.erb +32 -0
- data/generators/opensteam/templates/app/views/admin/users/_customers.html.erb +29 -0
- data/generators/opensteam/templates/app/views/admin/users/_customers_header.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/users/_user_fields.html.erb +9 -0
- data/generators/opensteam/templates/app/views/admin/users/_users.html.erb +29 -0
- data/generators/opensteam/templates/app/views/admin/users/_users_header.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/users/edit.html.erb +6 -0
- data/generators/opensteam/templates/app/views/admin/users/index.html.erb +7 -0
- data/generators/opensteam/templates/app/views/admin/users/new.html.erb +6 -0
- data/generators/opensteam/templates/app/views/admin/users/show.html.erb +34 -0
- data/generators/opensteam/templates/app/views/admin/users.html.erb +4 -0
- data/generators/opensteam/templates/{views → app/views}/administration_mailer/order_admin.erb +0 -0
- data/generators/opensteam/templates/{views → app/views}/administration_mailer/order_customer.erb +0 -0
- data/generators/opensteam/templates/app/views/cart/_cart.html.erb +8 -0
- data/generators/opensteam/templates/{views/webshop → app/views/cart}/_cart_content.html.erb +7 -10
- data/generators/opensteam/templates/app/views/cart/index.html.erb +5 -0
- data/generators/opensteam/templates/app/views/cart/update.rjs +1 -0
- data/generators/opensteam/templates/app/views/checkout/intro.html.erb +18 -0
- data/generators/opensteam/templates/{views → app/views}/checkout/outro.html.erb +0 -1
- data/generators/opensteam/templates/{views → app/views}/checkout/payment.html.erb +0 -0
- data/generators/opensteam/templates/app/views/checkout/shipping.html.erb +45 -0
- data/generators/opensteam/templates/app/views/checkout/show_cart.html.erb +13 -0
- data/generators/opensteam/templates/{views → app/views}/checkout/update_cart_content.rjs +0 -0
- data/generators/opensteam/templates/{views → app/views}/common/_cart.html.erb +2 -2
- data/generators/opensteam/templates/{views → app/views}/common/_cart_content.html.erb +1 -1
- data/generators/opensteam/templates/app/views/common/_footer.html.erb +1 -0
- data/generators/opensteam/templates/app/views/common/_header.html.erb +4 -0
- data/generators/opensteam/templates/app/views/common/_header_flash.html.erb +3 -0
- data/generators/opensteam/templates/app/views/common/_signup_fields.html.erb +16 -0
- data/generators/opensteam/templates/app/views/common/_top_links.html.erb +10 -0
- data/generators/opensteam/templates/app/views/layouts/admin.html.erb +45 -0
- data/generators/opensteam/templates/app/views/layouts/profile.html.erb +45 -0
- data/generators/opensteam/templates/app/views/layouts/webshop.html.erb +51 -0
- data/generators/opensteam/templates/app/views/profile/_customer_sidebar.html.erb +12 -0
- data/generators/opensteam/templates/app/views/profile/index.html.erb +11 -0
- data/generators/opensteam/templates/app/views/profile/infos/_customer.html.erb +5 -0
- data/generators/opensteam/templates/app/views/profile/infos/edit.html.erb +25 -0
- data/generators/opensteam/templates/app/views/profile/infos/edit_password.html.erb +26 -0
- data/generators/opensteam/templates/app/views/profile/orders/_order.html.erb +11 -0
- data/generators/opensteam/templates/app/views/profile/orders/_order_item.html.erb +10 -0
- data/generators/opensteam/templates/app/views/profile/orders/_orders.html.erb +19 -0
- data/generators/opensteam/templates/app/views/profile/orders/index.html.erb +14 -0
- data/generators/opensteam/templates/app/views/profile/orders/show.html.erb +48 -0
- data/generators/opensteam/templates/app/views/searches/_search_bar.html.erb +5 -0
- data/generators/opensteam/templates/app/views/searches/new.html.erb +23 -0
- data/generators/opensteam/templates/app/views/searches/show.html.erb +1 -0
- data/generators/opensteam/templates/app/views/user_sessions/new.html.erb +14 -0
- data/generators/opensteam/templates/app/views/users/_user_bar.html.erb +5 -0
- data/generators/opensteam/templates/app/views/users/index.html.erb +27 -0
- data/generators/opensteam/templates/app/views/users/new.html.erb +7 -0
- data/generators/opensteam/templates/app/views/users/show.html.erb +5 -0
- data/generators/opensteam/templates/{views → app/views}/webshop/_inventory_content.html.erb +0 -0
- data/generators/opensteam/templates/app/views/webshop/_nav.html.erb +6 -0
- data/generators/opensteam/templates/{views → app/views}/webshop/add_inventory_to_cart.rjs +0 -0
- data/generators/opensteam/templates/{views → app/views}/webshop/add_to_cart_with_parameters.rjs +0 -0
- data/generators/opensteam/templates/{views → app/views}/webshop/del_item.rjs +0 -0
- data/generators/opensteam/templates/app/views/webshop/index.html.erb +11 -0
- data/generators/opensteam/templates/{views → app/views}/webshop/inventory.rjs +0 -0
- data/generators/opensteam/templates/{views → app/views}/webshop/show.html.erb +15 -15
- data/generators/opensteam/templates/config/initializers/init_states.rb +68 -0
- data/generators/opensteam/templates/{init → config/initializers}/opensteam.rb +6 -0
- data/generators/opensteam/templates/config/initializers/opensteam_model_tables.rb +57 -0
- data/generators/opensteam/templates/db/migrate/20080609095714_create_profiles.rb +14 -0
- data/generators/opensteam/templates/{migrations/create_sessions.rb → db/migrate/20080609095720_create_sessions.rb} +0 -0
- data/generators/opensteam/templates/db/migrate/20080609095721_create_users.rb +29 -0
- data/generators/opensteam/templates/{migrations/create_addresses.rb → db/migrate/20080609095723_create_addresses.rb} +0 -0
- data/generators/opensteam/templates/{migrations/create_customers.rb → db/migrate/20080609095724_create_customers.rb} +0 -0
- data/generators/opensteam/templates/db/migrate/20080609095725_create_dummy_users.rb +21 -0
- data/generators/opensteam/templates/{migrations/create_inventories.rb → db/migrate/20080609095726_create_inventories.rb} +0 -0
- data/generators/opensteam/templates/{migrations/create_inventories_properties.rb → db/migrate/20080609095727_create_inventories_properties.rb} +0 -0
- data/generators/opensteam/templates/{migrations/create_order_items.rb → db/migrate/20080609095728_create_order_items.rb} +5 -0
- data/generators/opensteam/templates/db/migrate/20080609095729_create_orders.rb +32 -0
- data/generators/opensteam/templates/{migrations/create_payment_types.rb → db/migrate/20080609095730_create_payment_types.rb} +0 -0
- data/generators/opensteam/templates/{migrations/create_properties.rb → db/migrate/20080609095731_create_properties.rb} +0 -0
- data/generators/opensteam/templates/db/migrate/20080623075613_create_states.rb +13 -0
- data/generators/opensteam/templates/db/migrate/20080624132807_create_searches.rb +20 -0
- data/generators/opensteam/templates/db/migrate/20080630114155_create_state_histories.rb +14 -0
- data/generators/opensteam/templates/db/migrate/20080714131513_create_invoices.rb +20 -0
- data/generators/opensteam/templates/db/migrate/20080714131650_create_shipments.rb +19 -0
- data/generators/opensteam/templates/lib/authenticated_system.rb +201 -0
- data/generators/opensteam/templates/lib/authentication/by_cookie_token.rb +90 -0
- data/generators/opensteam/templates/lib/authentication/by_password.rb +68 -0
- data/generators/opensteam/templates/lib/authentication.rb +46 -0
- data/generators/opensteam/templates/lib/states/invoice/finished.rb +6 -0
- data/generators/opensteam/templates/lib/states/invoice/payment_received.rb +8 -0
- data/generators/opensteam/templates/lib/states/invoice/pending.rb +6 -0
- data/generators/opensteam/templates/lib/states/invoice/waiting_for_payment.rb +5 -0
- data/generators/opensteam/templates/lib/states/order/finished.rb +6 -0
- data/generators/opensteam/templates/lib/states/order/pending.rb +19 -0
- data/generators/opensteam/templates/lib/states/order/processing.rb +11 -0
- data/generators/opensteam/templates/lib/states/shipment/finished.rb +6 -0
- data/generators/opensteam/templates/lib/states/shipment/pending.rb +5 -0
- data/generators/opensteam/templates/lib/tasks/opensteam.rake +114 -0
- data/generators/opensteam/templates/public/images/athmo_background.jpg +0 -0
- data/generators/opensteam/templates/public/images/bg.jpg +0 -0
- data/generators/opensteam/templates/public/images/cart_big.gif +0 -0
- data/generators/opensteam/templates/public/images/cross.png +0 -0
- data/generators/opensteam/templates/public/images/enter.gif +0 -0
- data/generators/opensteam/templates/public/images/menu_background.jpg +0 -0
- data/generators/opensteam/templates/public/images/opensteam_background.jpg +0 -0
- data/generators/opensteam/templates/public/images/opensteam_logo1.jpg +0 -0
- data/generators/opensteam/templates/public/images/opensteam_petstore_logo1.jpg +0 -0
- data/generators/opensteam/templates/public/images/opensteam_store_logo.jpg +0 -0
- data/generators/opensteam/templates/public/images/os_logo.gif +0 -0
- data/generators/opensteam/templates/public/images/slogan.png +0 -0
- data/generators/opensteam/templates/public/images/tick.png +0 -0
- data/generators/opensteam/templates/public/images/zoom.png +0 -0
- data/generators/opensteam/templates/public/index.html +19 -36
- data/generators/opensteam/templates/public/javascripts/opensteam.js +30 -0
- data/generators/opensteam/templates/public/stylesheets/opensteam_newdesign.css +188 -0
- data/generators/opensteam/templates/public/stylesheets/opensteam_white.css +168 -0
- data/generators/opensteam/templates/public/stylesheets/webshop.css +0 -1
- data/generators/opensteam/templates/tasks/opensteam.rake +1 -1
- data/generators/opensteam/templates/{fixtures → test/fixtures}/inventories.yml +0 -0
- data/generators/opensteam/templates/{fixtures → test/fixtures}/inventories_properties.yml +0 -0
- data/generators/opensteam/templates/{fixtures → test/fixtures}/product_animals.yml +0 -0
- data/generators/opensteam/templates/{fixtures → test/fixtures}/product_dog_foods.yml +0 -0
- data/generators/opensteam/templates/{fixtures → test/fixtures}/properties.yml +0 -0
- data/generators/opensteam_product/opensteam_product_generator.rb +25 -9
- data/generators/opensteam_product/templates/controllers/product_controller.rb +5 -4
- data/generators/opensteam_product/templates/migration.rb +2 -1
- data/generators/opensteam_product/templates/models/product.rb +1 -0
- data/generators/opensteam_product/templates/views/{administration → admin}/_attributes.html.erb +1 -1
- data/generators/opensteam_product/templates/views/{administration → admin}/_get_products.html.erb +0 -0
- data/generators/opensteam_product/templates/views/{administration → admin}/_inventories.html.erb +2 -2
- data/generators/opensteam_product/templates/views/admin/edit.html.erb +13 -0
- data/generators/opensteam_product/templates/views/{administration → admin}/index.html.erb +5 -5
- data/generators/opensteam_product/templates/views/admin/new.html.erb +16 -0
- data/generators/opensteam_product/templates/views/{administration → admin}/show.html.erb +2 -2
- data/generators/opensteam_property/opensteam_property_generator.rb +8 -8
- data/generators/opensteam_property/templates/controllers/property_controller.rb +6 -4
- data/generators/opensteam_property/templates/migration.rb +2 -1
- data/generators/opensteam_property/templates/models/property.rb +1 -0
- data/generators/opensteam_property/templates/views/{administration → admin}/edit.html.erb +3 -3
- data/generators/opensteam_property/templates/views/admin/index.html.erb +24 -0
- data/generators/opensteam_property/templates/views/{administration → admin}/new.html.erb +2 -2
- data/generators/opensteam_property/templates/views/admin/show.html.erb +10 -0
- data/lib/opensteam/base.rb +16 -0
- data/lib/opensteam/cart_base.rb +227 -0
- data/lib/opensteam/checkout.rb +30 -3
- data/lib/opensteam/config.rb +37 -0
- data/lib/opensteam/extension_base.rb +76 -0
- data/lib/opensteam/finder.rb +36 -5
- data/lib/opensteam/helper/configurable_table.rb +228 -0
- data/lib/opensteam/history.rb +56 -0
- data/lib/opensteam/initializer.rb +127 -0
- data/lib/opensteam/inventory_base.rb +24 -1
- data/lib/opensteam/invoice_base.rb +61 -0
- data/lib/opensteam/order_base.rb +105 -14
- data/lib/opensteam/product_base.rb +31 -3
- data/lib/opensteam/property_base.rb +16 -0
- data/lib/opensteam/shipment_base.rb +60 -0
- data/lib/opensteam/shopping_cart.rb +32 -14
- data/lib/opensteam/state_logic.rb +218 -0
- data/lib/opensteam/state_machine.rb +216 -0
- data/lib/opensteam/user_base.rb +115 -131
- data/lib/opensteam/version.rb +17 -1
- data/lib/opensteam.rb +30 -35
- metadata +245 -146
- data/History.txt +0 -0
- data/License.txt +0 -4
- data/Manifest.txt +0 -131
- data/Manifest.txt.bak +0 -132
- data/generators/opensteam/templates/controllers/administration/customers_controller.rb +0 -23
- data/generators/opensteam/templates/controllers/administration/orders_controller.rb +0 -61
- data/generators/opensteam/templates/controllers/administration_controller.rb +0 -80
- data/generators/opensteam/templates/controllers/checkout_controller.rb +0 -142
- data/generators/opensteam/templates/helpers/webshop_helper.rb +0 -29
- data/generators/opensteam/templates/migrations/create_dummy_users.rb +0 -16
- data/generators/opensteam/templates/migrations/create_orders.rb +0 -18
- data/generators/opensteam/templates/migrations/create_users.rb +0 -19
- data/generators/opensteam/templates/models/administration_mailer.rb +0 -18
- data/generators/opensteam/templates/models/inventories_property.rb +0 -10
- data/generators/opensteam/templates/models/inventory.rb +0 -57
- data/generators/opensteam/templates/public/images/rails.png +0 -0
- data/generators/opensteam/templates/views/administration/_nav.html.erb +0 -11
- data/generators/opensteam/templates/views/administration/_update_tree.html.erb +0 -18
- data/generators/opensteam/templates/views/administration/admin_info.html.erb +0 -12
- data/generators/opensteam/templates/views/administration/customers/index.html.erb +0 -27
- data/generators/opensteam/templates/views/administration/customers/show.html.erb +0 -27
- data/generators/opensteam/templates/views/administration/customers.html.erb +0 -44
- data/generators/opensteam/templates/views/administration/index.html.erb +0 -9
- data/generators/opensteam/templates/views/administration/inventories/show.html.erb +0 -45
- data/generators/opensteam/templates/views/administration/login.html.erb +0 -16
- data/generators/opensteam/templates/views/administration/order.html.erb +0 -22
- data/generators/opensteam/templates/views/administration/orders/_order_item.html.erb +0 -22
- data/generators/opensteam/templates/views/administration/orders/index.html.erb +0 -32
- data/generators/opensteam/templates/views/administration/orders/show.html.erb +0 -25
- data/generators/opensteam/templates/views/administration/orders.html.erb +0 -32
- data/generators/opensteam/templates/views/administration/products.html.erb +0 -7
- data/generators/opensteam/templates/views/administration/properties.html.erb +0 -7
- data/generators/opensteam/templates/views/administration/show_order_item.html.erb +0 -5
- data/generators/opensteam/templates/views/administration/signup.html.erb +0 -65
- data/generators/opensteam/templates/views/administration/tree.html.erb +0 -15
- data/generators/opensteam/templates/views/administration/update_products.html.erb +0 -5
- data/generators/opensteam/templates/views/administration/update_properties.html.erb +0 -5
- data/generators/opensteam/templates/views/administration/update_tree.rjs +0 -3
- data/generators/opensteam/templates/views/checkout/intro.html.erb +0 -5
- data/generators/opensteam/templates/views/checkout/shipping.html.erb +0 -39
- data/generators/opensteam/templates/views/checkout/show_cart.html.erb +0 -13
- data/generators/opensteam/templates/views/common/_header.html.erb +0 -15
- data/generators/opensteam/templates/views/layouts/administration.html.erb +0 -29
- data/generators/opensteam/templates/views/layouts/webshop.html.erb +0 -36
- data/generators/opensteam/templates/views/webshop/_cart.html.erb +0 -11
- data/generators/opensteam/templates/views/webshop/_header.html.erb +0 -15
- data/generators/opensteam/templates/views/webshop/index.html.erb +0 -12
- data/generators/opensteam_product/templates/views/administration/edit.html.erb +0 -13
- data/generators/opensteam_product/templates/views/administration/new.html.erb +0 -16
- data/generators/opensteam_property/templates/views/administration/index.html.erb +0 -24
- data/generators/opensteam_property/templates/views/administration/show.html.erb +0 -10
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
module Opensteam
|
|
2
|
+
|
|
3
|
+
module Helper
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
# ConfigurableTable
|
|
7
|
+
#
|
|
8
|
+
# Module to Configure, Search and Sort a table, depending on a model-collection
|
|
9
|
+
#
|
|
10
|
+
module ConfigurableTableController
|
|
11
|
+
|
|
12
|
+
def self.included(base)
|
|
13
|
+
# base.extend( ClassMethods )
|
|
14
|
+
|
|
15
|
+
base.class_eval do
|
|
16
|
+
include InstanceMethods
|
|
17
|
+
before_filter :set_sort_column
|
|
18
|
+
private :sort_model, :set_sort_column
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
module InstanceMethods
|
|
24
|
+
|
|
25
|
+
# before_filter:
|
|
26
|
+
# if params[:sort] is set, it gets the current sort-column from the
|
|
27
|
+
# configured_table class variable
|
|
28
|
+
#
|
|
29
|
+
def set_sort_column
|
|
30
|
+
if params[:sort]
|
|
31
|
+
model = params[:model].demodulize.classify.constantize rescue nil
|
|
32
|
+
@sort_column = model.configured_table.get_column( params[:sort] ) || model.configured_table.default_sort
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def sort
|
|
37
|
+
if params[:sort]
|
|
38
|
+
self.class.to_s =~ /^(.+)Controller/
|
|
39
|
+
model = $1.demodulize.classify.constantize rescue nil
|
|
40
|
+
@result = sort_model( model, @sort_column )
|
|
41
|
+
end
|
|
42
|
+
render :action => :sort
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# sort the current model by column
|
|
47
|
+
# finds all entries for current model (including all associations)
|
|
48
|
+
# sort entries either by "ORDER" SQL or by a ruby sort-block (depending on
|
|
49
|
+
# the configuration or wether the column is an association)
|
|
50
|
+
#
|
|
51
|
+
def sort_model( model, column, conditions = nil, includes = nil )
|
|
52
|
+
finder_args = {}
|
|
53
|
+
finder_args[:conditions] = conditions if conditions
|
|
54
|
+
finder_args[:include] = includes if includes
|
|
55
|
+
|
|
56
|
+
if column.order_ruby?
|
|
57
|
+
result = model.find( :all, finder_args )
|
|
58
|
+
result.sort!(&column.order)
|
|
59
|
+
else
|
|
60
|
+
finder_args[:order] = column.order
|
|
61
|
+
result = model.find(:all, finder_args )
|
|
62
|
+
end
|
|
63
|
+
toggle_sorted( model.to_s.demodulize )
|
|
64
|
+
result.reverse! if sorted?( model.to_s.demodulize )
|
|
65
|
+
result
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# if model is currently sorted ascending
|
|
69
|
+
def sorted?(model)
|
|
70
|
+
session["#{model}_sorted".to_sym] ? true : false ;
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
# toggle the sorted-sesssion variable for the given model
|
|
75
|
+
def toggle_sorted(model)
|
|
76
|
+
session["#{model}_sorted".to_sym] = session["#{model}_sorted".to_sym] ? false : true
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
module ConfigurableTable
|
|
85
|
+
|
|
86
|
+
def self.included(base)
|
|
87
|
+
base.extend(ClassMethods)
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
module ClassMethods
|
|
93
|
+
# configure a table
|
|
94
|
+
# takes a block, like:
|
|
95
|
+
# configure_table :order do
|
|
96
|
+
# column :id, :name => "ID"
|
|
97
|
+
# end
|
|
98
|
+
#
|
|
99
|
+
def configure_table( mdl, &block )
|
|
100
|
+
mdl = mdl.to_s.classify.constantize unless mdl.is_a?( Class )
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
mdl.class_eval do
|
|
104
|
+
@configured_table = ConfigTable.new( self )
|
|
105
|
+
@configured_table.instance_eval( &block )
|
|
106
|
+
|
|
107
|
+
class << self ; attr_accessor :configured_table ; end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
# ConfigTable
|
|
118
|
+
# Holds all the Columns defined fot the Configurable-Table
|
|
119
|
+
#
|
|
120
|
+
class ConfigTable
|
|
121
|
+
|
|
122
|
+
attr_accessor :columns, :model, :assocs, :assoc_names, :table_id
|
|
123
|
+
|
|
124
|
+
def initialize(mdl)
|
|
125
|
+
@columns = []
|
|
126
|
+
@model = mdl
|
|
127
|
+
@table_id = "#{@model.table_name}_configured_table"
|
|
128
|
+
@assocs = mdl.reflect_on_all_associations
|
|
129
|
+
@assoc_names = @assocs.collect(&:name)
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def default_sort_col( id )
|
|
134
|
+
@default_sort = id.to_sym
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def column( id, *args )
|
|
138
|
+
@columns << Column.new( id.to_sym, self, *args )
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
def get_column(id)
|
|
142
|
+
@columns.find { |s| s.id.to_sym == id.to_sym }
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def default_sort ; get_column( @default_sort ) ; end
|
|
146
|
+
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
class Column
|
|
150
|
+
attr_accessor :id, :name, :opts, :order, :config_table, :method, :table_name, :sql_query
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
# initialize a column
|
|
154
|
+
# if column is an association of the current model, the entries
|
|
155
|
+
# are sorted either by a ruby-block (if a :method is defined to call on the
|
|
156
|
+
# association-object), by :size (ruby-block, if its a _has_many_ association) or
|
|
157
|
+
# simply by the id (ORDER-SQL statement)
|
|
158
|
+
# if columns is not an association, the entries are sorted by an ORDER-SQL statement.
|
|
159
|
+
#
|
|
160
|
+
def initialize( id, config_table, *args )
|
|
161
|
+
@id = id
|
|
162
|
+
@opts = *args || Hash.new(nil)
|
|
163
|
+
@method = @opts[:method]
|
|
164
|
+
@name = @opts[:name] || @id.to_s
|
|
165
|
+
@config_table = config_table
|
|
166
|
+
|
|
167
|
+
@assoc = @config_table.assocs.find { |s| s.name.to_sym == @id.to_sym }
|
|
168
|
+
|
|
169
|
+
@order = @opts[:sort]
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
unless @order
|
|
174
|
+
if is_assoc?
|
|
175
|
+
if @method
|
|
176
|
+
@order = Proc.new { |a,b|
|
|
177
|
+
a.__send__( @id ).__send__( @method ).to_s <=> b.__send__( @id ).__send__( @method ).to_s
|
|
178
|
+
}
|
|
179
|
+
# @order = "`#{assoc_table_name}`.`#{@method}`"
|
|
180
|
+
else
|
|
181
|
+
@order = is_has_many_assoc? ? Proc.new { |a,b| a.__send__(@method).size <=> b.__send__(@method).size } :
|
|
182
|
+
"`#{assoc_table_name}`.`id`"
|
|
183
|
+
end
|
|
184
|
+
else
|
|
185
|
+
@order = "`#{@config_table.model.table_name}`.`#{@id}`"
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def sql_query
|
|
192
|
+
is_assoc? ? "`#{table_name}`.`#{@method =~ /size/ ? 'id' : @method}`" :
|
|
193
|
+
"`#{table_name}`.`#{@id}`" ;
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def table_name
|
|
197
|
+
is_assoc? ? assoc_table_name : @config_table.model.table_name ;
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
def is_assoc? #:nodoc:
|
|
201
|
+
@assoc ? true : false
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def is_has_many_assoc? #:nodoc:
|
|
205
|
+
@assoc.macro =~ /has_many/
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
def assoc_table_name #:nodoc:
|
|
209
|
+
@assoc.options.include?( :class_name ) ?
|
|
210
|
+
@assoc.options[:class_name].constantize.table_name :
|
|
211
|
+
@id.to_s.tableize
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def order_ruby? #:nodoc:
|
|
216
|
+
@order.is_a?( Proc )
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
17
|
+
module Opensteam
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# History Module
|
|
21
|
+
#
|
|
22
|
+
# Defines all the History (Logging) specific class + modules
|
|
23
|
+
#
|
|
24
|
+
module History
|
|
25
|
+
|
|
26
|
+
class Base < ActiveRecord::Base
|
|
27
|
+
self.table_name = "histories"
|
|
28
|
+
belongs_to :receiver, :polymorphic => true
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def self.included(receiver)
|
|
33
|
+
receiver.class_eval do
|
|
34
|
+
include InstanceMethods
|
|
35
|
+
|
|
36
|
+
has_many :history, :class_name => 'Opensteam::History::Base', :as => :receiver
|
|
37
|
+
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
module InstanceMethods
|
|
44
|
+
|
|
45
|
+
def add_history( message )
|
|
46
|
+
save
|
|
47
|
+
self.history.create( :message => message )
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
end
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
17
|
+
module Opensteam
|
|
18
|
+
|
|
19
|
+
class Initializer #:nodoc:
|
|
20
|
+
|
|
21
|
+
class << self ;
|
|
22
|
+
def _logger(args)
|
|
23
|
+
logger = ( defined? RAILS_DEFAULT_LOGGER) ? RAILS_DEFAULT_LOGGER : Logger.new("#{RAILS_ROOT}/log/#{RAILS_ENV}.log")
|
|
24
|
+
logger.info "** [openSteam] #{args}"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def run( command = :process, config = Configuration.new )
|
|
29
|
+
yield config if block_given?
|
|
30
|
+
|
|
31
|
+
init = new config
|
|
32
|
+
init.__send__( command )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def require_opensteam_after_initialize
|
|
37
|
+
require 'opensteam/user_base' ## AuthenticatedMethods include !!!
|
|
38
|
+
|
|
39
|
+
_logger "loaded!"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def initialize( c )
|
|
48
|
+
@config = c
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _logger(args) ; self.class._logger( args ) ; end
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def process
|
|
56
|
+
require 'opensteam/version'
|
|
57
|
+
_logger"v#{Opensteam::VERSION::STRING} loading .."
|
|
58
|
+
|
|
59
|
+
require_libs
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
# extend ActiveRecord with the "opensteam" method
|
|
63
|
+
ActiveRecord::Base.send(:include, Opensteam::Base::Extension )
|
|
64
|
+
|
|
65
|
+
Rails::Initializer.class_eval do
|
|
66
|
+
def after_initialize_with_opensteam_initialize
|
|
67
|
+
after_initialize_without_opensteam_initialize
|
|
68
|
+
|
|
69
|
+
Opensteam::Initializer.require_opensteam_after_initialize
|
|
70
|
+
|
|
71
|
+
Opensteam::ExtensionBase.init_extensions( :backend )
|
|
72
|
+
Opensteam::ExtensionBase.verify_extensions
|
|
73
|
+
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
alias_method_chain :after_initialize, :opensteam_initialize
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def require_libs
|
|
83
|
+
require 'opensteam/version'
|
|
84
|
+
require 'opensteam/config'
|
|
85
|
+
require 'opensteam/finder'
|
|
86
|
+
require 'opensteam/product_base'
|
|
87
|
+
require 'opensteam/property_base'
|
|
88
|
+
require 'opensteam/base'
|
|
89
|
+
require 'opensteam/history'
|
|
90
|
+
require 'opensteam/state_machine'
|
|
91
|
+
require 'opensteam/invoice_base'
|
|
92
|
+
require 'opensteam/shipment_base'
|
|
93
|
+
require 'opensteam/order_base'
|
|
94
|
+
require 'opensteam/state_logic'
|
|
95
|
+
require 'opensteam/extension_base'
|
|
96
|
+
require 'opensteam/shopping_cart'
|
|
97
|
+
require 'opensteam/cart_base'
|
|
98
|
+
require 'opensteam/checkout'
|
|
99
|
+
require 'opensteam/inventory_base'
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
require 'opensteam/helper/configurable_table'
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class Configuration
|
|
113
|
+
|
|
114
|
+
def say_something
|
|
115
|
+
|
|
116
|
+
puts "....."
|
|
117
|
+
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
1
17
|
module Opensteam
|
|
2
18
|
|
|
3
19
|
|
|
@@ -31,11 +47,18 @@ module Opensteam
|
|
|
31
47
|
|
|
32
48
|
belongs_to :product, :polymorphic => true
|
|
33
49
|
|
|
34
|
-
has_many :inventories_properties
|
|
50
|
+
has_many :inventories_properties, :class_name => "Opensteam::InventoryBase::InventoriesProperty"
|
|
35
51
|
has_many :properties, :through => :inventories_properties
|
|
36
52
|
|
|
37
53
|
validates_presence_of :price, :storage
|
|
38
54
|
|
|
55
|
+
|
|
56
|
+
def products
|
|
57
|
+
find(:all, :include => :product ).collect(&:product)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
39
62
|
|
|
40
63
|
|
|
41
64
|
# alias :real_properties :properties
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
17
|
+
module Opensteam
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Base Module for all Invoice-specific modules + classes
|
|
21
|
+
module InvoiceBase
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# available States for an Invoice-Instance
|
|
26
|
+
module States
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# Invoice Model
|
|
34
|
+
class Invoice < ActiveRecord::Base
|
|
35
|
+
include Opensteam::StateMachine
|
|
36
|
+
|
|
37
|
+
belongs_to :order, :class_name => 'Opensteam::OrderBase::Order'
|
|
38
|
+
belongs_to :customer, :class_name => 'Opensteam::UserBase::User'
|
|
39
|
+
belongs_to :address, :class_name => 'Opensteam::UserBase::Address'
|
|
40
|
+
|
|
41
|
+
has_many :order_items, :class_name => 'Opensteam::OrderBase::OrderItem'
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def initialize(*args)
|
|
45
|
+
super(*args)
|
|
46
|
+
if order
|
|
47
|
+
self.address = order.payment_address
|
|
48
|
+
self.customer = order.customer
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
end
|
data/lib/opensteam/order_base.rb
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
# openSteam - http://www.opensteam.net
|
|
2
|
+
# Copyright (C) 2008 DiamondDogs Webconsulting
|
|
3
|
+
#
|
|
4
|
+
# This program is free software; you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation; version 2 of the License.
|
|
7
|
+
#
|
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11
|
+
# GNU General Public License for more details.
|
|
12
|
+
#
|
|
13
|
+
# You should have received a copy of the GNU General Public License along
|
|
14
|
+
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
15
|
+
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
16
|
+
|
|
1
17
|
module Opensteam
|
|
2
18
|
|
|
3
19
|
|
|
@@ -7,28 +23,100 @@ module Opensteam
|
|
|
7
23
|
#
|
|
8
24
|
#
|
|
9
25
|
module OrderBase
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
module States
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
module OrderExtension
|
|
34
|
+
def all_finished? ; empty? ? false : collect(&:finished?).all? ; end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
module OrderItemsExtension
|
|
38
|
+
def all_shipped? ; collect { |s| s.shipment != nil }.all? ; end
|
|
39
|
+
def all_invoiced? ; collect { |s| s.invoice != nil }.all? ; end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
require 'uuidtools'
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
# Order Model
|
|
16
47
|
class Order < ActiveRecord::Base
|
|
17
|
-
|
|
18
|
-
|
|
48
|
+
include Opensteam::StateMachine
|
|
49
|
+
|
|
50
|
+
include Opensteam::UUIDHelper
|
|
51
|
+
|
|
52
|
+
# associations
|
|
53
|
+
|
|
54
|
+
has_many :order_items, :class_name => 'Opensteam::OrderBase::OrderItem', :extend => OrderItemsExtension
|
|
55
|
+
|
|
56
|
+
belongs_to :customer, :class_name => 'Opensteam::UserBase::User'
|
|
19
57
|
|
|
20
58
|
belongs_to :payment_address, :class_name => 'Opensteam::UserBase::Address', :foreign_key => 'payment_address_id'
|
|
21
59
|
belongs_to :shipping_address, :class_name => 'Opensteam::UserBase::Address', :foreign_key => 'shipping_address_id'
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
60
|
+
|
|
61
|
+
has_many :invoices, :class_name => 'Opensteam::InvoiceBase::Invoice', :extend => OrderExtension
|
|
62
|
+
|
|
63
|
+
has_many :shipments, :class_name => 'Opensteam::ShipmentBase::Shipment', :extend => OrderExtension
|
|
64
|
+
|
|
65
|
+
# belongs_to :payment_type
|
|
66
|
+
|
|
67
|
+
# validations
|
|
68
|
+
validates_associated :customer, :payment_address, :shipping_address
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
alias :real_customer= :customer=
|
|
72
|
+
# find or initialize customer by email and associate it to the order
|
|
73
|
+
def customer= (cust)
|
|
74
|
+
|
|
75
|
+
cust[:paassword] = cust[:password_confirmation] = "opensteam" unless cust[:password]
|
|
76
|
+
self.real_customer = Opensteam::UserBase::User.create( cust )
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# self.real_customer = Customer.find_or_initialize_by_email( cust[:email] )
|
|
80
|
+
#
|
|
81
|
+
# self.real_customer = Opensteam::UserBase::Customer.find_or_create_by_email( cust[:email] )
|
|
82
|
+
# self.customer.update_attributes( { :firstname => cust[:firstname], :lastname => cust[:lastname] } )
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
alias :real_payment_address= :payment_address=
|
|
87
|
+
# find or create payment-address and associate it with the order
|
|
88
|
+
def payment_address=(addr)
|
|
89
|
+
self.real_payment_address = get_address( addr )
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
alias :real_shipping_address= :shipping_address=
|
|
94
|
+
# find or create shipping-address and associate it with the order
|
|
95
|
+
def shipping_address=(addr)
|
|
96
|
+
self.real_shipping_address = get_address( addr )
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# copy the products from cart to order and update storage-quantity for inventory-entry
|
|
26
102
|
def copy_from_cart( cart )
|
|
27
103
|
cart.items.each do |v|
|
|
28
104
|
li = OrderItem.new_item(v)
|
|
29
105
|
order_items << li
|
|
106
|
+
li.inventory.storage -= li.quantity
|
|
107
|
+
li.inventory.save
|
|
30
108
|
end
|
|
31
109
|
end
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
def get_address(addr)
|
|
114
|
+
address = Opensteam::UserBase::Address.find( :first, :conditions => addr.update( { :user_id => self.customer.id } ) ) rescue nil
|
|
115
|
+
address = Opensteam::UserBase::Address.new( addr ) if address.nil?
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
|
|
32
120
|
end
|
|
33
121
|
|
|
34
122
|
|
|
@@ -39,9 +127,12 @@ module Opensteam
|
|
|
39
127
|
class OrderItem < ActiveRecord::Base
|
|
40
128
|
belongs_to :order
|
|
41
129
|
belongs_to :inventory , :class_name => "Opensteam::InventoryBase::Inventory"
|
|
130
|
+
|
|
131
|
+
belongs_to :invoice, :class_name => 'Opensteam::InvoiceBase::Invoice'
|
|
132
|
+
belongs_to :shipment, :class_name => 'Opensteam::ShipmentBase::Shipment'
|
|
133
|
+
|
|
134
|
+
def is_available? ; true ; end
|
|
42
135
|
|
|
43
|
-
|
|
44
|
-
|
|
45
136
|
def self.new_item(i)
|
|
46
137
|
returning(self.new) do |li|
|
|
47
138
|
li.itemid = i.yamlid
|