From 78187b5224f9b51d9bcfaee459d8a3ab186aff27 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 23 Jun 2018 19:05:20 -0600 Subject: [PATCH] Use separate required.php for online store --- public/action.php | 2 +- public/index.php | 3 +- public/lib/item.php | 4 +- public/parts/cart.php | 49 +++++++++++++--- public/required.php | 127 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 12 deletions(-) create mode 100644 public/required.php diff --git a/public/action.php b/public/action.php index 9a77e71..b27f059 100644 --- a/public/action.php +++ b/public/action.php @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -require_once __DIR__ . "/../required.php"; +require_once __DIR__ . "/required.php"; require_once __DIR__ . "/lib/item.php"; switch ($VARS['action']) { diff --git a/public/index.php b/public/index.php index c5740aa..14779ab 100644 --- a/public/index.php +++ b/public/index.php @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -require_once __DIR__ . "/../required.php"; +require_once __DIR__ . "/required.php"; define("NICKELBOX", true); @@ -16,6 +16,7 @@ $config = $database->select("config", ['key', 'value']); $settings = [ "sitename" => "Shop", "theme" => "default", + "tax" => 8.5, ]; foreach ($config as $c) { $settings[$c['key']] = $c['value']; diff --git a/public/lib/item.php b/public/lib/item.php index 0b9080e..511868d 100644 --- a/public/lib/item.php +++ b/public/lib/item.php @@ -6,7 +6,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -require_once __DIR__ . "/../../required.php"; +require_once __DIR__ . "/../required.php"; class Item { @@ -115,6 +115,7 @@ END; $catid = $item->getCategoryId(); $catname = $item->getCategoryName(); $price = $item->getPrice(); + $linetotal = number_format($price * $qty, 2); $html = <<
@@ -132,6 +133,7 @@ END; +
$$linetotal
END; diff --git a/public/parts/cart.php b/public/parts/cart.php index 332af88..58c2f7e 100644 --- a/public/parts/cart.php +++ b/public/parts/cart.php @@ -1,5 +1,4 @@ 0) { + foreach ($cart as $i => $qty) { + $item = new Item($i); + $listhtml .= RenderItem::cart($item, $qty); + $total += ($item->getPrice() * $qty); + } +} else { + $listhtml = "

The cart is empty.

"; +} + +$tax = $total * ($settings['tax'] / 100.0); ?>
@@ -23,15 +36,33 @@ if (!empty($_SESSION['cart'])) {
0) { - foreach ($cart as $i => $qty) { - echo RenderItem::cart(new Item($i), $qty); + echo $listhtml; + ?> +
+ +
+
+ 0.0) { + ?> +
+ Subtotal: +
+
+ Tax: +
+ -

The cart is empty.

- +

+ Total: +

+
\ No newline at end of file diff --git a/public/required.php b/public/required.php new file mode 100644 index 0000000..cce08c4 --- /dev/null +++ b/public/required.php @@ -0,0 +1,127 @@ +" + . "" + . "" + . "Error" + . "" + . "

A fatal application error has occurred.

" + . "(This isn't your fault.)" + . "

Details:

" + . "

" . htmlspecialchars($error) . "

"); +} + +date_default_timezone_set(TIMEZONE); + +// Database settings +// Also inits database and stuff +use Medoo\Medoo; + +$database; +$binstack; +try { + $database = new Medoo([ + 'database_type' => DB_TYPE, + 'database_name' => DB_NAME, + 'server' => DB_SERVER, + 'username' => DB_USER, + 'password' => DB_PASS, + 'charset' => DB_CHARSET + ]); + $binstack = new Medoo([ + 'database_type' => BINSTACK_DB_TYPE, + 'database_name' => BINSTACK_DB_NAME, + 'server' => BINSTACK_DB_SERVER, + 'username' => BINSTACK_DB_USER, + 'password' => BINSTACK_DB_PASS, + 'charset' => BINSTACK_DB_CHARSET + ]); +} catch (Exception $ex) { + //header('HTTP/1.1 500 Internal Server Error'); + sendError("Database error. Try again later. $ex"); +} + + +if (!DEBUG) { + error_reporting(0); +} else { + error_reporting(E_ALL); + ini_set('display_errors', 'On'); +} + + +$VARS; +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $VARS = $_POST; + define("GET", false); +} else { + $VARS = $_GET; + define("GET", true); +} + +/** + * Checks if a string or whatever is empty. + * @param $str The thingy to check + * @return boolean True if it's empty or whatever. + */ +function is_empty($str) { + return (is_null($str) || !isset($str) || $str == ''); +} \ No newline at end of file