Class: ShopModelFunctionsMigration

Inherits:
Migration
  • Object
show all
Defined in:
lib/migrations/08_shop_model_functions.rb

Class Method Summary collapse

Class Method Details

.down(site) ⇒ Object



35
36
# File 'lib/migrations/08_shop_model_functions.rb', line 35

def self.down(site)
end

.up(site) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/migrations/08_shop_model_functions.rb', line 2

def self.up(site)
  site.products.modify do |products|
    add_field :total_cost, :function, fn: 'sum(price, shipping, tax)'
  end
  
  site.product_holds.modify do |products|
    add_field :total_cost, :function, fn: 'multiply(product.total_cost, quantity)'
  end
  
  site.carts.modify do |carts|
    add_field :total_cost, :function, fn: 'product_holds.sum(total_cost)'
  end
  
  site.transactions.modify do |transactions|
    remove_field :product_total
    remove_field :shipping_total
    remove_field :tax_total
    remove_field :total
    
    modify_field :shipping_address do |shipping_address|
      remove_field :name
      add_field :first_name, :string
      add_field :last_name, :string
    end
    
    modify_field :billing_address do |billing_address|
      remove_field :name
      add_field :first_name, :string
      add_field :last_name, :string
    end
  end
end