diff --git a/index.php b/index.php index 681444f..e1a1b61 100644 --- a/index.php +++ b/index.php @@ -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'; diff --git a/src/.env.example b/src/.env.example index 5fb71e7..993e83f 100644 --- a/src/.env.example +++ b/src/.env.example @@ -1,4 +1,5 @@ EVENT_TICKET_PRICE="55" +TABLE_TICKET_PRICE="350" ENHANCER_TICKET_PRICE="20" DB_HOST="localhost" DB_USER="root" diff --git a/src/functions.php b/src/functions.php index 34ff29d..7d18fb7 100644 --- a/src/functions.php +++ b/src/functions.php @@ -49,16 +49,38 @@ function shoppingCartLineItem($name, $price, $description = '')
' . $name . '
' . $description . ' - ' . '$' . number_format(($price/100), 2) . ' + ' . '$' . number_format(($price / 100), 2) . ' '; } } +/** + * 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 '
  • Total - ' . '$' . number_format(($price/100), 2) . ' + ' . '$' . number_format(($price / 100), 2) . '
  • '; } \ No newline at end of file diff --git a/views/step2.php b/views/step2.php index 710f3cd..ac099c3 100644 --- a/views/step2.php +++ b/views/step2.php @@ -5,6 +5,7 @@ Your cart