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 you must order total must $500 to place an order. 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 store have a min order total of $500 still.

First I need to know if this is possible and if so how I would go about achieving this. The code for the order total right now is:

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

Could you post an example post with item data in the categories you want to add rules for?

It could be done with something like this:

[php]/* So we are supposed to do this if the order total is less than 500.

  • Not sure why we are checking the couponCodeBtn

  • And we check if the user has actually pressed the submit button of the form
    */
    if ($_POST[‘orderTotal’] < 500 && !isset($_POST[‘couponCodeBtn’]) && isset($_POST[‘Submit’])) {
    // This should be the category id’s of the categories with lower limit
    $categoriesWithLowerLimit = array(1,2,5);

    // then we must loop through the items in the order. Note: this will have to be edited to fit your data.
    foreach ($_POST[‘orderItems’] as $item) {
    // then we check every item in the order if they not are in one of the categories with lower limit.
    if (!in_array($item[‘categoryId’], $categoriesWithLowerLimit)) {
    // If even a single item is not in a category with lower limit then we should redirect to an error message for the original limit value.
    header(“Location: …/cart.php?error=Your order must be at least $500 to continue.”);
    exit;
    }
    }

    // ok, all items were in a low limit category. check if the order value is > 150
    if ($_POST[‘orderTotal’] < 150) {
    header(“Location: …/cart.php?error=Your order must be at least $150 to continue.”);
    }
    }[/php]

And an uncommented version
[php]if ($_POST[‘orderTotal’] < 500 && !isset($_POST[‘couponCodeBtn’]) && isset($_POST[‘Submit’])) {
$categoriesWithLowerLimit = array(1,2,5);

foreach ($_POST[‘orderItems’] as $item) {
if (!in_array($item[‘categoryId’], $categoriesWithLowerLimit)) {
header(“Location: …/cart.php?error=Your order must be at least $500 to continue.”);
exit;
}
}

if ($_POST[‘orderTotal’] < 150) {
header(“Location: …/cart.php?error=Your order must be at least $150 to continue.”);
}
}[/php]

This is helpful and I think I am following. I think I may have simplified it a little to much by only posting a small amount of what is actually on this page. Here is the rest. I think it changes up how I would insert your code a bit. (I tried but it broke the page) Thanks again for the help.

[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]

Sponsor our Newsletter | Privacy Policy | Terms of Service