I have been working on my loyalty point program on my website. The problem is that sometimes customers change their minds and do not want to use their points however once they have redeemed them...they dissappear and i get an email from them asking me to put them back on their accounts. So, I'm trying to make it so that once points are redeemed...there will be a button to undo the action...reverting the subtotal back(which i have been able to easily accomplish) AND also ADD those redeemed points BACK to the customers account. I can get the points removed from the cart but i cannot get it to add the points back to the customers account. Here is what I got so far...
//Begin Loyalty Modification
function round_down($value)
{
if(is_float($value))
{
$exploded = explode(".",$value);
return $exploded[0];
}
else
{
die("Only float values can be entered.");
}
}
$module = fetchDbConfig("Loyalty_Mod");
$view_cart->assign("STEP", $_GET['act']);
//when logged in gets quantity and value of points to display
if($basket['pointsaving']>0){
$view_cart->assign("POINTSAVING","Redeemed Points");
$view_cart->assign("VAL_POINTSAVING",priceFormat($basket['pointsaving']));
$pointssaving=$basket['pointsaving'];
$view_cart->assign("POINTSAVING","Redeemed Points");
$view_cart->assign("VAL_POINTSAVING",priceFormat($basket['pointsaving']));
}
//define redemption rules
if (isset($_POST['redeem'])){
if ($_POST['redeem']>$ccUserData[0]['availpoints']) {
$msg = "You Have Insufficent Points!";
$pointstrue=0;
}else{
$pointstrue=1;
$redeemed=$_POST['redeem'];
}
$availpoints = $ccUserData[0]['availpoints'];
$pendpoints = $ccUserData[0]['pendpoints'];
$pointsratecheck = $module['converted'];
$pointssavingcheck = $redeemed*$pointsratecheck;
if($basket['pointsaving']>0){
$updatesavingcheck=$basket['pointsaving']+$pointssavingcheck;
$pointssavingcheck=$updatesavingcheck;
}
$check=$_POST['subTotal']-$pointssavingcheck;
if($check<0.00){
$msg = "Invalid Amount";
$pointstrue=0;
}
if ($_POST['redeem']<0) {
$msg = "Invalid Amount!";
$pointstrue=0;
}
}
if ($pointstrue>0){
$module = fetchDbConfig("Loyalty_Mod");
$availpoints = $ccUserData[0]['availpoints'];
$pendpoints = $ccUserData[0]['pendpoints'];
$pointsrate = $module['converted'];
$pointssaving = $redeemed*$pointsrate;
//if your basket has point savings update basket
if($basket['pointsaving']>0){
$updatesaving=$basket['pointsaving']+$pointssaving;
$basket = $cart->setVar($updatesaving,"pointsaving");
$pointssaving=$updatesaving;
}else{
$basket = $cart->setVar($pointssaving,"pointsaving");
}
$view_cart->assign("POINTSAVING","Redeemed Points");
$view_cart->assign("VAL_POINTSAVING",priceFormat($basket['pointsaving']));
//changes happen to your account
$msg = "Your Points Have Been Redeemed";
$ccUserData[0]['availpoints'] = $ccUserData[0]['availpoints']-$redeemed;
$record['availpoints'] = $ccUserData[0]['availpoints'];
$where = "customer_id = ".$ccUserData[0]['customer_id'];
$update = $db->update($glob['dbprefix']."CubeCart_customer", $record, $where);
}
//RETURN MY LOYALTY POINTS!
if(isset($_GET['return'])){
$basket = $cart->unsetVar("pointsaving");
headerRedir();
$msg = "Your Points Have Been Returned";
$ccUserData[0]['availpoints'] = $ccUserData[0]['availpoints']+$pointsaving/$pointsrate;
$record['availpoints'] = $ccUserData[0]['availpoints'];
$where = "customer_id = ".$ccUserData[0]['customer_id'];
$update = $db->update($glob['dbprefix']."CubeCart_customer", $record, $where);
}
if ($module['status']==1){
$availpoints = $ccUserData[0]['availpoints'];
$pendpoints = $ccUserData[0]['pendpoints'];
$view_cart->assign("PENDPOINTS",$pendpoints);
$view_cart->assign("AVAILPOINTS",$availpoints);
$pointsrate = $module['converted'];
$availcash = $pointsrate*$availpoints;
$view_cart->assign("AVAILCASH",priceFormat($availcash));
}
//End Loyalty Modification