The cart is maintained per session. session[:cart_id] will have the id of the cart object in that session.
All the paid courses have an add_to_cart link, clicking on which a request is sent to carts_controller create action which adds the course to cart.
add_to_cart_link(item, link_text)
Adding course to cart will insert entries in cart_items table. Duplicate courses are not added to cart.
All the courses in cart preview will have a remove_from_cart link, clicking on which a request is sent to carts_controller destroy action which removes the course from cart.
remove_from_cart_link(item, link_text)
Note - Right now, only courses can be purchased. So, cart_items will save course_id. This can be made polymorphic if we need to purchase more types.
All the orders are processed in orders_controller. orders table saves the billing information and cart id where as the payment information is saved in payments table. Each payment belongs to an order.
The buyer can pay with one of the following ways -
Table name - cart
This groups all cart items added in a single session.
| Column_name | type | Description |
|---|---|---|
| id | integer | primary key |
| created_at | date_time | created date |
| updated_at | date_time | updated date |
Table name - cart_items
| Column_name | type | Description |
|---|---|---|
| id | integer | primary key |
| course_id | integer | foreign key to the courses table. Course which is added to the cart |
| cart_id | integer | foreign key to the carts table. Cart for the current session |
| price | float | The price of the course. |
| created_at | date_time | created date |
| updated_at | date_time | updated date |
Table name - orders
| Column_name | type | Description |
|---|---|---|
| id | integer | primary key |
| user_id | integer | foreign key to the users table. User who has placed this order |
| cart_id | integer | foreign key to the carts table. Cart whose items are ordered |
| account_name | text | |
| country | text | |
| address_1 | text | |
| address_2 | text | |
| town | text | |
| state | text | |
| zip | text | |
| phone_number | text | |
| created_at | date_time | created date |
| updated_at | date_time | updated date |
Note :
Based on the way we are going to handle the tax , the tables carts and orders might need to save the tax information.