diff --git a/Dockerfile b/Dockerfile index 9ef737b105279fa8e77508b757ee207b3de5286d..b28b7d0321a443f379cd838c538800b86b851fea 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,4 +4,7 @@ COPY src/. /var/www/html RUN docker-php-ext-install mysqli RUN a2enmod rewrite RUN apt-get -y update && apt-get -y upgrade +RUN apt-get update && \ + apt-get install -y libxml2-dev +RUN docker-php-ext-install soap EXPOSE 8080 \ No newline at end of file diff --git a/src/components/cart/Cart.php b/src/components/cart/Cart.php index 445572302e99a112c5d4d5d58868407bfc622a3d..6a3c9342bf12d54db39297cc85e508dd9f1832de 100644 --- a/src/components/cart/Cart.php +++ b/src/components/cart/Cart.php @@ -76,6 +76,7 @@ <button type="submit">Continue Shopping</button> </form> <form action="/Checkout" method="POST"> + <textarea name="alamat" id="" cols="30" rows="10" placeholder="Masukkan alamat disini" required></textarea> <button class="checkout-btn">Checkout</button> </form> </div> diff --git a/src/components/template/Navbar.php b/src/components/template/Navbar.php index c77ade18d026b1326baa4b0f3713b8acce1d70b4..aa7d8b82207006c6f07c12de561e9045a68424d2 100644 --- a/src/components/template/Navbar.php +++ b/src/components/template/Navbar.php @@ -16,6 +16,7 @@ $title = str_replace('.php', '', $title); <?php elseif ($this->userRole === 1) : ?> <!-- Display "Cart", "Profile", and "Log out" when logged in as a user --> <li <?php if ($title == "cart") echo 'aria-current="page"'; ?>><a href="/cart">Cart</a></li> + <li <?php if ($title == "track") echo 'aria-current="page"'; ?>><a href="/track">track</a></li> <li <?php if ($title == "profile") echo 'aria-current="page"'; ?>><a href="/profile">Profile</a></li> <li <?php if ($title == "history") echo 'aria-current="page"'; ?>><a href="/history">History</a></li> <li><a href="/logout">Log out</a></li> diff --git a/src/components/track/Track.php b/src/components/track/Track.php new file mode 100644 index 0000000000000000000000000000000000000000..79037b2304b6b433c5d3a46cb44d9f1907186cc6 --- /dev/null +++ b/src/components/track/Track.php @@ -0,0 +1,44 @@ +<!DOCTYPE html> +<html lang="en"> + +<head> + <meta charset="UTF-8"> + <title>Tracking</title> + <link rel="stylesheet" href="../../styles/Global.css"> + <link rel="stylesheet" href="../../styles/history/History.css"> + <link rel="stylesheet" href="../../styles/history/HistoryCard.css"> +</head> + +<body> + <?php + include(dirname(__DIR__) . '/template/Navbar.php'); + ?> + <div> + <h1>Tracking pesananmu</h1> + + <span class="background"> + <span class="centering"> + <ul> + <?php + include_once(dirname(__DIR__) . "/template/HistoryCard.php"); + + ?> + <section class="articles"> + <?php + $index = 1; + foreach ($this->data['pesanan'] as $pesanan) { + history_card_template( + "Pesanan".$index, + $pesanan['price'], + $pesanan['status'], + $pesanan['id']); + $index++; + } + ?> + </section> + </ul> + </span> + </span> + </div> +</body> +</html> \ No newline at end of file diff --git a/src/components/track/TrackDetail.php b/src/components/track/TrackDetail.php new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/src/controller/cart/CheckoutController.php b/src/controller/cart/CheckoutController.php index 9591226bef3fc20fb8bfa38e55cd2b2c2936e8f0..b17df0c64d0a5dd23561a109ca18b62382fea3a7 100644 --- a/src/controller/cart/CheckoutController.php +++ b/src/controller/cart/CheckoutController.php @@ -1,20 +1,51 @@ <?php +require_once __DIR__ . '/../../Soap/PesananSoap.php'; + class CheckoutController extends Controller{ public function post(){ $userId = $_SESSION['user_id']; + $alamat = $_POST['alamat']; + + $biaya_pengiriman = rand(20, 50) * 1000; + $keterangan = "lagi nyari kurir buat kamu, sabar ya"; $CartModel = $this->model('CartModel'); - $carts = $CartModel->getUserCart($userId); - + $userModel = $this->model('UserModel'); $productModel = $this->model('ProductModel'); + $carts = $CartModel->getUserCart($userId); + $nama_penerima = $userModel->getUserById($userId)[3]; + + $nama_product = ""; + $harga = ""; + $quantity = ""; + foreach($carts as $cart){ + $quantity .= $cart["quantity"].","; + $product = $productModel->getProductById($cart['product_id'])->fetch_assoc(); + $nama_product .= $product['name'] . ","; + $harga .= $product['price'] .","; + } + + // var_dump($userId); + // var_dump($alamat); + // var_dump($nama_penerima); + // var_dump($keterangan); + // var_dump($harga); + // var_dump($biaya_pengiriman); + // var_dump($nama_product); + // var_dump($quantity); + + PesananSoap::setSoapClient("pesanan"); + $result = PesananSoap::sendPesanan($userId, $alamat, $nama_penerima, $keterangan, $harga, $biaya_pengiriman, $nama_product, $quantity); foreach($carts as $cart){ $productModel->buy($cart['product_id'], $cart['quantity']); $CartModel->removeProductFromCart($userId, $cart['product_id']); } - + // var_dump($result); + // var_dump($_POST['alamat']); + header("Location: /cart/checkout"); } } diff --git a/src/controller/track/TrackController.php b/src/controller/track/TrackController.php new file mode 100644 index 0000000000000000000000000000000000000000..ba4461db3c8993de8987f1cdfc8347e478dec5c4 --- /dev/null +++ b/src/controller/track/TrackController.php @@ -0,0 +1,24 @@ +<?php + +require_once __DIR__ . '/../../Soap/PesananSoap.php'; + +class TrackController extends Controller{ + public function index() { + $userId = $_SESSION['user_id']; + PesananSoap::setSoapClient("pesanan"); + $result = PesananSoap::getPesanan($userId); + + $data = [ + 'pesanan' => $result + ]; + $this->render($data); + // foreach($carts as $cart){ + // $productModel->buy($cart['product_id'], $cart['quantity']); + // $CartModel->removeProductFromCart($userId, $cart['product_id']); + // } + + + + // $this->render(); + } +} \ No newline at end of file diff --git a/src/soap/BaseSoap.php b/src/soap/BaseSoap.php new file mode 100644 index 0000000000000000000000000000000000000000..e490f8c9da1849ca8ec83de3e103427c19772608 --- /dev/null +++ b/src/soap/BaseSoap.php @@ -0,0 +1,9 @@ +<?php + + +class BaseSoap{ + protected static $apiKey = "i9YKgYehGK3pqL2V9u/Zp6d6EmimY8cuJst0b2ae3Us="; + protected static $url = "http://host.docker.internal:6001/ws/"; + + +} \ No newline at end of file diff --git a/src/soap/DetailPesananSoap.php b/src/soap/DetailPesananSoap.php new file mode 100644 index 0000000000000000000000000000000000000000..591e655b1e250392e9acfa4cba350d937ce47968 --- /dev/null +++ b/src/soap/DetailPesananSoap.php @@ -0,0 +1,32 @@ +<?php + +require_once __DIR__ . '/BaseSoap.php'; +class PesananSoap extends BaseSoap{ + public static SoapClient $client; + public static string $service; + + public static function setSoapClient($service){ + static::$service = static::$url . $service; + static::$client = new SoapClient(static::$service . '?wsdl', array( + 'stream_context' => stream_context_create(array( + 'http' => array( + 'header' => 'apiKey: ' . static::$apiKey + ) + )) + )); + } + + public static function getDetailPesanan(int $idPesanan){ + $result = static::$client->__soapCall('getDetailPesanan', array( + 'addPesanan' => array( + 'arg0' => $idPesanan + ) + )); + + if(empty((array) $result)){ + return null; + } + + return $result; + } +} \ No newline at end of file diff --git a/src/soap/PesananSoap.php b/src/soap/PesananSoap.php new file mode 100644 index 0000000000000000000000000000000000000000..d6c25e50c6f95eb9d63973634be0a1e9b6e425e6 --- /dev/null +++ b/src/soap/PesananSoap.php @@ -0,0 +1,54 @@ +<?php + +require_once __DIR__ . '/BaseSoap.php'; +class PesananSoap extends BaseSoap{ + public static SoapClient $client; + public static string $service; + + public static function setSoapClient($service){ + static::$service = static::$url . $service; + static::$client = new SoapClient(static::$service . '?wsdl', array( + 'stream_context' => stream_context_create(array( + 'http' => array( + 'header' => 'apiKey: ' . static::$apiKey + ) + )) + )); + } + + public static function sendPesanan(int $idPemesan, String $alamat, String $nama_penerima, String $keterangan, String $harga, int $biaya_pengiriman, String $nama_product, String $quantity){ + $result = static::$client->__soapCall('addPesanan', array( + 'addPesanan' => array( + 'arg0' => $idPemesan, + 'arg1' => $alamat, + 'arg2' => $nama_penerima, + 'arg3' => $keterangan, + 'arg4' => $harga, + 'arg5' => $biaya_pengiriman, + 'arg6' => $nama_product, + 'arg7' => $quantity + ) + )); + + if(empty((array) $result)){ + return null; + } + + return $result; + } + + public static function getPesanan($userId){ + var_dump($userId); + $result = static::$client->__soapCall('getPesananByIdUser', array( + 'getPesananByIdUser' => array( + 'arg0' => $userId, + ) + )); + + if(empty((array) $result)){ + return null; + } + + return $result; + } +} \ No newline at end of file