opensteam 0.9.2 → 0.9.3
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 +53 -0
- data/README.rdoc +19 -10
- data/generators/opensteam/opensteam_generator.rb +27 -3
- data/generators/opensteam/templates/app/controllers/admin/configurations_controller.rb +85 -0
- data/generators/opensteam/templates/app/controllers/admin/inventories_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/admin/invoices_controller.rb +35 -4
- data/generators/opensteam/templates/app/controllers/admin/orders_controller.rb +5 -4
- data/generators/opensteam/templates/app/controllers/admin/shipments_controller.rb +6 -3
- data/generators/opensteam/templates/app/controllers/admin/shipping_rate_groups_controller.rb +76 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_groups_controller.rb +124 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_rules_controller.rb +19 -0
- data/generators/opensteam/templates/app/controllers/admin/tax_zones_controller.rb +118 -0
- data/generators/opensteam/templates/app/controllers/admin/users_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/admin_controller.rb +20 -0
- data/generators/opensteam/templates/app/controllers/carts_controller.rb +118 -0
- data/generators/opensteam/templates/app/controllers/checkout_controller.rb +119 -79
- data/generators/opensteam/templates/app/controllers/profile_controller.rb +2 -4
- data/generators/opensteam/templates/app/controllers/searches_controller.rb +1 -1
- data/generators/opensteam/templates/app/controllers/user_sessions_controller.rb +2 -1
- data/generators/opensteam/templates/app/controllers/users_controller.rb +10 -3
- data/generators/opensteam/templates/app/helpers/admin_helper.rb +15 -1
- data/generators/opensteam/templates/app/helpers/checkout_helper.rb +38 -0
- data/generators/opensteam/templates/app/helpers/webshop_helper.rb +6 -1
- data/generators/opensteam/templates/app/models/zone.rb +18 -0
- data/generators/opensteam/templates/app/views/admin/_menu.html.erb +18 -0
- data/generators/opensteam/templates/app/views/admin/catalog.html.erb +2 -3
- data/generators/opensteam/templates/app/views/admin/configurations/edit.html.erb +20 -0
- data/generators/opensteam/templates/app/views/admin/configurations/index.html.erb +22 -0
- data/generators/opensteam/templates/app/views/admin/configurations/new.html.erb +19 -0
- data/generators/opensteam/templates/app/views/admin/configurations/show.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/filters/_filter.html.erb +1 -1
- data/generators/opensteam/templates/app/views/admin/index.html.erb +0 -19
- data/generators/opensteam/templates/app/views/admin/inventories/edit.html.erb +10 -6
- data/generators/opensteam/templates/app/views/admin/inventories/new.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/inventories/show.html.erb +10 -6
- data/generators/opensteam/templates/app/views/admin/invoices/_invoice.html.erb +1 -0
- data/generators/opensteam/templates/app/views/admin/invoices/_invoice_fields.html.erb +52 -0
- data/generators/opensteam/templates/app/views/admin/invoices/new.html.erb +9 -37
- data/generators/opensteam/templates/app/views/admin/invoices/show.html.erb +10 -36
- data/generators/opensteam/templates/app/views/admin/invoices/show.pdf.prawn +59 -0
- data/generators/opensteam/templates/app/views/admin/order_config.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/order_items/_item_entry.html.erb +9 -0
- data/generators/opensteam/templates/app/views/admin/order_items/_items_table.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/orders/_order.html.erb +9 -9
- data/generators/opensteam/templates/app/views/admin/orders/_orders.html.erb +1 -1
- data/generators/opensteam/templates/app/views/admin/orders/show.html.erb +25 -9
- data/generators/opensteam/templates/app/views/admin/payment_types.html.erb +27 -0
- data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment.html.erb +26 -0
- data/generators/opensteam/templates/app/views/admin/payments/_credit_card_payment_info.html.erb +15 -0
- data/generators/opensteam/templates/app/views/admin/payments/_direct_debit_payment.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/shipments/new.html.erb +45 -30
- data/generators/opensteam/templates/app/views/admin/shipments/show.html.erb +3 -3
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_payment_addition.html.erb +12 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/_rate.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/edit.html.erb +63 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/index.html.erb +28 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/new.html.erb +60 -0
- data/generators/opensteam/templates/app/views/admin/shipping_rate_groups/show.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/system.html.erb +5 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_attributes.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups.html.erb +17 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_groups_row.html.erb +12 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/_tax_rule.html.erb +14 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/edit.html.erb +26 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/index.html.erb +8 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/new.html.erb +27 -0
- data/generators/opensteam/templates/app/views/admin/tax_groups/show.html.erb +28 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_attributes.html.erb +18 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zone_row.html.erb +13 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/_tax_zones.html.erb +11 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/edit.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/index.html.erb +16 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/new.html.erb +14 -0
- data/generators/opensteam/templates/app/views/admin/tax_zones/show.html.erb +15 -0
- data/generators/opensteam/templates/app/views/admin/users.html.erb +0 -1
- data/generators/opensteam/templates/app/views/admin/users/show.html.erb +10 -0
- data/generators/opensteam/templates/app/views/administration_mailer/order_customer.erb +1 -1
- data/generators/opensteam/templates/app/views/carts/_cart.html.erb +7 -0
- data/generators/opensteam/templates/app/views/carts/_cart_content.html.erb +45 -0
- data/generators/opensteam/templates/app/views/carts/create.rjs +3 -0
- data/generators/opensteam/templates/app/views/{cart → carts}/index.html.erb +0 -0
- data/generators/opensteam/templates/app/views/carts/update.rjs +11 -0
- data/generators/opensteam/templates/app/views/checkout/_address.html.erb +42 -0
- data/generators/opensteam/templates/app/views/checkout/_customer.html.erb +31 -0
- data/generators/opensteam/templates/app/views/checkout/_edit_checkout.html.erb +42 -0
- data/generators/opensteam/templates/app/views/checkout/_new_checkout.html.erb +44 -0
- data/generators/opensteam/templates/app/views/checkout/_shipping_buttons.html.erb +8 -0
- data/generators/opensteam/templates/app/views/checkout/edit.html.erb +7 -0
- data/generators/opensteam/templates/app/views/checkout/new.html.erb +11 -0
- data/generators/opensteam/templates/app/views/checkout/outro.html.erb +1 -4
- data/generators/opensteam/templates/app/views/checkout/show.html.erb +63 -0
- data/generators/opensteam/templates/app/views/common/_header_admin.html.erb +5 -0
- data/generators/opensteam/templates/app/views/layouts/admin.html.erb +28 -12
- data/generators/opensteam/templates/app/views/layouts/profile.html.erb +2 -2
- data/generators/opensteam/templates/app/views/layouts/webshop.html.erb +5 -4
- data/generators/opensteam/templates/app/views/payment/_advance_payment_payment.html.erb +1 -0
- data/generators/opensteam/templates/app/views/payment/_credit_card_payment.html.erb +37 -0
- data/generators/opensteam/templates/app/views/payment/_credit_card_payment_confirmation.html.erb +20 -0
- data/generators/opensteam/templates/app/views/payment/_direct_debit_payment.html.erb +5 -0
- data/generators/opensteam/templates/app/views/payment/_direct_debit_payment_confirmation.html.erb +5 -0
- data/generators/opensteam/templates/app/views/profile/index.html.erb +1 -1
- data/generators/opensteam/templates/app/views/profile/infos/edit.html.erb +20 -12
- data/generators/opensteam/templates/app/views/profile/infos/edit_password.html.erb +16 -12
- data/generators/opensteam/templates/app/views/profile/orders/_order.html.erb +1 -1
- data/generators/opensteam/templates/app/views/profile/orders/show.html.erb +10 -7
- data/generators/opensteam/templates/app/views/webshop/_inventory_content.html.erb +1 -0
- data/generators/opensteam/templates/app/views/webshop/show.html.erb +3 -1
- data/generators/opensteam/templates/config/initializers/init_states.rb +13 -24
- data/generators/opensteam/templates/config/initializers/opensteam.rb +41 -0
- data/generators/opensteam/templates/config/initializers/opensteam_model_tables.rb +49 -10
- data/generators/opensteam/templates/config/initializers/opensteam_security.rb +8 -0
- data/generators/opensteam/templates/config/initializers/payment_process.rb +37 -0
- data/generators/opensteam/templates/db/migrate/20080609095723_create_addresses.rb +8 -2
- data/generators/opensteam/templates/db/migrate/20080609095726_create_inventories.rb +6 -3
- data/generators/opensteam/templates/db/migrate/20080609095728_create_order_items.rb +12 -1
- data/generators/opensteam/templates/db/migrate/20080609095729_create_orders.rb +8 -12
- data/generators/opensteam/templates/db/migrate/20080609095730_create_payment_types.rb +2 -0
- data/generators/opensteam/templates/db/migrate/20080714131513_create_invoices.rb +2 -1
- data/generators/opensteam/templates/db/migrate/20080714131650_create_shipments.rb +3 -1
- data/generators/opensteam/templates/db/migrate/20080808075247_create_containers.rb +30 -0
- data/generators/opensteam/templates/db/migrate/20080808083011_create_container_items.rb +25 -0
- data/generators/opensteam/templates/db/migrate/20080812102727_create_tax_zones.rb +16 -0
- data/generators/opensteam/templates/db/migrate/20080812102858_create_tax_rules.rb +15 -0
- data/generators/opensteam/templates/db/migrate/20080812102956_create_tax_groups.rb +14 -0
- data/generators/opensteam/templates/db/migrate/20080831181436_create_configurations.rb +15 -0
- data/generators/opensteam/templates/db/migrate/20080903131506_create_payments.rb +22 -0
- data/generators/opensteam/templates/db/migrate/20080904133625_create_payment_transactions.rb +24 -0
- data/generators/opensteam/templates/db/migrate/20080916102341_create_zones.rb +19 -0
- data/generators/opensteam/templates/db/migrate/20080916134340_create_region_shipping_rates.rb +18 -0
- data/generators/opensteam/templates/db/migrate/20080916134523_create_shipping_rate_groups.rb +18 -0
- data/generators/opensteam/templates/db/migrate/20080916135226_create_shipping_payment_additions.rb +20 -0
- data/generators/opensteam/templates/db/migrate/20080916135228_init_opensteam_config.rb +60 -0
- data/generators/opensteam/templates/public/images/opensteam_black.jpg +0 -0
- data/generators/opensteam/templates/public/images/pdf.png +0 -0
- data/generators/opensteam/templates/public/images/shader.png +0 -0
- data/generators/opensteam/templates/public/index.html +1 -0
- data/generators/opensteam/templates/public/javascripts/opensteam.js +21 -21
- data/generators/opensteam/templates/public/stylesheets/opensteam_admin.css +291 -0
- data/generators/opensteam/templates/public/stylesheets/opensteam_white.css +47 -11
- data/generators/opensteam/templates/tasks/opensteam.rake +2 -12
- data/generators/opensteam/templates/test/fixtures/addresses.yml +26 -0
- data/generators/opensteam/templates/test/fixtures/configurations.yml +29 -0
- data/generators/opensteam/templates/test/fixtures/inventories.yml +32 -15
- data/generators/opensteam/templates/test/fixtures/profiles.yml +21 -0
- data/generators/opensteam/templates/test/fixtures/region_shipping_rates.yml +33 -0
- data/generators/opensteam/templates/test/fixtures/shipping_payment_additions.yml +91 -0
- data/generators/opensteam/templates/test/fixtures/shipping_rate_groups.yml +25 -0
- data/generators/opensteam/templates/test/fixtures/tax_groups.yml +13 -0
- data/generators/opensteam/templates/test/fixtures/tax_rules.yml +29 -0
- data/generators/opensteam/templates/test/fixtures/tax_zones.yml +33 -0
- data/generators/opensteam/templates/test/fixtures/users.yml +26 -0
- data/generators/opensteam/templates/test/fixtures/zones.yml +2707 -0
- data/generators/opensteam/templates/test/functional/carts_controller_test.rb +103 -0
- data/generators/opensteam/templates/test/test_helper.rb +38 -0
- data/generators/opensteam/templates/test/unit/container_test.rb +71 -0
- data/generators/opensteam/templates/test/unit/order_test.rb +93 -0
- data/generators/opensteam/templates/test/unit/payment_test.rb +220 -0
- data/generators/opensteam/templates/test/unit/product_test.rb +158 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/.gitignore +3 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/MIT-LICENSE +20 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/README +12 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/Rakefile +22 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/init.rb +6 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto.rb +13 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/action_controller.rb +47 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/base.rb +75 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/lib/prawnto/template_handler/raw.rb +54 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/tasks/prawnto_tasks.rake +4 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/action_controller_test.rb +36 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/base_template_handler_test.rb +58 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/raw_template_handler_test.rb +163 -0
- data/generators/opensteam/templates/vendor/plugins/prawnto/test/template_handler_test_mocks.rb +83 -0
- data/generators/opensteam_product/templates/views/admin/_attributes.html.erb +8 -3
- data/generators/opensteam_product/templates/views/admin/_inventories.html.erb +2 -0
- data/lib/opensteam.rb +0 -1
- data/lib/opensteam/base.rb +2 -1
- data/lib/opensteam/checkout.rb +3 -12
- data/lib/opensteam/config.rb +50 -2
- data/lib/opensteam/container.rb +196 -0
- data/lib/opensteam/extension_base.rb +19 -1
- data/lib/opensteam/finder.rb +1 -1
- data/lib/opensteam/helpers/config_table_helper.rb +18 -6
- data/lib/opensteam/initializer.rb +24 -4
- data/lib/opensteam/inventory_base.rb +6 -1
- data/lib/opensteam/invoice_base.rb +12 -13
- data/lib/opensteam/money.rb +230 -0
- data/lib/opensteam/order_base.rb +122 -48
- data/lib/opensteam/payment.rb +225 -0
- data/lib/opensteam/payment/advance_payment.rb +34 -0
- data/lib/opensteam/payment/credit_card_payment.rb +217 -0
- data/lib/opensteam/payment/direct_debit_payment.rb +53 -0
- data/lib/opensteam/product_base.rb +48 -12
- data/lib/opensteam/security.rb +54 -0
- data/lib/opensteam/shipment_base.rb +214 -6
- data/lib/opensteam/shopping_cart.rb +20 -300
- data/lib/opensteam/state_logic.rb +5 -3
- data/lib/opensteam/state_machine.rb +8 -3
- data/lib/opensteam/user_base.rb +48 -6
- data/lib/opensteam/version.rb +1 -1
- metadata +122 -16
- data/generators/opensteam/templates/app/controllers/cart_controller.rb +0 -94
- data/generators/opensteam/templates/app/views/admin/orders/_event.html.erb +0 -5
- data/generators/opensteam/templates/app/views/admin/orders/_order_item.html.erb +0 -10
- data/generators/opensteam/templates/app/views/cart/_cart.html.erb +0 -8
- data/generators/opensteam/templates/app/views/cart/_cart_content.html.erb +0 -20
- data/generators/opensteam/templates/app/views/cart/update.rjs +0 -1
- data/generators/opensteam/templates/app/views/checkout/payment.html.erb +0 -8
- data/generators/opensteam/templates/app/views/checkout/shipping.html.erb +0 -45
- data/generators/opensteam/templates/app/views/checkout/show_cart.html.erb +0 -13
- data/generators/opensteam/templates/app/views/checkout/update_cart_content.rjs +0 -2
- data/generators/opensteam/templates/app/views/profile/orders/_order_item.html.erb +0 -10
- data/generators/opensteam/templates/db/migrate/20080609095725_create_dummy_users.rb +0 -21
- data/lib/opensteam/cart_base.rb +0 -227
|
@@ -25,6 +25,52 @@ module Opensteam
|
|
|
25
25
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
+
|
|
29
|
+
module ShippingCalculation
|
|
30
|
+
|
|
31
|
+
def calculate_shipping_rate attr = {}
|
|
32
|
+
send( "shipping_rate_#{Opensteam::Config[:shipping_strategy]}", attr )
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def set_shipping_rate!
|
|
37
|
+
returning( self ) do |s|
|
|
38
|
+
s.shipping_rate = ( r = calculate_shipping_rate ).is_a?( Array ) ? r.sum : r
|
|
39
|
+
s.total_price += s.shipping_rate
|
|
40
|
+
end
|
|
41
|
+
# self.update_attribute( :shipping_rate, ( r = calculate_shipping_rate ).is_a?( Array ) ? r.sum : r )
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def shipping_rate_per_order attr
|
|
47
|
+
set_shipping_attributes( attr )
|
|
48
|
+
|
|
49
|
+
ShippingRateGroup.find_by_name( attr[:group_name] ).rate_for( attr )
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def shipping_rate_per_item attr
|
|
55
|
+
set_shipping_attributes( attr )
|
|
56
|
+
|
|
57
|
+
self.items.collect { |i|
|
|
58
|
+
ShippingRateGroup.find_by_name( i.shipping_rate_group ).rate_for( attr ) rescue 0.0
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def set_shipping_attributes( attr )
|
|
64
|
+
attr[:payment_type] = self.payment_type unless attr[:payment_type]
|
|
65
|
+
attr[:shipping_method] = self.shipping_type unless attr[:shipping_method]
|
|
66
|
+
attr[:country] = self.shipping_address.country unless attr[:country]
|
|
67
|
+
attr[:group_name] = Opensteam::Config[:shipping_rate_group_default] unless attr[:group_name]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
private :set_shipping_attributes
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
|
|
28
74
|
|
|
29
75
|
|
|
30
76
|
# Shipment Model
|
|
@@ -35,13 +81,11 @@ module Opensteam
|
|
|
35
81
|
belongs_to :order, :class_name => 'Opensteam::OrderBase::Order'
|
|
36
82
|
belongs_to :customer, :class_name => 'Opensteam::UserBase::User'
|
|
37
83
|
belongs_to :address, :class_name => 'Opensteam::UserBase::Address'
|
|
38
|
-
|
|
39
|
-
has_many :order_items, :class_name => 'Opensteam::OrderBase::OrderItem'
|
|
40
84
|
|
|
85
|
+
has_many :order_items, :class_name => 'Opensteam::Container::Item'
|
|
41
86
|
|
|
42
87
|
named_scope :by_order, lambda { |order_id| { :include => :order, :conditions => { :order_id => order_id } } }
|
|
43
|
-
named_scope :order_by, lambda { |by| { :include => Shipment.osteam_configtable.default_include, :order => Array(by).join(",") , :conditions => "
|
|
44
|
-
|
|
88
|
+
named_scope :order_by, lambda { |by| { :include => Shipment.osteam_configtable.default_include, :order => Array(by).join(",") , :conditions => "addresses.id = addresses.id" } }
|
|
45
89
|
|
|
46
90
|
|
|
47
91
|
def initialize(*args)
|
|
@@ -51,16 +95,180 @@ module Opensteam
|
|
|
51
95
|
self.address = order.shipping_address
|
|
52
96
|
self.customer = order.customer
|
|
53
97
|
end
|
|
54
|
-
|
|
55
98
|
end
|
|
56
99
|
|
|
100
|
+
|
|
57
101
|
end
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
# Model for Shipping Rate Groups
|
|
105
|
+
class ShippingRateGroup < ActiveRecord::Base
|
|
106
|
+
has_many :shipping_rates,
|
|
107
|
+
:class_name => 'Opensteam::ShipmentBase::RegionShippingRate',
|
|
108
|
+
:dependent => :destroy
|
|
109
|
+
|
|
110
|
+
has_many :zones,
|
|
111
|
+
:through => :shipping_rates
|
|
112
|
+
|
|
113
|
+
has_many :payment_additions,
|
|
114
|
+
:class_name => 'Opensteam::ShipmentBase::ShippingPaymentAddition'
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
validates_presence_of :name
|
|
118
|
+
validates_uniqueness_of :name
|
|
119
|
+
|
|
120
|
+
validates_associated :shipping_rates
|
|
121
|
+
validates_associated :payment_additions
|
|
122
|
+
|
|
123
|
+
after_update :save_shipping_rates, :save_payment_additions
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def rate_for( attr = {} )
|
|
127
|
+
conditions = {}
|
|
128
|
+
conditions["zones.country_name"] = attr[:country] || Opensteam::Config[:default_country]
|
|
129
|
+
conditions["shipping_method"] = attr[:shipping_method] || Opensteam::Config[:shipping_method_default]
|
|
130
|
+
|
|
131
|
+
srate = shipping_rates.find( :first, :include => :zone, :conditions => conditions )
|
|
132
|
+
|
|
133
|
+
rate = unless srate
|
|
134
|
+
shipping_disabled ? 0.0 : master_rate.to_f
|
|
135
|
+
else
|
|
136
|
+
srate.rate
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
rate += get_payment_additions( attr[:payment_type] ) if attr[:payment_type]
|
|
140
|
+
|
|
141
|
+
rate
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
private
|
|
149
|
+
|
|
150
|
+
def get_payment_additions( payment_type )
|
|
151
|
+
if ( pa = payment_additions.find(:first, :conditions => { :payment_type => payment_type } ) )
|
|
152
|
+
pa.amount
|
|
153
|
+
else
|
|
154
|
+
0.0
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
|
|
58
159
|
|
|
160
|
+
def new_payment_additions=( pa )
|
|
161
|
+
pa.each do |r|
|
|
162
|
+
payment_additions.build( r )
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
def existing_payment_additions=( pa )
|
|
168
|
+
payment_additions.reject(&:new_record?).each do |paddition|
|
|
169
|
+
attributes = pa[ paddition.id.to_s ]
|
|
170
|
+
if attributes
|
|
171
|
+
paddition.attributes = attributes
|
|
172
|
+
else
|
|
173
|
+
payment_additions.delete( paddition )
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def new_rates=( rates )
|
|
180
|
+
rates.each do |r|
|
|
181
|
+
shipping_rates.build( r )
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def existing_rates=( rates )
|
|
186
|
+
shipping_rates.reject(&:new_record?).each do |rate|
|
|
187
|
+
attributes = rates[ rate.id.to_s ]
|
|
188
|
+
if attributes
|
|
189
|
+
rate.attributes = attributes
|
|
190
|
+
else
|
|
191
|
+
shipping_rates.delete( rate )
|
|
192
|
+
end
|
|
193
|
+
end
|
|
59
194
|
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
|
|
60
198
|
|
|
199
|
+
def validate
|
|
200
|
+
if shipping_rates.empty?
|
|
201
|
+
if self.master_rate.blank? && !self.shipping_disabled
|
|
202
|
+
errors.add_to_base( "Either add Shipping Rates or define a default rate!" )
|
|
203
|
+
errors.add( :shipping_rates, "Cannot be empty!" )
|
|
204
|
+
errors.add( :master_rate, "Cannot be empty!" )
|
|
205
|
+
errors.add( :shipping_disabled, "" )
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
61
209
|
|
|
210
|
+
def save_shipping_rates
|
|
211
|
+
shipping_rates.each { |s| s.save(false) }
|
|
212
|
+
end
|
|
213
|
+
|
|
214
|
+
def save_payment_additions
|
|
215
|
+
payment_additions.each { |s| s.save(false) }
|
|
216
|
+
end
|
|
62
217
|
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
end
|
|
63
221
|
|
|
222
|
+
|
|
223
|
+
# Model for ShippingRate depending on Region (Zone, Country, .. )
|
|
224
|
+
class RegionShippingRate < ActiveRecord::Base
|
|
225
|
+
|
|
226
|
+
belongs_to :group,
|
|
227
|
+
:class_name => 'Opensteam::ShipmentBase::ShippingRateGroup'
|
|
228
|
+
|
|
229
|
+
belongs_to :zone,
|
|
230
|
+
:class_name => 'Zone'
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
## named scopes
|
|
234
|
+
|
|
235
|
+
# find all by country-name and shipping-method-name
|
|
236
|
+
named_scope :by_country_and_shipping_method, lambda { |country, sm|
|
|
237
|
+
{ :include => :zone,
|
|
238
|
+
:conditions => { "zones.country_name" => country, :shipping_method => sm }
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
# find all by country-name
|
|
243
|
+
named_scope :by_country_name, lambda { |country_name|
|
|
244
|
+
{ :include => :zone, :conditions => { "zones.country_name" => country_name } }
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
# find all by shipping-method-name
|
|
248
|
+
named_scope :by_shipping_method, lambda { |shipping_method|
|
|
249
|
+
{ :conditions => { :shipping_method => shipping_method } }
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
end
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
# Model for ShippingRate Additions depending on the payment_type
|
|
258
|
+
class ShippingPaymentAddition < ActiveRecord::Base
|
|
259
|
+
self.table_name = "shipping_payment_additions"
|
|
260
|
+
|
|
261
|
+
belongs_to :shipping_rate_group,
|
|
262
|
+
:class_name => "Opensteam::ShipmentBase::ShippingRateGroup"
|
|
263
|
+
|
|
264
|
+
validates_uniqueness_of :payment_type, :scope => [ :shipping_rate_group_id ]
|
|
265
|
+
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
64
272
|
end
|
|
65
273
|
|
|
66
|
-
end
|
|
274
|
+
end
|
|
@@ -19,7 +19,8 @@ require 'opensteam/finder'
|
|
|
19
19
|
|
|
20
20
|
module Opensteam
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
|
|
23
|
+
# Controller Actions for ShoppingCart( Opensteam::Container::Base, Opensteam::Cart ) manipulation
|
|
23
24
|
module ShoppingCart
|
|
24
25
|
|
|
25
26
|
|
|
@@ -28,334 +29,53 @@ module Opensteam
|
|
|
28
29
|
|
|
29
30
|
base.class_eval do
|
|
30
31
|
include InstanceMethods
|
|
31
|
-
before_filter :
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
before_filter :get_cart
|
|
34
33
|
end
|
|
34
|
+
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
-
module ClassMethods
|
|
37
|
+
module ClassMethods #:nodoc:
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
|
|
41
41
|
module InstanceMethods
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
# delete item from cart
|
|
45
|
-
#
|
|
46
|
-
def del_item
|
|
47
|
-
get_cart.del( :cart_item_id => params[:id])
|
|
48
|
-
@current_item = params[:id]
|
|
49
|
-
redirect_to_index unless request.xhr?
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# show item from cart
|
|
54
|
-
#
|
|
55
|
-
def show_cart_item
|
|
56
|
-
i = Opensteam::InventoryBase::Inventory.find( @cart.items[ params[:id].to_i ].yamlid )
|
|
57
|
-
@product = i.product
|
|
58
|
-
@inventory = [i]
|
|
59
|
-
@product.selected_inventory = @inventory
|
|
60
|
-
@properties = @product.selected_inventory.last.properties.to_h2 { |x| x.class.to_s.tableize }
|
|
61
|
-
@cart_details = true
|
|
62
|
-
render :action => :show
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
# add an inventory object to the shopping cart
|
|
68
|
-
#
|
|
69
|
-
# * finds the product + inventory object (based on selected properties)
|
|
70
|
-
# * checks if product is available
|
|
71
|
-
# * add inventory object to cart
|
|
72
|
-
def add_inventory_to_cart
|
|
73
|
-
if request.post?
|
|
74
|
-
|
|
75
|
-
params[:product] = frmt params[:product]
|
|
76
|
-
|
|
77
|
-
if params[:product][:properties] && params[:product][:properties].index("")
|
|
78
|
-
flash[:error] = "Please select a #{params[:product][:properties].index("").humanize}"
|
|
79
|
-
return
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
product = Opensteam::Find.find_product_with_inventory( params[:product] )
|
|
83
|
-
if product.is_available?
|
|
84
|
-
unless @cart.add product.selected_inventories.last.id
|
|
85
|
-
render :update do |page| page.alert "Sorry, there are only #{product.selected_inventories.last.storage} available!" end
|
|
86
|
-
end
|
|
87
|
-
else
|
|
88
|
-
render :update do |page| page.alert "Sorry, this product is currently not available!" end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
def incr_quantity
|
|
97
|
-
if request.post?
|
|
98
|
-
ci = @cart.get( :cart_item_id => params[:id] )
|
|
99
|
-
unless ci.incr
|
|
100
|
-
render :update do |page| page.alert "Sorry, there are only #{ci.quantity} available!" end
|
|
101
|
-
return
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
if session[:active_order]
|
|
105
|
-
render :template => "checkout/update_cart_content.rjs"
|
|
106
|
-
else
|
|
107
|
-
render :action => "add_inventory_to_cart.rjs"
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
end
|
|
111
43
|
|
|
112
|
-
|
|
113
|
-
def decr_quantity
|
|
114
|
-
if request.post?
|
|
115
|
-
( ( ci = @cart.get( :cart_item_id => params[:id] ) ).quantity - 1 ) == 0 ?
|
|
116
|
-
@cart.items.delete_at( params[:id].to_i ) :
|
|
117
|
-
ci.decr ;
|
|
118
|
-
end
|
|
119
|
-
if session[:active_order]
|
|
120
|
-
render :template => "checkout/update_cart_content.rjs"
|
|
121
|
-
else
|
|
122
|
-
render :action => "add_inventory_to_cart.rjs"
|
|
123
|
-
end
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
#
|
|
130
|
-
# update quantity for item in cart
|
|
131
|
-
# params[:quantity] = { "item_id" => "quantity }
|
|
132
|
-
#
|
|
133
|
-
def update_quantity
|
|
134
|
-
if request.post?
|
|
135
|
-
params[:quantity].each { |key,value| @cart.set_quantity(key, value) }
|
|
136
|
-
|
|
137
|
-
if session[:active_order]
|
|
138
|
-
redirect_to :action => "show_cart"
|
|
139
|
-
return
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
redirect_to_index
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
#
|
|
149
|
-
# empty cart
|
|
150
|
-
#
|
|
151
|
-
def empty_cart
|
|
152
|
-
wipe_cart
|
|
153
|
-
redirect_to_index
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
#====================================================
|
|
160
|
-
# private methods
|
|
161
|
-
#
|
|
162
|
-
#
|
|
163
44
|
private
|
|
164
|
-
|
|
45
|
+
|
|
165
46
|
# format params[:product] hash (-> rescursive templates...)
|
|
166
47
|
def frmt(h)
|
|
167
48
|
returning(Hash.new) { |hash| h.each_pair { |k,v| k =~ /^products/ ? ( hash[:products] ||= [] ) << frmt(v) : hash[k] = v } }
|
|
168
49
|
end
|
|
169
|
-
|
|
170
50
|
|
|
171
|
-
|
|
172
|
-
|
|
51
|
+
|
|
52
|
+
def get_cart_id
|
|
53
|
+
session[:cart] ||= Opensteam::Container::Cart.create.id
|
|
173
54
|
end
|
|
174
|
-
|
|
175
|
-
|
|
55
|
+
|
|
176
56
|
def get_cart
|
|
177
|
-
|
|
57
|
+
@cart = Opensteam::Container::Cart.find( get_cart_id )
|
|
58
|
+
rescue
|
|
59
|
+
session[:cart] = Opensteam::Container::Cart.create.id
|
|
60
|
+
@cart = Opensteam::Container::Cart.find( session[:cart] )
|
|
178
61
|
end
|
|
179
|
-
|
|
62
|
+
|
|
63
|
+
|
|
180
64
|
def wipe_cart
|
|
181
65
|
session[:cart] = nil
|
|
182
66
|
get_cart
|
|
183
67
|
end
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
def redirect_to_index
|
|
187
|
-
redirect_to opensteam_index_path
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
def get_user
|
|
193
|
-
if session[:user_login]
|
|
194
|
-
return Opensteam::UserBase::User.find(:first, :conditions => ["login = ?", session[:user_login]])
|
|
195
|
-
end
|
|
196
|
-
rescue
|
|
197
|
-
return nil
|
|
198
|
-
end
|
|
199
68
|
|
|
200
|
-
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
class Cart
|
|
207
|
-
|
|
208
|
-
## cart_items
|
|
209
|
-
attr_accessor :items
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
# intialize items array
|
|
213
|
-
def initialize
|
|
214
|
-
@items = []
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
# get item from cart
|
|
220
|
-
# get( :cart_itemd_id => 1 ) # get item by internal array id
|
|
221
|
-
# get( :yamlid => 3 ) # get item by Inventory-id
|
|
222
|
-
#
|
|
223
|
-
def get( opts = {} )
|
|
224
|
-
|
|
225
|
-
if opts.has_key? :yamlid
|
|
226
|
-
@items.each do |v|
|
|
227
|
-
return v if v.yamlid == opts[:yamlid]
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
elsif opts.has_key? :cart_item_id
|
|
231
|
-
return @items[ opts[:cart_item_id].to_i ]
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
return nil
|
|
235
|
-
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
# add an item to cart or increment its quantity
|
|
241
|
-
def add( yamlid )
|
|
242
|
-
item = get( :yamlid => yamlid )
|
|
243
|
-
if item.nil?
|
|
244
|
-
@items << CartItem.new( yamlid )
|
|
245
|
-
return true
|
|
246
|
-
else
|
|
247
|
-
return item.incr
|
|
248
|
-
end
|
|
249
|
-
end
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
# set quantity for item (by internal array-id)
|
|
254
|
-
def set_quantity( id, q )
|
|
255
|
-
item = @items[ id.to_i ]
|
|
256
|
-
|
|
257
|
-
return nil if item.nil?
|
|
258
|
-
|
|
259
|
-
q = q.to_i
|
|
260
|
-
if q == 0
|
|
261
|
-
@items.delete_at( id.to_i )
|
|
262
|
-
elsif q > 0
|
|
263
|
-
item.quantity = ( item.inventory.storage < q ) ? item.inventory.storage : q
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
item
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
# delete item from cart (:cart_item_id or :yamlid )
|
|
271
|
-
def del( opts = {} )
|
|
272
|
-
if opts.has_key?( :yamlid )
|
|
273
|
-
@items.delete( get( :yamlid => opts[:yamlid] ) )
|
|
274
|
-
elsif opts.has_key?( :cart_item_id )
|
|
275
|
-
@items.delete_at( opts[:cart_item_id].to_i )
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
# calculate total price
|
|
282
|
-
def total_price
|
|
283
|
-
@items.collect { |x| x.price * x.quantity }.inject(&:+)
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
protected
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
class CartItem
|
|
298
|
-
include Opensteam::Finder
|
|
299
|
-
|
|
300
|
-
@@_load_product_on_init = false
|
|
301
|
-
cattr_accessor :_load_product_on_init
|
|
302
|
-
|
|
303
|
-
attr_reader :yamlid
|
|
304
|
-
|
|
305
|
-
attr_reader :product
|
|
306
|
-
|
|
307
|
-
attr_accessor :quantity
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
#initialize cart-item
|
|
312
|
-
def initialize(id)
|
|
313
|
-
@yamlid = id
|
|
314
|
-
@quantity = 1
|
|
315
|
-
end
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
# increase quantity
|
|
320
|
-
def incr
|
|
321
|
-
if (@quantity + 1 ) > inventory.storage
|
|
322
|
-
return false
|
|
323
|
-
else
|
|
324
|
-
@quantity += 1
|
|
325
|
-
return true
|
|
326
|
-
end
|
|
327
|
-
end
|
|
328
|
-
|
|
329
|
-
# decrease quantity
|
|
330
|
-
def decr
|
|
331
|
-
@quantity -= 1
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
# return product
|
|
335
|
-
def product
|
|
336
|
-
return Opensteam::InventoryBase::Inventory.find( @yamlid ).product
|
|
337
|
-
end
|
|
338
|
-
|
|
69
|
+
alias :clear_cart :wipe_cart
|
|
339
70
|
|
|
340
|
-
# return Inventory Object
|
|
341
|
-
def inventory
|
|
342
|
-
return Opensteam::InventoryBase::Inventory.find( @yamlid )
|
|
343
|
-
end
|
|
344
71
|
|
|
345
|
-
# return price
|
|
346
|
-
def price
|
|
347
|
-
return Opensteam::InventoryBase::Inventory.find( @yamlid ).price
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
private
|
|
351
|
-
def load_product_object
|
|
352
72
|
|
|
73
|
+
def redirect_to_index
|
|
74
|
+
redirect_to opensteam_index_path
|
|
353
75
|
end
|
|
354
76
|
|
|
355
|
-
|
|
356
77
|
end
|
|
357
|
-
|
|
358
|
-
|
|
78
|
+
|
|
359
79
|
end
|
|
360
80
|
|
|
361
81
|
end
|