Commit a05fc5956ec9889a3fe0d3a569092d22aebf034b
1 parent
205a1ade
Exists in
master
and in
28 other branches
[purchase-order] Basics of shopping-cart order register
Co-authored-by: Aurélio A. Heckert <aurelio@colivre.coop.br> (ActionItem2062)
Showing
5 changed files
with
65 additions
and
0 deletions
Show diff stats
plugins/shopping_cart/db/migrate/20110825173657_create_purchase_order.rb
0 → 100644
| ... | ... | @@ -0,0 +1,15 @@ |
| 1 | +class CreatePurchaseOrder < ActiveRecord::Migration | |
| 2 | + def self.up | |
| 3 | + create_table :shopping_cart_plugin_purchase_orders do |t| | |
| 4 | + t.references :customer | |
| 5 | + t.references :seller | |
| 6 | + t.text :data | |
| 7 | + t.integer :status | |
| 8 | + t.timestamps | |
| 9 | + end | |
| 10 | + end | |
| 11 | + | |
| 12 | + def self.down | |
| 13 | + drop_table :shopping_cart_plugin_purchase_order | |
| 14 | + end | |
| 15 | +end | ... | ... |
plugins/shopping_cart/lib/shopping_cart_plugin.rb
plugins/shopping_cart/lib/shopping_cart_plugin/purchase_order.rb
0 → 100644
| ... | ... | @@ -0,0 +1,37 @@ |
| 1 | +class ShoppingCartPlugin::PurchaseOrder < Noosfero::Plugin::ActiveRecord | |
| 2 | + | |
| 3 | + belongs_to :customer, :class_name => "Profile" | |
| 4 | + belongs_to :seller, :class_name => "Profile" | |
| 5 | + | |
| 6 | + validates_presence_of :status, :seller | |
| 7 | + | |
| 8 | + acts_as_having_settings :field => :data | |
| 9 | + | |
| 10 | + settings_items :products_list, :type => Array, :default => {} | |
| 11 | + settings_items :customer_name, :type => String | |
| 12 | + settings_items :customer_email, :type => String | |
| 13 | + settings_items :customer_contact_phone, :type => String | |
| 14 | + settings_items :customer_address, :type => String | |
| 15 | + settings_items :customer_city, :type => String | |
| 16 | + settings_items :customer_zip_code, :type => String | |
| 17 | + | |
| 18 | + before_create do |order| | |
| 19 | + order.created_at = Time.now.utc | |
| 20 | + order.updated_at = Time.now.utc | |
| 21 | + end | |
| 22 | + | |
| 23 | + before_update do |order| | |
| 24 | + order.updated_at = Time.now.utc | |
| 25 | + end | |
| 26 | + | |
| 27 | + module Status | |
| 28 | + OPENED = 0 | |
| 29 | + CANCELED = 1 | |
| 30 | + CONFIRMED = 2 | |
| 31 | + SHIPPED = 3 | |
| 32 | + | |
| 33 | + def self.name | |
| 34 | + [_('Opened'), _('Canceled'), _('Confirmed'), _('Shipped')] | |
| 35 | + end | |
| 36 | + end | |
| 37 | +end | ... | ... |