Hello. I am working on a home-grown ecommerce solution and could use some help.
For now, my site offers subscriptions to users for access to premium content (e.g. news, articles, podccasts).
I have a “Subscribe” button in the top menu, and when someone clicks on that, I display a “membership-plans.php” page which shows a table of available member plans. Users can click on a “Select” (form) button for the option they want, and then are transferred to “checkout.php” where they will create an account and checkout all in one step.
As part of this, I need to come up with better solution than what I have now for determining the “Item Total” which is the cost of the subscription they chose.
Currently I am doing this…
In “membership-plans.php”, I have my 3 “Select” buttons, and when the form is submitted, I look at the $_POST array and stick whichever options was chosen into the $_SESSION variable.
For example, that might be…
$_SESSION['chosenPlan'] = $_POST['memberPlan-01'];
Then after I redirect them to the “checkout.php” page, that script can determine which option was chosen by looking at the $_SESSION variable, and then calculate the Order Total by maybe using a lookup like this…
IF ($_SESSION['chosenPlan'] = "memberPlan-01"){
$orderTotal = $20
ELSEIF ($_SESSION['chosenPlan'] = "memberPlan-02"){
$orderTotal = $30
ELSEIF...
ENDIF
The problem is that I have to hard-code lookup logic mapping the chosen Member Plan to a price, so if next week I introduce Member Plan 999 then I would have to update the above code.
I think I need a fresh set of eyes to look at what I am doing and offer a more streamlined (and scalable) solution!!
Thanks.