saving form data on checkout
This commit is contained in:
@@ -63,6 +63,8 @@ CREATE TABLE `orders` (
|
||||
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`ticket_quantity` int(11) NOT NULL,
|
||||
`enhancer_quantity` int(11) NOT NULL DEFAULT '0',
|
||||
`ticket_cents` int(11) NOT NULL DEFAULT '0',
|
||||
`enhancer_cents` int(11) NOT NULL DEFAULT '0',
|
||||
`additional_cents` int(11) NOT NULL DEFAULT '0',
|
||||
`total_cents` int(11) NOT NULL,
|
||||
`first_name` varchar(45) NOT NULL,
|
||||
|
||||
40
index.php
40
index.php
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Bramus\Router\Router;
|
||||
use RedBeanPHP\R;
|
||||
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
require __DIR__ . '/src/functions.php';
|
||||
@@ -12,12 +13,14 @@ $dotenv->required([
|
||||
'EVENT_TICKET_PRICE',
|
||||
'ENHANCER_TICKET_PRICE',
|
||||
'DB_HOST',
|
||||
'DB_NAME',
|
||||
'DB_USER',
|
||||
'DB_PASS',
|
||||
'POSTMARK_API_KEY',
|
||||
]);
|
||||
|
||||
$router = new Router();
|
||||
$r = R::setup('mysql:host=' . $_SERVER['DB_HOST'] . ';dbname=' . $_SERVER['DB_NAME'], $_SERVER['DB_USER'], $_SERVER['DB_PASS']);
|
||||
|
||||
// Custom 404 Handler
|
||||
$router->set404(function () {
|
||||
@@ -51,6 +54,43 @@ $router->post('/', function () {
|
||||
include 'views/common/footer.php';
|
||||
});
|
||||
|
||||
$router->post('/checkout', function () {
|
||||
//todo this is duplicated and should be handled by an object.
|
||||
// POST variables
|
||||
$originalTicketQty = $eventTicketQty = getInteger($_POST['eventTicketQty']); // Store original ticket quantity
|
||||
$ticketEnhancerQty = getInteger($_POST['ticketEnhancerQty']);
|
||||
|
||||
// Calculate totals
|
||||
$additionalContribution = convertPossibleFloatToCents($_POST['additionalContribution']);
|
||||
list($tableTicketQty, $eventTicketQty) = eventPricing($eventTicketQty);
|
||||
$eventTicketPrice = convertPossibleFloatToCents($eventTicketQty * $_SERVER['EVENT_TICKET_PRICE']);
|
||||
$tableTicketPrice = convertPossibleFloatToCents($tableTicketQty * $_SERVER['TABLE_TICKET_PRICE']);
|
||||
$ticketEnhancerPrice = convertPossibleFloatToCents($ticketEnhancerQty * $_SERVER['ENHANCER_TICKET_PRICE']);
|
||||
|
||||
// Sum the cart totals
|
||||
$cartTotal = $eventTicketPrice + $tableTicketPrice + $ticketEnhancerPrice + $additionalContribution;
|
||||
|
||||
$order = R::dispense('orders');
|
||||
$order->ticket_quantity = $originalTicketQty;
|
||||
$order->ticket_cents = $eventTicketPrice + $tableTicketPrice;
|
||||
$order->enhancer_quantity = $ticketEnhancerQty;
|
||||
$order->enhancer_cents = $ticketEnhancerPrice;
|
||||
$order->additional_cents = $additionalContribution;
|
||||
$order->total_cents = $cartTotal;
|
||||
$order->first_name = $_POST['firstName'];
|
||||
$order->last_name = $_POST['lastName'];
|
||||
$order->email = $_POST['email'];
|
||||
$order->address = $_POST['address'];
|
||||
$order->city = $_POST['city'];
|
||||
$order->state = $_POST['state'];
|
||||
$order->zip = $_POST['zip'];
|
||||
$order->payment_type = $_POST['paymentMethod'];
|
||||
$order->stripe_token = '1234';
|
||||
$order->uuid = $_POST['firstName'];
|
||||
$id = R::store($order);
|
||||
var_dump($id);
|
||||
});
|
||||
|
||||
|
||||
// Run it!
|
||||
$router->run();
|
||||
@@ -2,6 +2,7 @@ EVENT_TICKET_PRICE="55"
|
||||
TABLE_TICKET_PRICE="350"
|
||||
ENHANCER_TICKET_PRICE="20"
|
||||
DB_HOST="localhost"
|
||||
DB_NAME="ditw"
|
||||
DB_USER="root"
|
||||
DB_PASS="root"
|
||||
POSTMARK_API_KEY="special"
|
||||
@@ -16,24 +16,26 @@
|
||||
</div>
|
||||
<div class="col-md-8 order-md-1">
|
||||
<h4 class="mb-3">Billing address</h4>
|
||||
<form class="needs-validation" novalidate>
|
||||
<form class="needs-validation" novalidate method="POST" action="/checkout">
|
||||
<?php
|
||||
$eventTicketQty = getInteger($_POST['eventTicketQty']);
|
||||
$ticketEnhancerQty = getInteger($_POST['ticketEnhancerQty']);
|
||||
$additionalContribution = getInteger($_POST['additionalContribution']);
|
||||
?>
|
||||
<input type="hidden" name="eventTicketQty" value="<?=$eventTicketQty?>" />
|
||||
<input type="hidden" name="ticketEnhancerQty" value="<?=$ticketEnhancerQty?>" />
|
||||
<input type="hidden" name="additionalContribution" value="<?=$additionalContribution?>" />
|
||||
<div class="row">
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="firstName">First name</label>
|
||||
<input type="text" class="form-control" id="firstName" placeholder="" value="" required>
|
||||
<input type="text" class="form-control" id="firstName" name="firstName" value="" required>
|
||||
<div class="invalid-feedback">
|
||||
Valid first name is required.
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label for="lastName">Last name</label>
|
||||
<input type="text" class="form-control" id="lastName" placeholder="" value="" required>
|
||||
<input type="text" class="form-control" id="lastName" name="lastName" value="" required>
|
||||
<div class="invalid-feedback">
|
||||
Valid last name is required.
|
||||
</div>
|
||||
@@ -41,14 +43,14 @@
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="email">Email</label>
|
||||
<input type="email" class="form-control" id="email" placeholder="you@example.com" required>
|
||||
<input type="email" class="form-control" id="email" name="email" placeholder="you@example.com" required>
|
||||
<div class="invalid-feedback">
|
||||
Please enter a valid email address.
|
||||
</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="address">Address</label>
|
||||
<input type="text" class="form-control" id="address" placeholder="1234 Main St" required>
|
||||
<input type="text" class="form-control" id="address" name="address" placeholder="1234 Main St" required>
|
||||
<div class="invalid-feedback">
|
||||
Please enter your address.
|
||||
</div>
|
||||
@@ -56,14 +58,14 @@
|
||||
<div class="row">
|
||||
<div class="col-md-4 mb-4">
|
||||
<label for="city">City</label>
|
||||
<input type="text" class="form-control" id="city" placeholder="" required>
|
||||
<input type="text" class="form-control" id="city" name="city" placeholder="" required>
|
||||
<div class="invalid-feedback">
|
||||
City required.
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4 mb-4">
|
||||
<label for="state">State</label>
|
||||
<select class="custom-select d-block w-100" id="state" required>
|
||||
<select class="custom-select d-block w-100" id="state" name="state" required>
|
||||
<option value="AL">AL</option>
|
||||
<option value="AK">AK</option>
|
||||
<option value="AR">AR</option>
|
||||
@@ -123,7 +125,7 @@
|
||||
</div>
|
||||
<div class="col-md-4 mb-4">
|
||||
<label for="zip">Zip</label>
|
||||
<input type="text" class="form-control" id="zip" placeholder="" required>
|
||||
<input type="text" class="form-control" id="zip" name="zip" required>
|
||||
<div class="invalid-feedback">
|
||||
Zip code required.
|
||||
</div>
|
||||
@@ -135,11 +137,11 @@
|
||||
|
||||
<div class="d-block my-3">
|
||||
<div class="custom-control custom-radio">
|
||||
<input id="credit" name="paymentMethod" type="radio" class="custom-control-input" checked required>
|
||||
<input id="credit" name="paymentMethod" type="radio" class="custom-control-input" value="0" checked required>
|
||||
<label class="custom-control-label" for="credit">Credit card</label>
|
||||
</div>
|
||||
<div class="custom-control custom-radio">
|
||||
<input id="check" name="paymentMethod" type="radio" class="custom-control-input" required>
|
||||
<input id="check" name="paymentMethod" type="radio" class="custom-control-input" value="1" required>
|
||||
<label class="custom-control-label" for="debit">Check/Cash</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user