Hi Ray, with the last part that you wrote, I didn't quite understand the code : * -1 ?
Perhaps I am over-complicating. Looking at a fresh perspective, what do you think of this approach, this is a break down of what I need/done
(1) my discount system comprises of discounts (pounds/percentages for products, sale category or delivery) (done)
(2) the discount conditions for products or sale category would be placed in the discounts tab in the eCart Object. (done)
(3) in the shipping tab of the eCart object, I only have one rule (if session exists then flat rate on the session). (done)
(4) the basket page includes a form for customer to add a coupon code and pressing on the Apply button creates that session (done)
(5) if the coupon relates to either product or sale category then the discount shows on the basket page. (works)
(6) if the coupon relates to delivery then that session will be passed onto my delivery php file. (works)
(7) at checkout on the address page on submit it redirects to my delivery php file (before going to payment page) (works)
(8) on the delivery php file, I am looking up delivery cost in a filtered recordset (works)
(9) I have an IF statement if the customer chooses "store collection" then the delivery session = 0 (works)
(10) if the customer selected "standard delivery" on checkout then the session is based on the filtered recordset. (works)
(11) I need to write an if statement (based on the below conditions) if TRUE then then delivery session = the result on the IF statement (I need to write)
DELIVERY POUND DISCOUNT
If Session variable exists: CouponDiscount
If Session variable CouponType == 2
IF Session variable CouponGroup == 3
If today is after $_SESSION['CouponValidFrom']
If today is before $_SESSION['CouponValidTo']
{create the calculation for the current delivery cost - the coupon session value}
DELIVERY PERCENTAGE DISCOUNT
If Session variable exists: CouponDiscount
If Session variable CouponType == 1
IF Session variable CouponGroup == 3
If today is after $_SESSION['CouponValidFrom']
If today is before $_SESSION['CouponValidTo']
based on the cart subtotal
{create the caculation for the current delivery cost - the coupon session value as a percentage}
To me the above seems clear in my head as an approach as then I can add extra code to show the customer that delivery is discounted etc.
I just need to work out the calculations using the above conditions. I have coded this and wondered if it makes sense this way:
<?php
// Percentage
if (((isset($_SESSION['CouponDiscount']))
&& ((isset($_SESSION['CouponType'])?$_SESSION['CouponType']:"") == "1")
&& ((isset($_SESSION['CouponGroup'])?$_SESSION['CouponGroup']:"") == "3")
&& (time() >= strtotime("".$_SESSION['CouponValidFrom'] .""))
&& (time() <= strtotime("".$_SESSION['CouponValidTo'] ."")))) {
$_SESSION["EstimatedDeliveryCost"] = $_SESSION["EstimatedDeliveryCost"] - (($_SESSION["EstimatedDeliveryCost"] * $_SESSION['CouponDiscount']));
}
?>
<?php
// Flat Rate
if (((isset($_SESSION['CouponDiscount']))
&& ((isset($_SESSION['CouponType'])?$_SESSION['CouponType']:"") == "2")
&& ((isset($_SESSION['CouponGroup'])?$_SESSION['CouponGroup']:"") == "3")
&& (time() >= strtotime("".$_SESSION['CouponValidFrom'] .""))
&& (time() <= strtotime("".$_SESSION['CouponValidTo'] ."")))) {
$_SESSION["EstimatedDeliveryCost"] = ($_SESSION["EstimatedDeliveryCost"] - $_SESSION['CouponDiscount']);
}
?>