Shopping Cart Checkout Page

I have a php shopping cart that I am editing that someone else developed. My php skills are still very beginner. Currently the customer must order $500 to place an order if their cart contains less they get a message - order must be $500.

They want this to change so that any items that are in the categories of (accessories, scarves and jewelry) ONLY have a min order total of $150 but ALL other items in the other categories STILL have a min order total of $500.

So in summary

I need it to check if there are any items in accessories, scarves and jewelry - the total of those items ONLY needs to be $150 if not a message needs to be displayed “boutique items have $150 min order.”

Then I need it to check all other items in the cart and those items ONLY need to total $500 or a message needs to be displayed “$500 min order required”.

I need help on exactly how to modify the existing code - and I am a beginner.

current code:
[php]<?php ob_start(); session_start();
require_once(‘siteURL.php’);
require_once(’…/plugins/sqlconnect.php’);
require_once(’…/plugins/functions.php’);

$userName = $_SESSION[‘myusername’];

//Create accepted field array
$accepted = array(‘paymentType’, ‘billingAddress’, ‘shippingAddress’, ‘shipDate’, ‘PO’, ‘salesRep’, ‘repName’, ‘email’, ‘instructions’);

//Add post to session based on accepted field array
foreach ( $_POST as $details=>$field ) {
echo ("$details = $field
");
if ( in_array( $details, $accepted )) {
$_SESSION[$details] = $field;
}
}

//If order is less than 500, return to cart. Bypass if applying coupon code.
if (($_POST[‘orderTotal’] < 500) && ((!isset($_POST[‘couponCodeBtn’])) && (isset($_POST[‘Submit’])))) { header(“Location: …/cart.php?error=Your order must be at least $500 to continue.”);

//If coupon code applied return to cart.
} elseif ((isset($_POST[‘couponCodeBtn’])) && (!isset($_POST[‘Submit’]))) {

//If coupon code empty, unset coupon

if (((empty($_POST[‘couponCode’])) || ($_POST[‘couponCode’] == " "))) {
unset($_SESSION[‘couponCode’]);
header(“Location: …/cart.php?couponCodeMessage=Coupon removed”);
} else {
//Check if coupon code is valid
if (couponValid($_POST[‘orderTotal’], $userName, $_POST[‘couponCode’]) == “true”) {
$_SESSION[‘couponCode’] = $_POST[‘couponCode’];
header(“Location: …/cart.php?couponCodeMessage=Accepted!”);
} else {
header(“Location: …/cart.php?couponCodeError=” . couponValid($_POST[‘orderTotal’], $userName, $_POST[‘couponCode’]) . “”);
}
}

} else {

 //Check if coupon minimum met
 if (couponMinCheck($_POST['orderTotal'], $_POST['couponCode']) != "true") {
	 header("Location: ../cart.php?error=Coupon $_POST[couponCode] requires a minimum of $" . couponMinCheck($_POST['orderTotal'], $_POST['couponCode']) . ".&couponCodeError=Minimum $" . couponMinCheck($_POST['orderTotal'], $_POST['couponCode']) . ""); 
 } else {
	 

	  //If credit card/billing/shipping info need proceed to checkout, ortherwise proceed to confirm
	  if ((($_SESSION['paymentType'] == "creditCard") && (!isset($_SESSION['cardType']))) || ($_SESSION['billingAddress'] == "billingAddressNew") || ($_SESSION['shippingAddress'] == "shippingAddressNew")) {
	  header("Location: " . $siteSURL . "cart_checkout.php");
	  } else { 
	  header("Location: " . $siteSURL . "cart_confirm.php");
	  }
 }

}

?>[/php]

we need all the keys that $_POST gives this page. right now in the code the only thing that it has is a total and whether a coupon was used. in order to do what you want. the script needs (and we need the field names) for the category and price of each item in their shopping cart. I assume this is in $_POST somewhere but the code you have doesn’t show us where.

[php]var_dump($_POST;[/php]

at the top of that page to dump the received variables, and find the name for the category and price of each item in the cart.

I could not get var_dump($_POST); to work.

is it in php tags or did you put it in html?
[php]<?php var_dump($_POST);
ob_start(); session_start();
require_once(‘siteURL.php’);
require_once(’…/plugins/sqlconnect.php’);
require_once(’…/plugins/functions.php’);

$userName = $_SESSION[‘myusername’];

//Create accepted field array
$accepted = array(‘paymentType’, ‘billingAddress’, ‘shippingAddress’, ‘shipDate’, ‘PO’, ‘salesRep’, ‘repName’, ‘email’, ‘instructions’);

//Add post to session based on accepted field array
foreach ( $_POST as $details=>$field ) {
echo ("$details = $field
");
if ( in_array( $details, $accepted )) {
$_SESSION[$details] = $field;
}
}

//If order is less than 500, return to cart. Bypass if applying coupon code.
if (($_POST[‘orderTotal’] < 500) && ((!isset($_POST[‘couponCodeBtn’])) && (isset($_POST[‘Submit’])))) { header(“Location: …/cart.php?error=Your order must be at least $500 to continue.”);

//If coupon code applied return to cart.
} elseif ((isset($_POST[‘couponCodeBtn’])) && (!isset($_POST[‘Submit’]))) {

//If coupon code empty, unset coupon
if (((empty($_POST['couponCode'])) || ($_POST['couponCode'] == " "))) {
   unset($_SESSION['couponCode']);
   header("Location: ../cart.php?couponCodeMessage=Coupon removed");
} else {
	//Check if coupon code is valid
   if (couponValid($_POST['orderTotal'], $userName, $_POST['couponCode']) == "true") {
	 $_SESSION['couponCode'] = $_POST['couponCode'];   
	 header("Location: ../cart.php?couponCodeMessage=Accepted!"); 
   } else {
	 header("Location: ../cart.php?couponCodeError=" . couponValid($_POST['orderTotal'], $userName, $_POST['couponCode']) . "");   
   }
}

} else {

 //Check if coupon minimum met
 if (couponMinCheck($_POST['orderTotal'], $_POST['couponCode']) != "true") {
	 header("Location: ../cart.php?error=Coupon $_POST[couponCode] requires a minimum of $" . couponMinCheck($_POST['orderTotal'], $_POST['couponCode']) . ".&couponCodeError=Minimum $" . couponMinCheck($_POST['orderTotal'], $_POST['couponCode']) . ""); 
 } else {
	 

	  //If credit card/billing/shipping info need proceed to checkout, ortherwise proceed to confirm
	  if ((($_SESSION['paymentType'] == "creditCard") && (!isset($_SESSION['cardType']))) || ($_SESSION['billingAddress'] == "billingAddressNew") || ($_SESSION['shippingAddress'] == "shippingAddressNew")) {
	  header("Location: " . $siteSURL . "cart_checkout.php");
	  } else { 
	  header("Location: " . $siteSURL . "cart_confirm.php");
	  }
 }

}

?>[/php]

This is what it gave me:

array(0) { }
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /Users/admin/Sites/imaxcorp/plugins/orderDetails.php:1) in /Users/admin/Sites/imaxcorp/plugins/orderDetails.php on line 2

Notice: Undefined index: myusername in /Users/admin/Sites/imaxcorp/plugins/orderDetails.php on line 7

Notice: Undefined index: orderTotal in /Users/admin/Sites/imaxcorp/plugins/orderDetails.php on line 22

Notice: Undefined index: orderTotal in /Users/admin/Sites/imaxcorp/plugins/orderDetails.php on line 44

Notice: Undefined index: couponCode in /Users/admin/Sites/imaxcorp/plugins/orderDetails.php on line 44

Notice: Undefined index: paymentType in /Users/admin/Sites/imaxcorp/plugins/orderDetails.php on line 50

Notice: Undefined index: billingAddress in /Users/admin/Sites/imaxcorp/plugins/orderDetails.php on line 50

Notice: Undefined index: shippingAddress in /Users/admin/Sites/imaxcorp/plugins/orderDetails.php on line 50

Warning: Cannot modify header information - headers already sent by (output started at /Users/admin/Sites/imaxcorp/plugins/orderDetails.php:1) in /Users/admin/Sites/imaxcorp/plugins/orderDetails.php on line 53

Sponsor our Newsletter | Privacy Policy | Terms of Service