Table ticket pricing

This commit is contained in:
Chris Smith
2019-03-04 14:55:31 -06:00
parent be36a874fd
commit 011beb9b34
4 changed files with 29 additions and 3 deletions

View File

@@ -39,11 +39,13 @@ $router->post('/', function () {
// 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 + $ticketEnhancerPrice + $additionalContribution;
$cartTotal = $eventTicketPrice + $tableTicketPrice + $ticketEnhancerPrice + $additionalContribution;
include 'views/common/head.php';
include 'views/step2.php';
include 'views/common/footer.php';

View File

@@ -1,4 +1,5 @@
EVENT_TICKET_PRICE="55"
TABLE_TICKET_PRICE="350"
ENHANCER_TICKET_PRICE="20"
DB_HOST="localhost"
DB_USER="root"

View File

@@ -49,16 +49,38 @@ function shoppingCartLineItem($name, $price, $description = '')
<h6 class="my-0">' . $name . '</h6>
<small class="text-muted">' . $description . '</small>
</div>
<span class="text-muted">' . '$' . number_format(($price/100), 2) . '</span>
<span class="text-muted">' . '$' . number_format(($price / 100), 2) . '</span>
</li>';
}
}
/**
* Calculate table ticket price and event tickets based on quantity
*
* @param $qty integer Quantity of event tickets purchased
* @param $price integer Price of event tickets
* @param $tablePrice integer Price of table
* @return array
*/
function eventPricing($qty)
{
$tableQty = 0;
$eventQty = 0;
// If pricing is 8 or more then we need to factor in table reservations
if ($qty > 7) {
$tableQty = (int) ($qty / 8);
$eventQty = $qty - ($tableQty * 8);
}
return [$tableQty, $eventQty];
}
function shoppingCartTotal($price)
{
echo '<li class="list-group-item d-flex justify-content-between">
<span>Total</span>
<strong>' . '$' . number_format(($price/100), 2) . '</strong>
<strong>' . '$' . number_format(($price / 100), 2) . '</strong>
</li>';
}

View File

@@ -5,6 +5,7 @@
<span class="text-muted">Your cart</span>
</h4>
<ul class="list-group mb-3">
<?=shoppingCartLineItem('Table', $tableTicketPrice, $tableTicketQty . ' x table');?>
<?=shoppingCartLineItem('Dinner', $eventTicketPrice, $eventTicketQty . ' x tickets');?>
<?=shoppingCartLineItem('Ticket Enhancers', $ticketEnhancerPrice, $ticketEnhancerQty . ' x enhancers');?>
<?=shoppingCartLineItem('Additional Contribution', $additionalContribution);?>