comable-core 0.7.0.beta2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/comable/address.rb +6 -0
- data/app/models/comable/draft_order.rb +11 -0
- data/app/models/comable/order.rb +12 -2
- data/app/models/comable/order/associations.rb +1 -1
- data/app/models/comable/order/callbacks.rb +6 -1
- data/app/models/comable/order/scopes.rb +3 -2
- data/app/models/comable/order/validations.rb +7 -7
- data/app/models/comable/order_item.rb +3 -3
- data/app/models/comable/payment.rb +5 -1
- data/app/models/comable/product.rb +4 -9
- data/app/models/comable/shipment.rb +5 -1
- data/app/models/comable/user.rb +8 -4
- data/app/models/comable/variant.rb +13 -5
- data/app/models/concerns/comable/checkout.rb +10 -1
- data/config/locales/en.yml +3 -0
- data/config/locales/ja.yml +3 -0
- data/db/migrate/20151112102452_add_draft_to_comable_orders.rb +7 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b21105a8f6d073d7b66ee2dba182428b5008d78
|
4
|
+
data.tar.gz: c3c2f4c865dab49b010d16b658f14d1c0b5605b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da54c6caa5b324b720030516906dbd355f3375bbc54a385f21c3e8fe9ee157e43c2455043132ba71d1a048a48e0f3ad5bbf326c1962193d2550123a3ae152039
|
7
|
+
data.tar.gz: d2a46b412f7182914adf3abca17fcb2b1626f0cca649e255387c342660f5c7a62d548ed4902fb2e8d75bc874f135ad99a8198f28a359eb99e9270f8fcfc25c3e
|
@@ -10,6 +10,12 @@ module Comable
|
|
10
10
|
validates :detail, length: { maximum: 255 }
|
11
11
|
validates :phone_number, length: { maximum: 255 }
|
12
12
|
|
13
|
+
# for Search by ransack
|
14
|
+
# https://github.com/activerecord-hackery/ransack/wiki/using-ransackers#5-search-on-a-concatenated-full-name-from-first_name-and-last_name-several-examples
|
15
|
+
ransacker :full_name do |parent|
|
16
|
+
Arel::Nodes::InfixOperation.new('||', parent.table[:first_name], parent.table[:family_name])
|
17
|
+
end
|
18
|
+
|
13
19
|
class << self
|
14
20
|
def find_or_clone(address)
|
15
21
|
all.to_a.find { |obj| obj.same_as? address } || address.clone
|
data/app/models/comable/order.rb
CHANGED
@@ -26,6 +26,8 @@ module Comable
|
|
26
26
|
delegate :state, :human_state_name, to: :payment, allow_nil: true, prefix: true
|
27
27
|
delegate :cancel!, :resume!, to: :payment, allow_nil: true, prefix: true
|
28
28
|
|
29
|
+
attr_writer :same_as_bill_address
|
30
|
+
|
29
31
|
def complete!
|
30
32
|
ActiveRecord::Base.transaction do
|
31
33
|
run_callbacks :complete do
|
@@ -79,12 +81,12 @@ module Comable
|
|
79
81
|
|
80
82
|
# 時価送料を取得
|
81
83
|
def current_shipment_fee
|
82
|
-
shipments.to_a.sum(&:
|
84
|
+
shipments.to_a.sum(&:current_fee)
|
83
85
|
end
|
84
86
|
|
85
87
|
# Get the current payment fee
|
86
88
|
def current_payment_fee
|
87
|
-
payment.try(:
|
89
|
+
payment.try(:current_fee) || 0
|
88
90
|
end
|
89
91
|
|
90
92
|
# 時価合計を取得
|
@@ -106,6 +108,10 @@ module Comable
|
|
106
108
|
completed_at?
|
107
109
|
end
|
108
110
|
|
111
|
+
def draft?
|
112
|
+
read_attribute(:draft)
|
113
|
+
end
|
114
|
+
|
109
115
|
def paid?
|
110
116
|
payment ? payment.completed? : true
|
111
117
|
end
|
@@ -123,6 +129,10 @@ module Comable
|
|
123
129
|
shipments.with_state(:ready).each(&:ship!)
|
124
130
|
end
|
125
131
|
|
132
|
+
def same_as_bill_address
|
133
|
+
@same_as_bill_address.nil? ? bill_address == ship_address : @same_as_bill_address
|
134
|
+
end
|
135
|
+
|
126
136
|
private
|
127
137
|
|
128
138
|
def current_attributes
|
@@ -12,7 +12,7 @@ module Comable
|
|
12
12
|
has_many :shipments, dependent: :destroy, class_name: Comable::Shipment.name, inverse_of: :order
|
13
13
|
|
14
14
|
accepts_nested_attributes_for :bill_address
|
15
|
-
accepts_nested_attributes_for :ship_address
|
15
|
+
accepts_nested_attributes_for :ship_address, reject_if: :same_as_bill_address
|
16
16
|
accepts_nested_attributes_for :order_items
|
17
17
|
accepts_nested_attributes_for :payment
|
18
18
|
accepts_nested_attributes_for :shipments
|
@@ -6,9 +6,10 @@ module Comable
|
|
6
6
|
included do
|
7
7
|
define_model_callbacks :complete
|
8
8
|
|
9
|
+
before_validation :copy_ship_address_from_bill_address, if: :same_as_bill_address
|
10
|
+
before_validation :generate_code, on: :create
|
9
11
|
before_validation :generate_guest_token, on: :create
|
10
12
|
before_validation :clone_addresses_from_user, on: :create
|
11
|
-
before_complete :generate_code
|
12
13
|
after_complete :clone_addresses_to_user
|
13
14
|
end
|
14
15
|
|
@@ -38,6 +39,10 @@ module Comable
|
|
38
39
|
user.update_bill_address_by bill_address
|
39
40
|
user.update_ship_address_by ship_address
|
40
41
|
end
|
42
|
+
|
43
|
+
def copy_ship_address_from_bill_address
|
44
|
+
self.ship_address = bill_address
|
45
|
+
end
|
41
46
|
end
|
42
47
|
end
|
43
48
|
end
|
@@ -5,12 +5,13 @@ module Comable
|
|
5
5
|
|
6
6
|
included do
|
7
7
|
scope :complete, -> { where.not(completed_at: nil) }
|
8
|
-
scope :incomplete, -> { where(completed_at: nil) }
|
8
|
+
scope :incomplete, -> { where(completed_at: nil).where(draft: false) }
|
9
9
|
scope :by_user, -> (user) { where(user_id: user) }
|
10
|
+
scope :draft, -> { where(draft: true) }
|
10
11
|
scope :this_month, -> { where(completed_at: Time.now.beginning_of_month..Time.now.end_of_month) }
|
11
12
|
scope :this_week, -> { where(completed_at: Time.now.beginning_of_week..Time.now.end_of_week) }
|
12
13
|
scope :last_week, -> { where(completed_at: 1.week.ago.beginning_of_week..1.week.ago.end_of_week) }
|
13
|
-
scope :recent, -> { order('completed_at DESC, id DESC') }
|
14
|
+
scope :recent, -> { order('completed_at DESC, created_at DESC, id DESC') }
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
@@ -4,31 +4,31 @@ module Comable
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
validates :
|
7
|
+
validates :code, presence: true
|
8
|
+
validates :user_id, uniqueness: { scope: :completed_at }, if: -> { user && !draft }
|
8
9
|
validates :guest_token, presence: true, uniqueness: { scope: :completed_at }, unless: :user
|
9
10
|
|
10
|
-
with_options if: -> { stated?(:cart) } do |context|
|
11
|
+
with_options if: -> { stated?(:cart) || draft? } do |context|
|
11
12
|
context.validates :email, presence: true, length: { maximum: 255 }
|
12
13
|
end
|
13
14
|
|
14
|
-
with_options if: -> { stated?(:orderer) } do |context|
|
15
|
+
with_options if: -> { stated?(:orderer) || draft? } do |context|
|
15
16
|
context.validates :bill_address, presence: true
|
16
17
|
end
|
17
18
|
|
18
|
-
with_options if: -> { stated?(:delivery) } do |context|
|
19
|
+
with_options if: -> { stated?(:delivery) || draft? } do |context|
|
19
20
|
context.validates :ship_address, presence: true
|
20
21
|
end
|
21
22
|
|
22
|
-
with_options if: -> { stated?(:shipment) && shipment_required? } do |context|
|
23
|
+
with_options if: -> { (stated?(:shipment) || draft?) && shipment_required? } do |context|
|
23
24
|
context.validates :shipments, presence: true
|
24
25
|
end
|
25
26
|
|
26
|
-
with_options if: -> { stated?(:payment) && payment_required? } do |context|
|
27
|
+
with_options if: -> { (stated?(:payment) || draft?) && payment_required? } do |context|
|
27
28
|
context.validates :payment, presence: true
|
28
29
|
end
|
29
30
|
|
30
31
|
with_options if: -> { stated?(:confirm) } do |context|
|
31
|
-
context.validates :code, presence: true
|
32
32
|
context.validates :payment_fee, presence: true
|
33
33
|
context.validates :shipment_fee, presence: true
|
34
34
|
context.validates :total_price, presence: true
|
@@ -14,8 +14,8 @@ module Comable
|
|
14
14
|
|
15
15
|
liquid_methods :name, :name_with_sku, :code, :quantity, :price, :subtotal_price
|
16
16
|
|
17
|
-
delegate :product, to: :variant
|
18
|
-
delegate :image_url, to: :product
|
17
|
+
delegate :product, to: :variant, allow_nil: true
|
18
|
+
delegate :image_url, to: :product, allow_nil: true
|
19
19
|
delegate :guest_token, to: :order
|
20
20
|
delegate :completed?, to: :order, allow_nil: true
|
21
21
|
|
@@ -42,7 +42,7 @@ module Comable
|
|
42
42
|
|
43
43
|
# 売価小計を取得
|
44
44
|
def subtotal_price
|
45
|
-
price * quantity
|
45
|
+
price * quantity if price
|
46
46
|
end
|
47
47
|
|
48
48
|
def unstocked?
|
@@ -72,6 +72,10 @@ module Comable
|
|
72
72
|
touch :completed_at
|
73
73
|
end
|
74
74
|
|
75
|
+
def current_fee
|
76
|
+
payment_method.try(:fee) || 0
|
77
|
+
end
|
78
|
+
|
75
79
|
private
|
76
80
|
|
77
81
|
def order_completed?
|
@@ -80,7 +84,7 @@ module Comable
|
|
80
84
|
|
81
85
|
def copy_attributes_from_payment_method
|
82
86
|
self.attributes = {
|
83
|
-
fee:
|
87
|
+
fee: current_fee
|
84
88
|
}
|
85
89
|
end
|
86
90
|
end
|
@@ -7,7 +7,7 @@ module Comable
|
|
7
7
|
include Comable::Product::Csvable
|
8
8
|
|
9
9
|
has_many :variants, class_name: Comable::Variant.name, inverse_of: :product, dependent: :destroy
|
10
|
-
has_many :images, class_name: Comable::Image.name, dependent: :destroy
|
10
|
+
has_many :images, -> { order(:id) }, class_name: Comable::Image.name, dependent: :destroy
|
11
11
|
has_and_belongs_to_many :categories, class_name: Comable::Category.name, join_table: :comable_products_categories
|
12
12
|
|
13
13
|
accepts_nested_attributes_for :variants, allow_destroy: true
|
@@ -24,12 +24,6 @@ module Comable
|
|
24
24
|
|
25
25
|
PREVIEW_SESSION_KEY = :preview_product
|
26
26
|
|
27
|
-
# Add conditions for the images association.
|
28
|
-
# Override method of the images association to support Rails 3.x.
|
29
|
-
def images
|
30
|
-
super.order(:id)
|
31
|
-
end
|
32
|
-
|
33
27
|
def image_url
|
34
28
|
image = images.first
|
35
29
|
return image.url if image
|
@@ -56,8 +50,9 @@ module Comable
|
|
56
50
|
option_types.empty?
|
57
51
|
end
|
58
52
|
|
59
|
-
def as_json(options =
|
60
|
-
|
53
|
+
def as_json(options = {})
|
54
|
+
options[:include] = { variants: { except: :product, methods: [:quantity, :option_names] } }
|
55
|
+
super
|
61
56
|
end
|
62
57
|
|
63
58
|
def sku_h_item_name
|
@@ -91,6 +91,10 @@ module Comable
|
|
91
91
|
shipment_method.try(:name) || Comable.t(:normal_shipment)
|
92
92
|
end
|
93
93
|
|
94
|
+
def current_fee
|
95
|
+
shipment_method.try(:fee) || 0
|
96
|
+
end
|
97
|
+
|
94
98
|
private
|
95
99
|
|
96
100
|
def order_completed?
|
@@ -99,7 +103,7 @@ module Comable
|
|
99
103
|
|
100
104
|
def copy_attributes_from_shipment_method
|
101
105
|
self.attributes = {
|
102
|
-
fee:
|
106
|
+
fee: current_fee
|
103
107
|
}
|
104
108
|
end
|
105
109
|
end
|
data/app/models/comable/user.rb
CHANGED
@@ -57,10 +57,6 @@ module Comable
|
|
57
57
|
!new_record?
|
58
58
|
end
|
59
59
|
|
60
|
-
def not_signed_in?
|
61
|
-
!signed_in?
|
62
|
-
end
|
63
|
-
|
64
60
|
# TODO: Add a test case
|
65
61
|
def reload(*_)
|
66
62
|
super.tap do
|
@@ -92,6 +88,14 @@ module Comable
|
|
92
88
|
"##{id}"
|
93
89
|
end
|
94
90
|
|
91
|
+
def text
|
92
|
+
bill_address ? "#{bill_full_name} (#{email})" : email
|
93
|
+
end
|
94
|
+
|
95
|
+
def as_json(options = {})
|
96
|
+
super options.merge(include: [:bill_address, :ship_address], methods: [:text])
|
97
|
+
end
|
98
|
+
|
95
99
|
private
|
96
100
|
|
97
101
|
def current_guest_token
|
@@ -20,6 +20,7 @@ module Comable
|
|
20
20
|
scope :by_newest, -> { reorder(created_at: :desc) }
|
21
21
|
|
22
22
|
alias_method :quantity, :total_quantity
|
23
|
+
delegate :image_url, to: :product
|
23
24
|
|
24
25
|
def quantity=(quantity)
|
25
26
|
fail 'Stocks are already exists!' if stocks.any?
|
@@ -49,11 +50,18 @@ module Comable
|
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
53
|
+
alias_method :text, :name
|
54
|
+
|
55
|
+
def option_names
|
56
|
+
option_values.map(&:name)
|
57
|
+
end
|
58
|
+
|
59
|
+
def as_json(options = {})
|
60
|
+
options = {
|
61
|
+
include: { product: { except: :variants } },
|
62
|
+
methods: [:text, :quantity, :option_names, :image_url]
|
63
|
+
}
|
64
|
+
super
|
57
65
|
end
|
58
66
|
end
|
59
67
|
end
|
@@ -3,7 +3,11 @@ module Comable
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
state_machine initial: :cart do
|
6
|
+
state_machine initial: -> (order) { order.draft? ? :draft : :cart } do
|
7
|
+
# for Draft Order
|
8
|
+
state :draft
|
9
|
+
|
10
|
+
# for Normal Order
|
7
11
|
state :cart
|
8
12
|
state :orderer
|
9
13
|
state :delivery
|
@@ -24,6 +28,11 @@ module Comable
|
|
24
28
|
transition :confirm => :completed
|
25
29
|
end
|
26
30
|
|
31
|
+
event :next_draft_state do
|
32
|
+
transition :draft => :shipment, if: :shipment_required?
|
33
|
+
transition all => :completed
|
34
|
+
end
|
35
|
+
|
27
36
|
event :cancel do
|
28
37
|
transition to: :canceled, from: [:completed, :resumed], if: :allow_cancel?
|
29
38
|
end
|
data/config/locales/en.yml
CHANGED
@@ -173,9 +173,11 @@ en:
|
|
173
173
|
add_variants: 'Add variants'
|
174
174
|
size: 'Size'
|
175
175
|
add_stocks: 'Add stocks'
|
176
|
+
user: 'User'
|
176
177
|
nav:
|
177
178
|
dashboard: 'Dashboard'
|
178
179
|
order: 'Orders'
|
180
|
+
draft_order: 'Draft Orders'
|
179
181
|
product: 'Products'
|
180
182
|
stock: 'Stocks'
|
181
183
|
category: 'Categories'
|
@@ -334,6 +336,7 @@ en:
|
|
334
336
|
guest_token: 'Guest token'
|
335
337
|
payment_state: 'Payment state'
|
336
338
|
shipment_state: 'Shipment state'
|
339
|
+
same_as_bill_address: 'Same as the billing address'
|
337
340
|
<<: *timestamps
|
338
341
|
comable/order_item: &comable_order_item
|
339
342
|
quantity: *quantity
|
data/config/locales/ja.yml
CHANGED
@@ -173,9 +173,11 @@ ja:
|
|
173
173
|
add_variants: 'バリエーションを追加する'
|
174
174
|
size: 'サイズ'
|
175
175
|
add_stocks: '在庫を追加する'
|
176
|
+
user: 'ユーザー'
|
176
177
|
nav:
|
177
178
|
dashboard: ダッシュボード
|
178
179
|
order: 注文管理
|
180
|
+
draft_order: '下書き注文'
|
179
181
|
product: 商品管理
|
180
182
|
stock: 在庫管理
|
181
183
|
category: カテゴリ
|
@@ -334,6 +336,7 @@ ja:
|
|
334
336
|
guest_token: ゲストトークン
|
335
337
|
payment_state: '決済ステータス'
|
336
338
|
shipment_state: '配送ステータス'
|
339
|
+
same_as_bill_address: '請求先と同じ住所を利用する'
|
337
340
|
<<: *timestamps
|
338
341
|
comable/order_item: &comable_order_item
|
339
342
|
quantity: *quantity
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comable-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.0
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- YOSHIDA Hiroki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -287,6 +287,7 @@ files:
|
|
287
287
|
- app/models/comable/ability.rb
|
288
288
|
- app/models/comable/address.rb
|
289
289
|
- app/models/comable/category.rb
|
290
|
+
- app/models/comable/draft_order.rb
|
290
291
|
- app/models/comable/image.rb
|
291
292
|
- app/models/comable/inventory/adjuster.rb
|
292
293
|
- app/models/comable/inventory/coordinator.rb
|
@@ -373,6 +374,7 @@ files:
|
|
373
374
|
- db/migrate/20151012143215_create_comable_shipment_items.rb
|
374
375
|
- db/migrate/20151013082845_remove_null_option_of_shipment_method_id_on_comable_shipments.rb
|
375
376
|
- db/migrate/20151013194926_add_guest_token_index_to_comable_orders.rb
|
377
|
+
- db/migrate/20151112102452_add_draft_to_comable_orders.rb
|
376
378
|
- db/seeds.rb
|
377
379
|
- db/seeds/comable/users.rb
|
378
380
|
- lib/comable/core.rb
|
@@ -403,9 +405,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
403
405
|
version: 2.1.5
|
404
406
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
405
407
|
requirements:
|
406
|
-
- - "
|
408
|
+
- - ">="
|
407
409
|
- !ruby/object:Gem::Version
|
408
|
-
version:
|
410
|
+
version: '0'
|
409
411
|
requirements: []
|
410
412
|
rubyforge_project:
|
411
413
|
rubygems_version: 2.4.5
|