Skip to content

Commit

Permalink
Don't offer GV payment if order only has GV's (zencart#6313)
Browse files Browse the repository at this point in the history
* Don't offer GV payment if order only has GV's
  • Loading branch information
lat9 authored Mar 11, 2024
1 parent b588c73 commit d3e6258
Showing 1 changed file with 41 additions and 19 deletions.
60 changes: 41 additions & 19 deletions includes/modules/order_total/ot_gv.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,27 +261,49 @@ function update_credit_account($i) {
}
}
}
/**
* check system to see if GVs should be made available or not. If true, then supply GV-selection fields on checkout pages
*/
function credit_selection() {
global $db, $currencies;
$selection = array();
$gv_query = $db->Execute("SELECT coupon_id FROM " . TABLE_COUPONS . " WHERE coupon_type = 'G' AND coupon_active='Y'");
// checks to see if any GVs are in the system and active or if the current customer has any GV balance
if ($gv_query->RecordCount() > 0 || $this->use_credit_amount()) {
$selection = array('id' => $this->code,
'module' => $this->title,
'redeem_instructions' => MODULE_ORDER_TOTAL_GV_REDEEM_INSTRUCTIONS,
'checkbox' => $this->use_credit_amount(),
'fields' => array(array('title' => MODULE_ORDER_TOTAL_GV_TEXT_ENTER_CODE,
'field' => zen_draw_input_field('gv_redeem_code', '', 'id="disc-'.$this->code.'" onkeyup="submitFunction(0,0)"'),
'tag' => 'disc-'.$this->code,
)));

/**
* check system to see if GVs should be made available or not. If true, then supply GV-selection fields on checkout pages
*/
function credit_selection()
{
global $db, $order;

// -----
// Don't offer a GV payment for orders that contain **only** GV's!
//
$only_gvs_in_order = true;
foreach ($order->products as $next_product) {
if (str_starts_with($next_product['model'], 'GIFT') === false) {
$only_gvs_in_order = false;
break;
}
}
if ($only_gvs_in_order === true) {
return [];
}

$selection = [];
$gv_query = $db->Execute("SELECT coupon_id FROM " . TABLE_COUPONS . " WHERE coupon_type = 'G' AND coupon_active = 'Y' LIMIT 1");
// checks to see if any GVs are in the system and active or if the current customer has any GV balance
if (!$gv_query->EOF || $this->use_credit_amount()) {
$selection = [
'id' => $this->code,
'module' => $this->title,
'redeem_instructions' => MODULE_ORDER_TOTAL_GV_REDEEM_INSTRUCTIONS,
'checkbox' => $this->use_credit_amount(),
'fields' => [
[
'title' => MODULE_ORDER_TOTAL_GV_TEXT_ENTER_CODE,
'field' => zen_draw_input_field('gv_redeem_code', '', 'id="disc-' . $this->code . '" onkeyup="submitFunction(0,0)"'),
'tag' => 'disc-'.$this->code,
],
],
];
}
return $selection;
}
return $selection;
}

/**
* Verify that the customer has entered a valid redemption amount, and return the amount that can be applied to this order
*/
Expand Down

0 comments on commit d3e6258

Please sign in to comment.