Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
dhp-venshop
Overview
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
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Hoang Phuc Do
dhp-venshop
Commits
74200a58
Commit
74200a58
authored
Jun 19, 2017
by
Hoang Phuc Do
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Order template for user
parent
c2d0a2b6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
14 additions
and
1 deletions
+14
-1
app/models/order.rb
+7
-0
db/migrate/20170619091633_add_order_status_to_orders.rb
+5
-0
db/schema.rb
+2
-1
No files found.
app/models/order.rb
View file @
74200a58
class
Order
<
ApplicationRecord
has_many
:product_items
,
dependent: :destroy
belongs_to
:user
after_save
:set_default_order_status
enum
order_status:
{
pending:
0
,
done:
1
}
def
total_price
product_items
.
to_a
.
sum
{
|
item
|
item
.
product
.
price
*
item
.
quantity
}
end
def
set_default_order_status
update_attribute
(
:order_status
,
0
)
end
end
\ No newline at end of file
db/migrate/20170619091633_add_order_status_to_orders.rb
0 → 100644
View file @
74200a58
class
AddOrderStatusToOrders
<
ActiveRecord
::
Migration
[
5.1
]
def
change
add_column
:orders
,
:order_status
,
:integer
end
end
db/schema.rb
View file @
74200a58
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2017061
5035827
)
do
ActiveRecord
::
Schema
.
define
(
version:
2017061
9091633
)
do
create_table
"categories"
,
force: :cascade
,
options:
"ENGINE=InnoDB DEFAULT CHARSET=utf8"
do
|
t
|
t
.
string
"title"
...
...
@@ -21,6 +21,7 @@ ActiveRecord::Schema.define(version: 20170615035827) do
t
.
bigint
"user_id"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
integer
"order_status"
t
.
index
[
"user_id"
],
name:
"index_orders_on_user_id"
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