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
13bf393f
Commit
13bf393f
authored
Apr 19, 2018
by
ivan Lan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow merchant to modify spec_rewrite
parent
5e976c3e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
12 deletions
+27
-12
1_create_shotengai_products_and_orders.rb
db/migrate/1_create_shotengai_products_and_orders.rb
+4
-3
product_snapshots_controller.rb
...engai/controller/merchant/product_snapshots_controller.rb
+13
-1
json_column.rb
lib/shotengai/json_column.rb
+10
-8
No files found.
db/migrate/1_create_shotengai_products_and_orders.rb
View file @
13bf393f
...
...
@@ -89,9 +89,10 @@ class CreateShotengaiProductsAndOrders < ActiveRecord::Migration[5.1]
# Single Table Inheritance
t
.
string
:type
t
.
json
:meta
t
.
json
:spec_value
t
.
json
:remark_value
t
.
json
:info_value
t
.
json
:spec_value
t
.
json
:spec_rewrite
t
.
json
:remark_value
t
.
json
:info_value
t
.
references
:shotengai_series
,
foreign_key:
true
t
.
references
:shotengai_order
,
foreign_key:
true
...
...
lib/shotengai/controller/merchant/product_snapshots_controller.rb
View file @
13bf393f
...
...
@@ -6,7 +6,6 @@ module Shotengai
self
.
template_dir
=
'shotengai/merchant/snapshots/'
remove_actions
:create
,
:destroy
before_action
:edit_only_unpaid
,
only: :update
def
default_query
resources
resources
.
in_order
...
...
@@ -20,6 +19,15 @@ module Shotengai
)
end
def
update
@resource
.
class
.
transaction
do
@resource
.
attributes
=
resource_params
@resource
.
has_changes_to_save?
&&
edit_only_unpaid
@resource
.
update_columns
(
rewrite_params
.
to_h
)
# skip validation
end
head
200
end
private
def
resource_params
remark_value
=
params
.
require
(
resource_key
).
fetch
(
:remark_value
,
{}).
permit!
...
...
@@ -28,6 +36,10 @@ module Shotengai
).
merge
(
remark_value:
remark_value
)
end
def
rewrite_params
params
.
require
(
resource_key
).
permit
(
spec_rewrite:
{})
end
def
edit_only_unpaid
raise
Shotengai
::
WebError
.
new
(
'订单已支付,不可修改该快照。'
,
'-1'
,
403
)
unless
@resource
.
order
.
unpaid?
end
...
...
lib/shotengai/json_column.rb
View file @
13bf393f
...
...
@@ -36,20 +36,22 @@ module Shotengai
def
template_with_value
key
,
value:
"
#{
key
}
_value"
,
template:
"
#{
key
}
_template"
,
trans:
nil
,
trans_to: :en
trans_result
=
trans
.
is_a?
(
Hash
)
?
%Q{
#{
trans_to
}
_value: val&.reduce({}) do |o, obj|
trans =
#{
trans
}
val = obj[1].is_a?(Array) ? obj[1].map{ |x| trans[x] } : trans[ obj[1] ]
o.merge( obj[0] => val )
end
}
:
{}
{
#{
trans_to
}
_value: val&.reduce({}) do |o, obj|
trans =
#{
trans
}
val = obj[1].is_a?(Array) ? obj[1].map{ |x| trans[x] } : trans[ obj[1] ]
o.merge( obj[0] => val )
end
}
}
:
'{}'
class_eval
%Q{
def
#{
key
}
val =
#{
value
}
.is_a?(Harray) ?
#{
value
}
.decode :
#{
value
}
{
template: Shotengai::Harray.encode(
#{
template
}
).keys,
value: val,
}.merge(
#{
trans_result
}
)
}.merge(
#{
trans_result
}
)
.merge(try(:
#{
key
}
_rewrite) || {})
end
}
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