Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Recommended Posts

Posted

My apologies if this should have been in the Credit Class/Gift Vouchers/Discount Coupons thread, but I didn't see my problem there and didn't want to interrupt the discussion currently being held there.

 

I'm using the (very nice) Coupon Codes and Gift Vouchers 5.16 contribution, and so far it's working perfectly apart from one problem: A coupon code must be redeemed twice in order for the discount to be applied.

 

The first time a coupon code is entered I get the "The coupon has been successfully applied for <BR>***HOWEVER:No reducion available, please see the coupon restrictions***" error. If I then enter a coupon code again and redeem it, the coupon works fine (whether it's the same coupon code or a different one).

 

Going over the code, it seems to me that the problem occurs when checkout_confirmation.php calls the collect_posts method:

 

function pre_confirmation_check($order_total) {
 global $customer_id;
 return $this->calculate_credit($order_total);
}

//...

function collect_posts() {
//...
  global $order,$ot_coupon,$currency;
  //BEGIN >>> CCVG 5.15 - Custom Modification - fix Coupon code redemption error
  //Moved code up a few lines
  if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id');
  $cc_id = $coupon_result['coupon_id'];
  //END <<< CCVG 5.15 - Custom Modification - fix Coupon code redemption error
  $coupon_amount= tep_round($ot_coupon->pre_confirmation_check($order->info['subtotal']), $currencies->currencies[$currency]['decimal_places']); // $cc_id
//...
}

function calculate_credit($amount) {
 global $customer_id, $order, $cc_id;
 //echo "cc_id from calculate_credit function:  ".$cc_id."<BR>";
 //$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
 $od_amount = 0;
 if (isset($cc_id) ) {
//do stuff that gets od_amount to be set correctly
 }
 return tep_round($od_amount,2);
}

 

The problem is that $coupon_amount is always getting set to 0 the first time, though it gets set correctly on subsequent attempts. This seems to be because the calculate_credit function always sees $cc_id as not being set the first time, even though it has already been set by collect_posts before it gets called by pre_confirmation_check.

 

As far as I can tell I've installed the contribution correctly. What am I missing?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...