Voivodeship and country for orders

This commit is contained in:
Adrian Hinz 2018-06-05 09:15:41 +02:00
parent 3ef5187b03
commit d289397f40
5 changed files with 34 additions and 6 deletions

View File

@ -75,6 +75,7 @@ class CheckoutController < ShopController
def order_params
params.require(:order)
.permit(:email, :message_from_client, :terms_of_service_acceptance,
:first_name, :last_name, :phone, :street, :city, :zip_code)
:first_name, :last_name, :phone, :street, :city, :zip_code,
:voivodeship, :country, :shipping_id)
end
end

View File

@ -43,6 +43,12 @@ class Order < ApplicationRecord
7 => '<span class="badge bg-orange-active">Anulowane</span>'
}.freeze
VOIVOIDSHIPS = ['dolnośląskie', 'kujawsko-pomorskie', 'lubelskie', 'lubuskie',
'łódzkie', 'małopolskie', 'mazowieckie', 'opolskie',
'podkarpackie', 'podlaskie', 'pomorskie', 'śląskie',
'świętokrzyskie', 'warmińsko-mazurskie', 'wielkopolskie',
'zachodniopomorskie'].freeze
def order_summary
order_value + shipping.price
end
@ -80,7 +86,8 @@ class Order < ApplicationRecord
end
def address
"#{street}\n#{zip_code} #{city}\n\ntel: #{phone}"
"#{street}\n#{zip_code} #{city}\n"\
"woj. #{voivodeship}\n#{country}\n\ntel: #{phone}"
end
def order_value

View File

@ -61,10 +61,20 @@
<!-- end col -->
</div>
<!-- end row -->
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label>Województwo: </label>
</div>
</div>
<div class="col-sm-9">
<div class="form-group">
<%= select(:order, :voivodeship, options_for_select(Order::VOIVOIDSHIPS), {}, {class: 'form-control'}) %>
</div>
</div>
</div>
<div class="form-group">
<select class="form-control">
<option value="pl">Polska</option>
</select>
<%= select(:order, :country, options_for_select(['Polska']), {}, {class: 'form-control'}) %>
</div>
</div>

View File

@ -0,0 +1,6 @@
class AddVoivodeshipAndCountryToOrder < ActiveRecord::Migration[5.1]
def change
add_column :orders, :voivodeship, :string, after: 'zip_code'
add_column :orders, :country, :string, after: 'voivodeship'
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180119145343) do
ActiveRecord::Schema.define(version: 20180605061228) do
create_table "admins", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_polish_ci" do |t|
t.string "email", default: "", null: false
@ -157,6 +157,7 @@ ActiveRecord::Schema.define(version: 20180119145343) do
end
create_table "orders", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.integer "order_number"
t.bigint "cart_id", null: false
t.integer "shipping_id"
t.integer "payment_method_id"
@ -168,6 +169,8 @@ ActiveRecord::Schema.define(version: 20180119145343) do
t.string "street"
t.string "city", limit: 80
t.string "zip_code", limit: 10
t.string "voivodeship"
t.string "country"
t.text "message_from_client"
t.integer "status", default: 0, null: false
t.datetime "created_at"
@ -239,6 +242,7 @@ ActiveRecord::Schema.define(version: 20180119145343) do
t.text "index_page_second_info", limit: 4294967295
t.text "index_page_content", limit: 4294967295
t.text "shop_owners_emails"
t.boolean "recaptcha_chk", default: false, null: false
t.datetime "updated_at"
t.integer "updated_by"
end