Assignment group was graded merit, Assignments of Web Design and Development

Based on the actual presentation and the report, the student presents parts: -Users’ requirements/User Story (page 3-4); ERD (page 5) ;Sitemap (page 4) ; GitHub repository; Images of final application; Demonstrates his/her part in the project and shows the source code and explain how it works (migration, model,table, controller, view, routes ); CRUD of application(order, checkout), relationships between tables;login/ register; authorization; -The student needs to evaluate more about: Implement API/ Javascript; -Individual score: 8, excluding group report score: 8.5 (group report score accounts for 30%)

Typology: Assignments

2022/2023

Uploaded on 09/11/2023

djuc-djao-djinh
djuc-djao-djinh 🇻🇳

1 document

1 / 40

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
WEBG301: Project Web
Submission date
4/29/2023
Date Received 1st submission
Re-submission Date
Date Received 2nd submission
Student Name
Dao Dinh Duc
Student ID
GCH211224
Class
GCH1103
Assessor name
Dinh Duc Manh
Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that
making a false declaration is a form of malpractice.
Student’s signature
Grading grid
Grade (0-10)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28

Partial preview of the text

Download Assignment group was graded merit and more Assignments Web Design and Development in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title WEBG301: Project Web

Submission date 4/29/2023 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Dao Dinh Duc Student ID GCH

Class GCH1103 Assessor name Dinh Duc Manh

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand the consequences of plagiarism. I understand that

making a false declaration is a form of malpractice.

Student’s signature

Grading grid

Grade (0-10)

Summative Feedback:Resubmission Feedback:

Grade: Assessor Signature: Date:

Lecturer Signature:

- Because the user needs to filter products by category, so that they can quickly find products

in specific categories.

- Because the user needs to add products to their shopping, Carts that they can keep track of

products they want to buy.

- Because the user needs to track their orders, so that they can see the status of their orders

and know when to expect their products.

Guest:

- Because the guest needs to see the home page of the store, so that they can view information

about the store and its products.

- Because the guest needs to register an account to become a member, so that they can access

additional features and make purchases.

- Because the guest needs to log in to their account, so that they can access their profile and

shopping cart.

Chapter 2 – System Design

2.1. Site map

FIGURE 1 SITE MAP

2.2. Entity Relationship Diagram

FIGURE 2 ERD

FIGURE 3 DATA TABLE RELATIONSHIP IN MYSQL SERVER (PHP MYADMIN)

$table->timestamps(); ///foreign key $table->foreign('cart_ID')->references('id')->on('carts')- >onDelete('cascade'); $table->foreign('product_ID')->references('id')->on('products')- >onDelete('cascade'); }); } /**

  • Reverse the migrations.
  • @return void */ public function down() { Schema::dropIfExists('cart_product'); } }; First thing after I have designed the data to generate the data for the whole site in the migrations section in the database. It will include all the relevant data like the Figure 3 table. In the data there are defaults including data types, foreign keys, and attributes like onDelete, default(1)... 2.model php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory;

use Illuminate\Database\Eloquent\Model; use App\Models\Category; use App\Models\Order; use App\Models\Cart; class Product extends Model { use HasFactory; protected $table = 'products'; protected $fillable = [ 'name','quantity','image', 'price', 'description' ]; public function categories() { return $this->belongsToMany(Category::class, 'category_product')- >withTimestamps(); } public function orders() { return $this->belongsToMany(Order::class, 'order_product')->withTimestamps()- >withPivot('quantity'); } public function carts() { return $this->belongsToMany(Cart::class, 'order_product')->withTimestamps()- >withPivot('quantity'); } } I will then design the models to hold all the relevant data and return types while using the data in the Controller. Here is an example of how I created the product model and its related data such as belonging, data table to populate and where to get the data.

use App\Models\CartProduct; use App\Models\OrderProduct; use Illuminate\Support\Facades\DB; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Validator; class OrderController extends Controller { /**

  • Display a listing of the resource.
  • @return \Illuminate\Http\Response */ public function index() { $order = Order::all(); return response()->json([ 'success' => true, 'data' => $order, ], 200 ); } public function indexAutoLoadOrders() { // $orders = Order::latest(); $orders = OrderController::getUser()->paginate( 16 ); return view('admin.orders.index', compact('orders')); } public function indexAutoLoad() { // $orders = Order::where('user_ID','=',Auth::user()->id); //check orders and create getOrder to collect data $orders = OrderController::getOrder(Auth::user()->id); return view('profile.order', compact('orders')); }

public function checkout(Request $request) { $user_id = Auth::user()->id; $order['user_ID'] = $user_id; $order['total'] = $request['total']; $order['status'] = 0 ; $cart = Cart::where('user_id', '=', $user_id)->get(); if ($order['total'] != 0 ) { // save order $order = Order::create($order); $cartProducts = CartProduct::where('cart_ID', '=', $cart[ 0 ]->id)->get(); foreach ($cartProducts as $cartProduct) { $orderProduct['order_ID'] = $order['id']; $orderProduct['product_ID'] = $cartProduct['product_ID']; $orderProduct['quantity'] = $cartProduct['quantity']; OrderProduct::create($orderProduct); $cartProduct->delete(); } } return view('cart.detail', compact('cart')); } /**

  • Store a newly created resource in storage.
  • @param \Illuminate\Http\Request $request
  • @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = Validator::make($request->all(), [ 'user_ID' => 'required|exists:users,id', 'total' => 'required|decimal:0,5', 'status' => 'required|decimal:0,5' ]); if ($validator->fails()) { return response()->json([
  • Remove the specified resource from storage.
  • @param int $id
  • @return \Illuminate\Http\Response */ public function destroy(Order $order) { } protected static function getOrder($user_id) { return DB::table('orders')->where('user_id', '=', $user_id)
  • >leftJoin('order_product', 'order_product.order_id', '=', 'orders.id')
  • >leftJoin('products', 'order_product.product_id', '=', 'products.id')
  • >select('order_product.product_id', 'order_product.quantity', 'order_product.order_ID', 'products.name', 'products.price', 'orders.total', 'orders.status')
  • >get(); } protected static function getUser() { return DB::table('orders')
  • >leftJoin('users', 'orders.user_id', '=', 'users.id')
  • >select('orders.id', 'orders.user_ID', 'orders.total', 'orders.status', 'users.address', 'users.phone'); } } In the Order section, I used conditions to check and load related orders. Some tables will use data directly from the database through table concatenation. In addition, in this section, I used to create an item that is checkout, the effect is that after the user clicks on checkout in the author view, all products will be placed in the order. There the order will get important information such as quantity, total price, and create status for the order. B, view order

Back

ID User_ID Address Phone Status {{-- Created At Updated At --}} Action

@foreach ($orders as $order)

{{ $order->id }} {{ $order->user_ID }} {{ $order->address }} {{ $order->phone }}

@if ($order->status == 0 )

Canceled

@endif

@if ($order->status == 0 )

@csrf @method('put')

Confirm Payment

@endif @if ($order->status == 1 )

@csrf @method('put')

Confirm Delivered

@endif

@endforeach

@if ($orders->links())

{{ $orders->links() }}

@endif

After creating the order, the web owner can check to see if there are orders by whom and where. In addition, they can adjust the status and confirm the order has been delivered.

Items: {{ $items }}

Tax (5%): $ {{ $tax = ($total / 100 ) * 5 }}

Total:

{{ $order->total }}

@if ($order->status == 0 )

Pending

@elseif($order->status == 1 )

Accecpted

@elseif($order->status == 2 )

Delivered

@elseif($order->status == 3 )