Posted 08 December 2010, 23:43
And I think I have found the solution as well....it seems there was a global variable missing....
Within the function before_process()
function before_process() {
global $customer_id, $order, $order_total_modules, $order_totals, $sendto, $billto, $languages_id, $payment, $currencies, $cart, $cart_PayPal_Standard_ID;
global $$payment;
$order_total_modules was missing...I can't believe none noticed that.
Now the process complete succesfully and everything works perfectly.
I have only a small little problem when the voucher is inserted and it failed any of the check, instead of getting the error message I get an empty pink line....
I think I have narrowed down the problem but I still did not manage to solve it:
Checkout_payment.php call the following functions:
<?php
// Start - CREDIT CLASS Gift Voucher Contribution
echo $order_total_modules->credit_selection();
// End - CREDIT CLASS Gift Voucher Contribution ?>
<?php
order_total.php will call the same function in ot_coupon:
while (list(, $value) = each($this->modules)) {
$class = substr($value, 0, strrpos($value, '.'));
if ($GLOBALS[$class]->enabled && $GLOBALS[$class]->credit_class) {
if ($selection_string =='') $selection_string = $GLOBALS[$class]->credit_selection();
if ( ($use_credit_string !='' ) || ($selection_string != '') ) {
$output_string .= '<tr colspan="4"><td colspan="4" width="100%">' . tep_draw_separator('pixel_trans.gif', '100%', '10') . '</td></tr>';
$output_string = ' <tr class="moduleRow" onmouseover="rowOverEffect(this)" onmouseout="rowOutEffect(this)" >' . "\n" .
' <td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') .'</td>' .
' <td class="main"><b>' . $GLOBALS[$class]->header . '</b></td>' . $use_credit_string;
$output_string .= '<td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') . '</td>';
$output_string .= ' </tr>' . "\n";
$output_string .= $selection_string;
ot_coupon does all the checks to verify that the coupoon is correct and set the error if any of the check it fails:
function collect_posts() {
// All tep_redirect URL parameters modified for this function in v5.13 by Rigadin
global $HTTP_POST_VARS, $customer_id, $currencies, $cc_id;
if ($HTTP_POST_VARS['gv_redeem_code']) {
// get some info from the coupon table
$coupon_query=tep_db_query("select coupon_id, coupon_amount, coupon_type, coupon_minimum_order,uses_per_coupon, uses_per_user, restrict_to_products,restrict_to_categories from " . TABLE_COUPONS . " where coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."' and coupon_active='Y'");
$coupon_result=tep_db_fetch_array($coupon_query);
if ($coupon_result['coupon_type'] != 'G') {
if (tep_db_num_rows($coupon_query)==0) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_NO_INVALID_REDEEM_COUPON), 'SSL'));
}
$date_query=tep_db_query("select coupon_start_date from " . TABLE_COUPONS . " where coupon_start_date <= now() and coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'");
if (tep_db_num_rows($date_query)==0) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_STARTDATE_COUPON), 'SSL'));
}
$date_query=tep_db_query("select coupon_expire_date from " . TABLE_COUPONS . " where coupon_expire_date >= now() and coupon_code='".$HTTP_POST_VARS['gv_redeem_code']."'");
if (tep_db_num_rows($date_query)==0) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_FINISDATE_COUPON), 'SSL'));
}
$coupon_count = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id']."'");
$coupon_count_customer = tep_db_query("select coupon_id from " . TABLE_COUPON_REDEEM_TRACK . " where coupon_id = '" . $coupon_result['coupon_id']."' and customer_id = '" . $customer_id . "'");
if (tep_db_num_rows($coupon_count)>=$coupon_result['uses_per_coupon'] && $coupon_result['uses_per_coupon'] > 0) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_USES_COUPON . $coupon_result['uses_per_coupon'] . TIMES ), 'SSL'));
}
if (tep_db_num_rows($coupon_count_customer)>=$coupon_result['uses_per_user'] && $coupon_result['uses_per_user'] > 0) {
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES ), 'SSL'));
}
//**si** 09-11-05
/*
if ($coupon_result['coupon_type']=='S') {
$coupon_amount = $order->info['shipping_cost'];
} else {
$coupon_amount = $currencies->format($coupon_result['coupon_amount']) . ' ';
}
if ($coupon_result['coupon_type']=='P') $coupon_amount = $coupon_result['coupon_amount'] . '% ';
if ($coupon_result['coupon_minimum_order']>0) $coupon_amount .= 'on orders greater than ' . $coupon_result['coupon_minimum_order'];
if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id'); //Fred - this was commented out before
$cc_id = $coupon_result['coupon_id']; //Fred ADDED, set the global and session variable
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_REDEEMED_AMOUNT), 'SSL')); // Added in v5.13a by Rigadin
*/
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
/* you will need to uncomment this if your tax order total module is AFTER shipping eg you have all of your tax, including tax from shipping module, in your tax total.
if ($coupon_result['coupon_type']=='S') {
//if not zero rated add vat to shipping
$coupon_amount = tep_add_tax($coupon_amount, '17.5');
}
*/
$coupon_amount_out = $currencies->format($coupon_amount) . ' ';
if ($coupon_result['coupon_minimum_order']>0) $coupon_amount_out .= 'on orders greater than ' . $currencies->format($coupon_result['coupon_minimum_order']);
if (!tep_session_is_registered('cc_id')) tep_session_register('cc_id');
$cc_id = $coupon_result['coupon_id'];
if ( strlen($cc_id)>0 && $coupon_amount==0 ) {
// ccgv coupon restrictions error fix
// $err_msg = ERROR_REDEEMED_AMOUNT.ERROR_REDEEMED_AMOUNT_ZERO;
$err_msg = ERROR_REDEEMED_AMOUNT_ZERO;
} else {
$err_msg = ERROR_REDEEMED_AMOUNT.$coupon_amount_out;
}
tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode($err_msg), 'SSL'));
//**si** 09-11-05 end
// $_SESSION['cc_id'] = $coupon_result['coupon_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
} // ENDIF valid coupon code
} // ENDIF code entered
// v5.13a If no code entered and coupon redeem button pressed, give an alarm
if ($HTTP_POST_VARS['submit_redeem_coupon_x']) tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'payment_error='.$this->code.'&error=' . urlencode(ERROR_NO_REDEEM_CODE), 'SSL'));
}
I suspect that in the code above the problem arises. I think the payment_error->&error variable is not populated correctly
As you can see all the if redirect back to checkout_payment.php that will print the error on the screen:
<?php
if (isset($HTTP_GET_VARS['payment_error']) && is_object(${$HTTP_GET_VARS['payment_error']}) && ($error = ${$HTTP_GET_VARS['payment_error']}->get_error())) {
?>
<tr>
<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td class="main"><b><?php echo tep_output_string_protected($error['title']); ?></b></td>
</tr>
</table></td>
</tr>
<tr>
<td><table border="0" width="100%" cellspacing="1" cellpadding="2" class="infoBoxNotice">
<tr class="infoBoxNoticeContents">
<td><table border="0" width="100%" cellspacing="0" cellpadding="2">
<tr>
<td><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
<td class="main" width="100%" valign="top"><?php echo tep_output_string_protected($error['error']); ?></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
<?php
}
?>
You can see from there that to retrieve the error it calls the function get_error() once more from ot_coupon.php:
function get_error() {
global $HTTP_GET_VARS;
$error = array('title' => MODULE_ORDER_TOTAL_COUPON_TEXT_ERROR,
'error' => stripslashes(urldecode($HTTP_GET_VARS['$error'])));
return $error;
}
Here $error is populated with a title and and error.
$error['title'] is printed correctly on the screen $error ['error'] is not.
If instead of using stripslashes(urldecode($HTTP_GET_VARS['$error']))); I manually add some text then even the $error['error'] is printed on the screen. So my suspect is that the error either occurred when:
1) error is encoded : 'payment_error='.$this->code.'&error=' . urlencode(ERROR_REDEEMED_AMOUNT), 'SSL'));
or
2) error is decoded: 'error' => stripslashes(urldecode($HTTP_GET_VARS['$error'])));
I so in the forum someone had the same problem. Did anyone manage to resolve it?
Can someone help?
Any feedback is really appreciated.
Cheers
JK