Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shotengai
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
shotengai
Commits
30aac4aa
Commit
30aac4aa
authored
Aug 29, 2017
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix Cart & Finish Customer Snapshot Controller
parent
88461037
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
14 deletions
+66
-14
_snapshot.json.jbuilder
lib/generators/templates/views/share/_snapshot.json.jbuilder
+3
-3
_snapshot_simple.json.jbuilder
...tors/templates/views/share/_snapshot_simple.json.jbuilder
+3
-3
cart.rb
lib/shotengai/cart.rb
+2
-2
product_snapshots_controller.rb
...ngai/controllers/customer/product_snapshots_controller.rb
+46
-0
product_snapshots_controller.rb
...ngai/controllers/merchant/product_snapshots_controller.rb
+6
-6
snapshot.rb
lib/shotengai/snapshot.rb
+6
-0
No files found.
lib/generators/templates/views/share/_snapshot.json.jbuilder
View file @
30aac4aa
json.extract! snapshot, :id, :original_price, :price, :count,
json.extract! snapshot, :id, :
shotengai_series_id, :
original_price, :price, :count,
:product_status_zh, :order_status_zh, :product_status, :order_status,
:total_price, :total_original_price, :revised_amount,
:spec, :cover_image, :banners, :detail, :meta
\ No newline at end of file
:spec, :cover_image, :banners, :detail, :meta, :is_in_cart
\ No newline at end of file
lib/generators/templates/views/share/_snapshot_simple.json.jbuilder
View file @
30aac4aa
json.extract! snapshot, :id, :original_price, :price, :count,
json.extract! snapshot, :id, :
shotengai_series_id, :
original_price, :price, :count,
:product_status_zh, :order_status_zh, :product_status, :order_status,
:total_price, :total_original_price, :revised_amount,
:spec, :cover_image, :meta
\ No newline at end of file
:spec, :cover_image, :meta, :is_in_cart
\ No newline at end of file
lib/shotengai/cart.rb
View file @
30aac4aa
...
...
@@ -41,11 +41,11 @@ module Shotengai
# 所有snapshot
has_many
:snapshots
,
->
{
where
(
type:
good_classes
.
map
{
|
good_class
|
"
#{
good_class
.
name
}
Snapshot"
})
},
class_name:
'Shotengai::Snapshot'
},
class_name:
'Shotengai::Snapshot'
,
foreign_key: :shotengai_order_id
good_classes
.
each
do
|
klass
|
# cart has many good_class.collection
has_many
klass
.
model_name
.
collection
.
to_sym
,
class_name:
klass
.
name
has_many
klass
.
model_name
.
collection
.
to_sym
,
class_name:
klass
.
name
,
foreign_key: :shotengai_order_id
# belongs_to 本 Cart class
# optional: true 允许父对象不存在
klass
.
snapshot_class
.
belongs_to
(
...
...
lib/shotengai/controllers/customer/product_snapshots_controller.rb
0 → 100644
View file @
30aac4aa
module
Shotengai
module
Controller
module
Customer
class
ProductSnapshotsController
<
Shotengai
::
Controller
::
Base
self
.
resources
=
ProductSnapshot
self
.
template_dir
=
'shotengai/merchant/snapshots/'
before_action
:edit_only_unpaid
,
only:
[
:update
,
:destroy
]
default_query
do
|
resource
,
params
|
# /orders/:order_id/snapshots
# /series/:series_id/snapshots
resource
.
where
(
params
[
:order_id
]
&&
{
shotengai_order_id:
params
[
:order_id
]
}
).
where
(
params
[
:series_id
]
&&
{
shotengai_series_id:
params
[
:series_id
]
}
)
end
index_query
do
|
resource
,
params
|
params
[
:in_cart
]
?
resource
.
in_cart
:
resource
.
in_order
end
def
create
buyer_type
,
buyer_id
=
resource_params
.
values_at
(
:buy_type
,
:buyer_id
)
@buyer
=
buyer_type
.
constantize
.
find
(
buyer_id
)
if
buyer_type
&&
buyer_id
@resource
=
default_resources
.
create!
(
resource_params
.
merge
(
buyer:
buyer
)
)
respond_with
@resource
,
template:
"
#{
@@template_dir
}
/show"
,
status:
201
end
private
def
resource_params
params
.
require
(
resource_key
).
permit
(
:count
,
:shotengai_series_id
,
:buyer_id
,
:buy_type
)
end
def
edit_only_unpaid
raise
Shotengai
::
WebError
.
new
(
'订单已支付,不可修改。'
,
'-1'
,
403
)
unless
@resource
.
order
.
unpaid?
end
end
end
end
end
lib/shotengai/controllers/merchant/product_snapshots_controller.rb
View file @
30aac4aa
...
...
@@ -6,7 +6,8 @@ module Shotengai
self
.
template_dir
=
'shotengai/merchant/snapshots/'
remove_actions
:create
,
:destroy
before_action
:edit_only_unpaid
,
only: :update
default_query
do
|
resource
,
params
|
resource
.
in_order
end
...
...
@@ -19,17 +20,16 @@ module Shotengai
)
end
def
update
raise
Shotengai
::
WebError
.
new
(
'订单已支付,不可修改。'
,
'-1'
,
403
)
unless
@resource
.
order
.
unpaid?
super
end
private
def
resource_params
params
.
require
(
resource_key
).
permit
(
:revised_amount
)
end
def
edit_only_unpaid
raise
Shotengai
::
WebError
.
new
(
'订单已支付,不可修改。'
,
'-1'
,
403
)
unless
@resource
.
order
.
unpaid?
end
end
end
end
...
...
lib/shotengai/snapshot.rb
View file @
30aac4aa
...
...
@@ -33,6 +33,8 @@ module Shotengai
belongs_to
:shotengai_order
,
foreign_key: :shotengai_order_id
,
class_name:
'Shotengai::Order'
,
optional:
true
belongs_to
:shotengai_cart
,
foreign_key: :shotengai_order_id
,
class_name:
'Shotengai::Cart'
,
optional:
true
scope
:in_order
,
->
{
joins
(
"
...
...
@@ -92,6 +94,10 @@ module Shotengai
count
*
original_price
end
def
is_in_cart
shotengai_cart
&
.
status
==
'cart'
end
def
product_status
;
series
.
status
end
def
product_status_zh
;
series
.
status_zh
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment