Jump to content
Strider

Credit Class/Gift Vouchers/Discount Coupons 5.10

Recommended Posts

jamoor: you probably don't have your model number set to GIFTsomething or other and about the problems you are having with the configure code it is usually a line or two above where the error states. sounds like syntax though.

 

acpaulley: all of the defines are there in the addendum files. and in the instructions it tells you to require those files in the appropriate files

 

Jack_mcs: Have you asked linda about this jack? I really haven't looked at the way sec is done. I just keep gettting told not to talk about loaded versions around here. But since she wrote it and you have to download it from her site you might ask her to fix it for you.

 

DesertDogs: you probably want to use the 5.3 version of ccgv for ms1. If I remember right there was a stack of changes that needed to be done to make it work with 2.2.2

 

jcall: actually there is a bug in the categories section of the discount coupon depending on how you use it. the bug is if you have the same products defined in multiple categoties the coupon only works in the first defined category. I haven't had time to play with it even though someone sent me the code to play with it. But other than that they play fine. I have 3 installations that use that feature at great length.


(my knowledge is so small you would think that an ant was a genius in comparison)

Share this post


Link to post
Share on other sites

Hi Strider. The configure code has been fixed. Thanks. As far as the gift voucher queue - My gift voucher model numbers are GIFT100, GIFT50, and GIFT25. I believe I have the models numbers fine so that is not the problem. Any other advice? Thanks Strider.


We will not regret what we have done. We will regret what we didn't do.

Share this post


Link to post
Share on other sites
I loaded the credit class contribution from

http://www.oscommerce.com/community/contributions,282

 

I want to use the coupon component, but I don't see any place for the customer to enter the coupon on my site. Can someone describe how this is supposed to work or provide an illustration?

 

-Matt

Have you activated coupons?

 

Try Admin | Modules | Order Total | Discount Coupons.

 

You should then see a redeem box in stage "Payment" of the checkout process.

 

/Fred

I don't see "Discount Coupons" under Admin | Modules | Order Total

 

I have Low Order Fee, Shipping, Sub-total, Tax and Total.

 

How do I make Discount Coupons show up? I must have missed a step.

 

Don't know if this would make a difference, but I've previously loaded a security contribution, Admin Account w/ Access Levels:

http://www.oscommerce.com/community/contributions,1174

 

Thanks,

 

-Matt

Share this post


Link to post
Share on other sites

DesertDogs: You might want to install it admin looks in the order totals modules in the catalog side for that

 

jamoor: do you have access to the gv after you purchase it


(my knowledge is so small you would think that an ant was a genius in comparison)

Share this post


Link to post
Share on other sites
DesertDogs: You might want to install it admin looks in the order totals modules in the catalog side for that

It works! My FS_Catalog path in the config file was pointing to the production site, instead of the development site with the new modules.

 

Now a new problem/question:

 

I created a coupon, emailed it to a (test) customer, they were able to use it and it showed up on the invoice and its use was shown on the Coupon Admin page.

 

I created another coupon. Used it as a test customer. [Without emailing it this time -- We're going to physically distribute the coupons to try to build business] It allowed the customer to use the coupon, gave them the discount, but the coupon didn't show up on the invoice (although the money was missing from the total), nor was the coupon's usage shown on the Coupon Admin page.

 

Do you have to email the coupons before they become active? If this is so, how come the test customer was able to use it and get a discount?

 

Thanks,

-Matt

 

BTW, thanks very much for the quick response on the last question. We got stuck trying to figure it out, went out for a hike, found the answer on our return and were able to get a bit further.

Share this post


Link to post
Share on other sites

desertdog: shouldn't be any difference in the way they are handled.


(my knowledge is so small you would think that an ant was a genius in comparison)

Share this post


Link to post
Share on other sites
Somehow, on my checkout_payment.php page, it is putting up two places to put the coupon code in.  The top one doesn't work and the bottom one does.  How can I eliminate the top one?  I know I have to edit a file somewhere.  But, I just can't figure out which one.  You can see it at

https://secureform1.dnspropagation.com/~knd...d68e4db9d5e0aaf

You should only have one redeem box. Take a look at the credit_selection() function in \catalog\includes\modules\order_total\ot_coupon.php, that function generates the redeem box.

 

/Fred

Share this post


Link to post
Share on other sites

Hi Strider. No I don't have access to the gv after it is purchased.


We will not regret what we have done. We will regret what we didn't do.

Share this post


Link to post
Share on other sites
Jack_mcs: Have you asked linda about this jack? I really haven't looked at the way sec is done. I just keep gettting told not to talk about loaded versions around here. But since she wrote it and you have to download it from her site you might ask her to fix it for you.

She hasn't respinded to any questions on her thread for some time now unfortunately. I was just hoping someone here might have already installed the update, and are using SEC, and would be able to help. Any chance of there ever be a doc generated that describes the changes made by the update? Something like "the gv_faq.php was changed on line 20 from "this" to "that?"

 

Jack

Share this post


Link to post
Share on other sites

Jack_mcs: you might try her web site then as far as help from her. As far as a point by point changelog, no sorry I just don't even have the time to do that.

 

Jaamor: You might try making queue false and see if you have access to your gv then. If not you probably haven't modified your checkout process properly.

 

giftkountry: did you modify your order_total file, thinking you were fixing a bug by placing a .= somewhere instead of just leaving it as an =


(my knowledge is so small you would think that an ant was a genius in comparison)

Share this post


Link to post
Share on other sites

Help! :(

 

I'm still in urgent need for an authorize.net fix. The correct discounted total displays on screen, in the customer order confirmation email and in the admin area. Thought all was well and emailed hundreds of discount coupons to perspective customers. Many orders are being placed as a result.

 

BUT, when the transaction goes to authorize.net, the amount does not include the discount and customer credit cards are being billed for the non-discounted amount. A major problem.

 

Relevant info:

 

1. Using Authorizenet ADC Direct Connection w/cvv and transaction key.

2. This is the only payment module being used.

3. Using the 510b release of ccgv.

 

I would truly appreciate any help with this. Thank you!!


festina lente

Share this post


Link to post
Share on other sites
Sorry to bug you Strider, but can you please add the Gift Voucher Balance info and Send Gift Voucher link to the account.php file? B)

 

Adding a new box under the E-mail Notifications box that works like the shopping cart box would be great. I don't use the shopping cart box, so the GV info doesn't show.

 

Example:

 

Title-> Gift Vouchers / Coupons

 

Green arrow -> Gift Voucher Balance $50.00

Green arrow -> Send Gift Voucher

 

I've tried to make it work, but no luck.

I modified the header code below to eliminate the shopping cart box and show the shopping cart info and GV info in the header at the top of the screen.

 

In the /catalog/includes/header.php file find the following code:

 

// check session.auto_start is disabled
?if ( (function_exists('ini_get')) && (WARN_SESSION_AUTO_START == 'true') ) {
? ?if (ini_get('session.auto_start') == '1') {
? ? ?$messageStack->add('header', WARNING_SESSION_AUTO_START, 'warning');
? ?}
?}

?if ( (WARN_DOWNLOAD_DIRECTORY_NOT_READABLE == 'true') && (DOWNLOAD_ENABLED == 'true') ) {
? ?if (!is_dir(DIR_FS_DOWNLOAD)) {
? ? ?$messageStack->add('header', WARNING_DOWNLOAD_DIRECTORY_NON_EXISTENT, 'warning');
? ?}
?}

?if ($messageStack->size('header') > 0) {
? ?echo $messageStack->output('header');
?}
?>

 

Add this code after it and modify its format to suit your needs and store layout:

 

<!-- Start Header Mod Here -->
<!-- Delete existing code section and post to the Design Notes. ?Replace with code section below -->

<table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-top: 10">
?<tr class="header">
? ?<td valign="middle" width="265"><?php echo '<a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_image(DIR_WS_IMAGES . 'your_logo.gif', 'Your logo image') . '</a>'; ?></td>
? ?<td width="350" align="center" valign="center" class="header">
? <table width="295" border="0" align="center" cellpadding="0" cellspacing="5">
? ? <tr class="header">
? ?<td width="199" align="right" class="header">
? ? ?<?php
? ?echo '<a href="' . tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '">' . HEADER_TITLE_CART_ITEM_COUNT . '</a> ' . $cart->count_contents() . '<br>';
? ?echo HEADER_TITLE_CURRENT_TOTAL . ' ' . $currencies->format($cart->show_total());
?	?>
? ?</td>
? ?<td width="96" align="left" valign="center"><?php echo '  <a href="' . tep_href_link(FILENAME_SHOPPING_CART, '', 'SSL') . '">' . tep_image(DIR_WS_IMAGES . 'header_cart.gif', HEADER_TITLE_CART_CONTENTS) . '</a>'; ?></td>
?</tr>

<!-- ICW ADDED FOR CREDIT CLASS GV -->
<tr class="header">
<td colspan="2" align="center" class="header">
<?php
// ICW ADDED FOR CREDIT CLASS GV
?if (tep_session_is_registered('customer_id')) {
? ?$gv_query = tep_db_query("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . $customer_id . "'");
? ?$gv_result = tep_db_fetch_array($gv_query);
? ?if ($gv_result['amount'] > 0 ) {
?echo tep_draw_separator();
?echo VOUCHER_BALANCE . ' ' . $currencies->format($gv_result['amount']);
?echo ' | <a href="' . tep_href_link(FILENAME_GV_SEND, '', 'SSL') . '">' . BOX_SEND_TO_FRIEND . '</a>';
? ?}
?}
?if (tep_session_is_registered('gv_id')) {
? ?$gv_query = tep_db_query("select coupon_amount from " . TABLE_COUPONS . " where coupon_id = '" . $gv_id . "'");
? ?$coupon = tep_db_fetch_array($gv_query);
echo tep_draw_separator() . ' ' . VOUCHER_REDEEMED . ' ' . $currencies->format($coupon['coupon_amount']);
?}
?if (tep_session_is_registered('cc_id') && $cc_id) {
? ?echo tep_draw_separator() . ' ' . CART_COUPON . ' ' . '<a href="javascript:couponpopupWindow(\'' . tep_href_link(FILENAME_POPUP_COUPON_HELP, 'cID=' . $cc_id) . '\')">' . CART_COUPON_INFO . '</a>';
?}
// ADDED FOR CREDIT CLASS GV END ADDITTION ? ?
?>
</td>
</tr>
<!-- EOM Credit Class GV Module -->

? </table>
</td>
? ?<td align="right" valign="bottom" class="header">  </td>
?</tr>
</table>

 

I hope this helps.

I added a smidgen to this bit of enhanced coding myself (OSC MS.2.2) - when the customer selects the send gift voucher link and are brought to the gv_send.php page it shows their available GV balance. With a bit of wordage thrown in.

 

Edit to suit.

 

FILE to edit - gv_send.php

 

At approximately line 183 FIND

 

            <td class="main"><?php echo ENTRY_AMOUNT; ?><br><?php echo tep_draw_input_field('amount', $HTTP_POST_VARS['amount'], '', '', false); if ($error) echo $error_amount; ?></td>

 

REPLACE with

 

            <td class="main"><?php echo ENTRY_AMOUNT; ?><br><?php echo tep_draw_input_field('amount', $HTTP_POST_VARS['amount'], '', '', false); if ($error) echo $error_amount; ?>
<?php
// ICW ADDED FOR CREDIT CLASS GV
if (tep_session_is_registered('customer_id')) {
  $gv_query = tep_db_query("select amount from " . TABLE_COUPON_GV_CUSTOMER . " where customer_id = '" . $customer_id . "'");
  $gv_result = tep_db_fetch_array($gv_query);
  if ($gv_result['amount'] > 0 ) {
echo '       ' . tep_image(DIR_WS_IMAGES . 'arrow_green.gif', ''), '  <B>Your available Gift  ' . VOUCHER_BALANCE . ' is ' . $currencies->format($gv_result['amount']) . '</B><P>You may send up to that amount. The amount you choose to send will then be deducted from your Gift Voucher balance. As your current balance is already paid for there are no fees associated with sending this Gift Voucher.';
  }
}
?>
</td>

Share this post


Link to post
Share on other sites

FRED: This is my ot_coupons.php file. I don't see anything in there that would cause this.

 

STRIDER: The only thing I done was upload the files per the instructions in the contribution into a new installation. So, not sure what I did wrong

 

<?php
/*
$Id: ot_coupon.php,v 1.1.2.37.3 2004/01/01 22:52:59 Strider Exp $
$Id: ot_coupon.php,v 1.1.2.37 2003/07/24 22:52:59 Strider-Cote Exp $
$Id: ot_coupon.php,v 1.1.2.36 2003/05/14 22:52:59 wilt Exp $

osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com/

Copyright ? 2002 osCommerce

Released under the GNU General Public License
*/

class ot_coupon {
var $title, $output;

function ot_coupon() {

$this->code = 'ot_coupon';
$this->header = MODULE_ORDER_TOTAL_COUPON_HEADER;
$this->title = MODULE_ORDER_TOTAL_COUPON_TITLE;
$this->description = MODULE_ORDER_TOTAL_COUPON_DESCRIPTION;
$this->user_prompt = '';
$this->enabled = MODULE_ORDER_TOTAL_COUPON_STATUS;
$this->sort_order = MODULE_ORDER_TOTAL_COUPON_SORT_ORDER;
$this->include_shipping = MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING;
$this->include_tax = MODULE_ORDER_TOTAL_COUPON_INC_TAX;
$this->calculate_tax = MODULE_ORDER_TOTAL_COUPON_CALC_TAX;
$this->tax_class = MODULE_ORDER_TOTAL_COUPON_TAX_CLASS;
$this->credit_class = true;
$this->output = array();

}

function process() {
global $PHP_SELF, $order, $currencies;


$order_total=$this->get_order_total();
$od_amount = $this->calculate_credit($order_total);
$tod_amount = 0.0; //Fred
$this->deduction = $od_amount;
if ($this->calculate_tax != 'None') { //Fred - changed from 'none' to 'None'!
 $tod_amount = $this->calculate_tax_deduction($order_total, $this->deduction, $this->calculate_tax);
}

if ($od_amount > 0) {
 $order->info['total'] = $order->info['total'] - $od_amount;
 $this->output[] = array('title' => $this->title . ':' . $this->coupon_code .':','text' => '<b>-' . $currencies->format($od_amount) . '</b>', 'value' => $od_amount); //Fred added hyphen
}
}

function selection_test() {
return false;
}


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

function use_credit_amount() {
return $output_string;
}


function credit_selection() {
global $customer_id, $currencies, $language;
$selection_string = '';
$selection_string .= '<tr>' . "\n";
$selection_string .= ' <td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') .'</td>';
$selection_string .= ' <td class="main">' . "\n";
$image_submit = '<input type="image" name="submit_redeem" onClick="submitFunction()" src="' . DIR_WS_LANGUAGES . $language . '/images/buttons/button_redeem.gif" border="0" alt="' . IMAGE_REDEEM_VOUCHER . '" title = "' . IMAGE_REDEEM_VOUCHER . '">';
$selection_string .= TEXT_ENTER_COUPON_CODE . tep_draw_input_field('gv_redeem_code') . '</td>';
$selection_string .= ' <td align="right">' . $image_submit . '</td>';
$selection_string .= ' <td width="10">' . tep_draw_separator('pixel_trans.gif', '10', '1') . '</td>';
$selection_string .= '</tr>' . "\n";
return $selection_string;
}


function collect_posts() {
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, 'error_message=' . 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, 'error_message=' . 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, 'error_message=' . 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, 'error_message=' . 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, 'error_message=' . urlencode(ERROR_INVALID_USES_USER_COUPON . $coupon_result['uses_per_user'] . TIMES ), 'SSL'));
 }
 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
 // $_SESSION['cc_id'] = $coupon_result['coupon_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
}
if ($HTTP_POST_VARS['submit_redeem_coupon_x'] && !$HTTP_POST_VARS['gv_redeem_code']) tep_redirect(tep_href_link(FILENAME_CHECKOUT_PAYMENT, 'error_message=' . urlencode(ERROR_NO_REDEEM_CODE), 'SSL'));
}
}

function calculate_credit($amount) {
global $customer_id, $order, $cc_id;
//$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) ) {
 $coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");
 if (tep_db_num_rows($coupon_query) !=0 ) {
	 $coupon_result = tep_db_fetch_array($coupon_query);
	 $this->coupon_code = $coupon_result['coupon_code'];
	 $coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS ." where coupon_code = '". $coupon_result['coupon_code'] . "'");
	 $get_result = tep_db_fetch_array($coupon_get);
	 $c_deduct = $get_result['coupon_amount'];
	 if ($get_result['coupon_type']=='S') $c_deduct = $order->info['shipping_cost'];
	 if ($get_result['coupon_minimum_order'] <= $this->get_order_total()) {
   if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {
  	 for ($i=0; $i<sizeof($order->products); $i++) {
     if ($get_result['restrict_to_products']) {
    	 $pr_ids = split("[,]", $get_result['restrict_to_products']);
    	 for ($ii = 0; $ii < count($pr_ids); $ii++) {
       if ($pr_ids[$ii] == tep_get_prid($order->products[$i]['id'])) {
      	 if ($get_result['coupon_type'] == 'P') {
        	 /* Fixes to Gift Voucher module 5.03
        	 =================================
        	 Submitted by Rob Cote, robc@traininghott.com

        	 original code: $od_amount = round($amount*10)/10*$c_deduct/100;
        	 $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
        	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
        	 */
        	 //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
        	 $pr_c = $this->product_price($pr_ids[$ii]); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!
        	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
        	 $od_amount = $od_amount + $pod_amount;
         } else {
        	 $od_amount = $c_deduct;
         }
      	 }
       }
    	 } else {
       $cat_ids = split("[,]", $get_result['restrict_to_categories']);
       for ($i=0; $i<sizeof($order->products); $i++) {
      	 $my_path = tep_get_product_path(tep_get_prid($order->products[$i]['id']));
      	 $sub_cat_ids = split("[_]", $my_path);
      	 for ($iii = 0; $iii < count($sub_cat_ids); $iii++) {
         for ($ii = 0; $ii < count($cat_ids); $ii++) {
        	 if ($sub_cat_ids[$iii] == $cat_ids[$ii]) {
           if ($get_result['coupon_type'] == 'P') {
          	 /* Category Restriction Fix to Gift Voucher module 5.04
          	 Date: August 3, 2003
          	 =================================
          	 Nick Stanko of UkiDev.com, nick@ukidev.com

          	 original code:
          	 $od_amount = round($amount*10)/10*$c_deduct/100;
          	 $pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
          	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
          	 */
          	 //$od_amount = round($amount*10)/10*$c_deduct/100;
          	 //$pr_c = $order->products[$i]['final_price']*$order->products[$i]['qty'];
          	 $pr_c = $this->product_price(tep_get_prid($order->products[$i]['id'])); //Fred 2003-10-28, fix for the row above, otherwise the discount is calc based on price excl VAT!
          	 $pod_amount = round($pr_c*10)/10*$c_deduct/100;
          	 $od_amount = $od_amount + $pod_amount;
           } else {
          	 $od_amount = $c_deduct;
           }
        	 }
         }
      	 }
       }
    	 }
     }
  	 } else {
     if ($get_result['coupon_type'] !='P') {
    	 $od_amount = $c_deduct;
     } else {
    	 $od_amount = $amount * $get_result['coupon_amount'] / 100;
     }
  	 }
   }
	 }
 if ($od_amount>$amount) $od_amount = $amount;
 }
return $od_amount;
}

function calculate_tax_deduction($amount, $od_amount, $method) {
global $customer_id, $order, $cc_id, $cart;
//$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
$coupon_query = tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id = '" . $cc_id . "'");
if (tep_db_num_rows($coupon_query) !=0 ) {
 $coupon_result = tep_db_fetch_array($coupon_query);
 $coupon_get = tep_db_query("select coupon_amount, coupon_minimum_order, restrict_to_products, restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code = '". $coupon_result['coupon_code'] . "'");
 $get_result = tep_db_fetch_array($coupon_get);
 if ($get_result['coupon_type'] != 'S') {

	 //RESTRICTION--------------------------------
	 if ($get_result['restrict_to_products'] || $get_result['restrict_to_categories']) {
   // What to do here.
   // Loop through all products and build a list of all product_ids, price, tax class
   // at the same time create total net amount.
   // then
   // for percentage discounts. simply reduce tax group per product by discount percentage
   // or
   // for fixed payment amount
   // calculate ratio based on total net
   // for each product reduce tax group per product by ratio amount.
   $products = $cart->get_products();
   $valid_product = false;
   for ($i=0; $i<sizeof($products); $i++) {
   $valid_product = false;
  	 $t_prid = tep_get_prid($products[$i]['id']);
  	 $cc_query = tep_db_query("select products_tax_class_id from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
  	 $cc_result = tep_db_fetch_array($cc_query);
  	 if ($get_result['restrict_to_products']) {
     $pr_ids = split("[,]", $get_result['restrict_to_products']);
     for ($p = 0; $p < sizeof($pr_ids); $p++) {
    	 if ($pr_ids[$p] == $t_prid) $valid_product = true;
     }
  	 }
  	 if ($get_result['restrict_to_categories']) {
     $cat_ids = split("[,]", $get_result['restrict_to_categories']);
     for ($c = 0; $c < sizeof($cat_ids); $c++) {
    	 $cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $products_id . "' and categories_id = '" . $cat_ids[$i] . "'");
    	 if (tep_db_num_rows($cat_query) !=0 ) $valid_product = true;
     }
  	 }
  	 if ($valid_product) {
     $price_excl_vat = $products[$i]['final_price'] * $products[$i]['quantity']; //Fred - added
     $price_incl_vat = $this->product_price($t_prid); //Fred - added
     $valid_array[] = array('product_id' => $t_prid, 'products_price' => $price_excl_vat, 'products_tax_class' => $cc_result['products_tax_class_id']); //jason //Fred - changed from $products[$i]['final_price'] 'products_tax_class' => $cc_result['products_tax_class_id']);
//      $total_price += $price_incl_vat; //Fred - changed
     $total_price += $price_excl_vat; // changed
  	 }
   }
   if (sizeof($valid_array) > 0) { // if ($valid_product) {
  	 if ($get_result['coupon_type'] == 'P') {
     $ratio = $get_result['coupon_amount']/100;
  	 } else {
     $ratio = $od_amount / $total_price;
  	 }
  	 if ($get_result['coupon_type'] == 'S') $ratio = 1;
  	 if ($method=='Credit Note') {
     $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
     $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
     if ($get_result['coupon_type'] == 'P') {
    	 $tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate;
     } else {
    	 $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100;
     }
     $order->info['tax_groups'][$tax_desc] -= $tod_amount;
     $order->info['total'] -= $tod_amount; //  need to modify total ...OLD
     $order->info['tax'] -= $tod_amount; //Fred - added
  	 } else {
     for ($p=0; $p<sizeof($valid_array); $p++) {
    	 $tax_rate = tep_get_tax_rate($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
    	 $tax_desc = tep_get_tax_description($valid_array[$p]['products_tax_class'], $order->delivery['country']['id'], $order->delivery['zone_id']);
    	 if ($tax_rate > 0) {
       //Fred $tod_amount[$tax_desc] += ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; //OLD
       $tod_amount = ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // calc total tax Fred - added
       $order->info['tax_groups'][$tax_desc] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio;
       $order->info['total'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust total
       $order->info['tax'] -= ($valid_array[$p]['products_price'] * $tax_rate)/100 * $ratio; // adjust tax -- Fred - added
    	 }
     }
  	 }
   }
   //NO RESTRICTION--------------------------------
	 } else {
   if ($get_result['coupon_type'] =='F') {
  	 $tod_amount = 0;
  	 if ($method=='Credit Note') {
     $tax_rate = tep_get_tax_rate($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
     $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
     $tod_amount = $od_amount / (100 + $tax_rate)* $tax_rate;
     $order->info['tax_groups'][$tax_desc] -= $tod_amount;
  	 } else {
//      $ratio1 = $od_amount/$amount;   // this produces the wrong ratipo on fixed amounts
     reset($order->info['tax_groups']);
     while (list($key, $value) = each($order->info['tax_groups'])) {
    	 $ratio1 = $od_amount/($amount-$order->info['tax_groups'][$key]); ////debug
    	 $tax_rate = tep_get_tax_rate_from_desc($key);
    	 $net = $tax_rate * $order->info['tax_groups'][$key];
    	 if ($net>0) {
       $god_amount = $order->info['tax_groups'][$key] * $ratio1;
       $tod_amount += $god_amount;
       $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
    	 }
     }
  	 }
  	 $order->info['total'] -= $tod_amount; //OLD
  	 $order->info['tax'] -= $tod_amount; //Fred - added
	 }
	 if ($get_result['coupon_type'] =='P') {
   $tod_amount=0;
   if ($method=='Credit Note') {
  	 $tax_desc = tep_get_tax_description($this->tax_class, $order->delivery['country']['id'], $order->delivery['zone_id']);
  	 $tod_amount = $order->info['tax_groups'][$tax_desc] * $od_amount/100;
  	 $order->info['tax_groups'][$tax_desc] -= $tod_amount;
   } else {
  	 reset($order->info['tax_groups']);
  	 while (list($key, $value) = each($order->info['tax_groups'])) {
     $god_amout=0;
     $tax_rate = tep_get_tax_rate_from_desc($key);
     $net = $tax_rate * $order->info['tax_groups'][$key];
     if ($net>0) {
    	 $god_amount = $order->info['tax_groups'][$key] * $get_result['coupon_amount']/100;
    	 $tod_amount += $god_amount;
    	 $order->info['tax_groups'][$key] = $order->info['tax_groups'][$key] - $god_amount;
     }
  	 }
   }
   $order->info['total'] -= $tod_amount; // have to modify total also
   $order->info['tax'] -= $tod_amount;
	 }
 }
}
}
return $tod_amount;
}

function update_credit_account($i) {
return false;
}

function apply_credit() {
global $insert_id, $customer_id, $REMOTE_ADDR, $cc_id;
//$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
if ($this->deduction !=0) {
 tep_db_query("insert into " . TABLE_COUPON_REDEEM_TRACK . " (coupon_id, redeem_date, redeem_ip, customer_id, order_id) values ('" . $cc_id . "', now(), '" . $REMOTE_ADDR . "', '" . $customer_id . "', '" . $insert_id . "')");
}
tep_session_unregister('cc_id');
}

function get_order_total() {
global $order, $cart, $customer_id, $cc_id;
//$cc_id = $_SESSION['cc_id']; //Fred commented out, do not use $_SESSION[] due to backward comp. Reference the global var instead.
$order_total = $order->info['total'];
// Check if gift voucher is in cart and adjust total
$products = $cart->get_products();
for ($i=0; $i<sizeof($products); $i++) {
 $t_prid = tep_get_prid($products[$i]['id']);
 $gv_query = tep_db_query("select products_price, products_tax_class_id, products_model from " . TABLE_PRODUCTS . " where products_id = '" . $t_prid . "'");
 $gv_result = tep_db_fetch_array($gv_query);
 if (ereg('^GIFT', addslashes($gv_result['products_model']))) {
	 $qty = $cart->get_quantity($t_prid);
	 $products_tax = tep_get_tax_rate($gv_result['products_tax_class_id']);
	 if ($this->include_tax =='false') {
   $gv_amount = $gv_result['products_price'] * $qty;
	 } else {
   $gv_amount = ($gv_result['products_price'] + tep_calculate_tax($gv_result['products_price'],$products_tax)) * $qty;
	 }
	 $order_total=$order_total - $gv_amount;
 }
}
if ($this->include_tax == 'false') $order_total=$order_total-$order->info['tax'];
if ($this->include_shipping == 'false') $order_total=$order_total-$order->info['shipping_cost'];
// OK thats fine for global coupons but what about restricted coupons
// where you can only redeem against certain products/categories.
// and I though this was going to be easy !!!
$coupon_query=tep_db_query("select coupon_code from " . TABLE_COUPONS . " where coupon_id='".$cc_id."'");
if (tep_db_num_rows($coupon_query) !=0) {
 $coupon_result=tep_db_fetch_array($coupon_query);
 $coupon_get=tep_db_query("select coupon_amount, coupon_minimum_order,restrict_to_products,restrict_to_categories, coupon_type from " . TABLE_COUPONS . " where coupon_code='".$coupon_result['coupon_code']."'");
 $get_result=tep_db_fetch_array($coupon_get);
 $in_cat = true;
 if ($get_result['restrict_to_categories']) {
	 $cat_ids = split("[,]", $get_result['restrict_to_categories']);
	 $in_cat=false;
	 for ($i = 0; $i < count($cat_ids); $i++) {
   if (is_array($this->contents)) {
  	 reset($this->contents);
  	 while (list($products_id, ) = each($this->contents)) {
     $cat_query = tep_db_query("select products_id from products_to_categories where products_id = '" . $products_id . "' and categories_id = '" . $cat_ids[$i] . "'");
     if (tep_db_num_rows($cat_query) !=0 ) {
    	 $in_cat = true;
    	 $total_price += $this->get_product_price($products_id);
     }
  	 }
   }
	 }
 }
 $in_cart = true;
 if ($get_result['restrict_to_products']) {

	 $pr_ids = split("[,]", $get_result['restrict_to_products']);

	 $in_cart=false;
	 $products_array = $cart->get_products();

	 for ($i = 0; $i < sizeof($pr_ids); $i++) {
   for ($ii = 1; $ii<=sizeof($products_array); $ii++) {
  	 if (tep_get_prid($products_array[$ii-1]['id']) == $pr_ids[$i]) {
     $in_cart=true;
     $total_price += $this->get_product_price($products_array[$ii-1]['id']);
  	 }
   }
	 }
	 $order_total = $total_price;
 }
}
return $order_total;
}

function get_product_price($product_id) {
global $cart, $order;
$products_id = tep_get_prid($product_id);
// products price
$qty = $cart->contents[$product_id]['qty'];
$product_query = tep_db_query("select products_id, products_price, products_tax_class_id, products_weight from " . TABLE_PRODUCTS . " where products_id='" . $product_id . "'");
if ($product = tep_db_fetch_array($product_query)) {
 $prid = $product['products_id'];
 $products_tax = tep_get_tax_rate($product['products_tax_class_id']);
 $products_price = $product['products_price'];
 $specials_query = tep_db_query("select specials_new_products_price from " . TABLE_SPECIALS . " where products_id = '" . $prid . "' and status = '1'");
 if (tep_db_num_rows ($specials_query)) {
	 $specials = tep_db_fetch_array($specials_query);
	 $products_price = $specials['specials_new_products_price'];
 }
 if ($this->include_tax == 'true') {
	 $total_price += ($products_price + tep_calculate_tax($products_price, $products_tax)) * $qty;
// 	 echo("total price = " . $total_price . " products_price = " . $products_price . " products_tax = " . $products_tax . "<br>");

 } else {
	 $total_price += $products_price * $qty;
 }

 // attributes price
 if (isset($cart->contents[$product_id]['attributes'])) {
	 reset($cart->contents[$product_id]['attributes']);
	 while (list($option, $value) = each($cart->contents[$product_id]['attributes'])) {
   $attribute_price_query = tep_db_query("select options_values_price, price_prefix from " . TABLE_PRODUCTS_ATTRIBUTES . " where products_id = '" . $prid . "' and options_id = '" . $option . "' and options_values_id = '" . $value . "'");
   $attribute_price = tep_db_fetch_array($attribute_price_query);
   if ($attribute_price['price_prefix'] == '+') {
  	 if ($this->include_tax == 'true') {
     $total_price += $qty * ($attribute_price['options_values_price'] + tep_calculate_tax($attribute_price['options_values_price'], $products_tax));
  	 } else {
     $total_price += $qty * ($attribute_price['options_values_price']);
  	 }
   } else {
  	 if ($this->include_tax == 'true') {
     $total_price -= $qty * ($attribute_price['options_values_price'] + tep_calculate_tax($attribute_price['options_values_price'], $products_tax));
  	 } else {
     $total_price -= $qty * ($attribute_price['options_values_price']);
  	 }
   }
	 }
 }
}
if ($this->include_shipping == 'true') {

 $total_price += $order->info['shipping_cost'];
}
return $total_price;
}

//Added by Fred -- BOF -----------------------------------------------------
//JUST RETURN THE PRODUCT PRICE (INCL ATTRIBUTE PRICES) WITH OR WITHOUT TAX
function product_price($product_id) {
$total_price = $this->get_product_price($product_id);
if ($this->include_shipping == 'true') $total_price -= $order->info['shipping_cost'];
return $total_price;
}
//Added by Fred -- EOF -----------------------------------------------------

function check() {
if (!isset($this->check)) {
 $check_query = tep_db_query("select configuration_value from " . TABLE_CONFIGURATION . " where configuration_key = 'MODULE_ORDER_TOTAL_COUPON_STATUS'");
 $this->check = tep_db_num_rows($check_query);
}

return $this->check;
}

function keys() {
return array('MODULE_ORDER_TOTAL_COUPON_STATUS', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS');
}

function install() {
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function, date_added) values ('Display Total', 'MODULE_ORDER_TOTAL_COUPON_STATUS', 'true', 'Do you want to display the Discount Coupon value?', '6', '1','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) values ('Sort Order', 'MODULE_ORDER_TOTAL_COUPON_SORT_ORDER', '9', 'Sort order of display.', '6', '2', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Shipping', 'MODULE_ORDER_TOTAL_COUPON_INC_SHIPPING', 'true', 'Include Shipping in calculation', '6', '5', 'tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Include Tax', 'MODULE_ORDER_TOTAL_COUPON_INC_TAX', 'true', 'Include Tax in calculation.', '6', '6','tep_cfg_select_option(array(\'true\', \'false\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, set_function ,date_added) values ('Re-calculate Tax', 'MODULE_ORDER_TOTAL_COUPON_CALC_TAX', 'None', 'Re-Calculate Tax', '6', '7','tep_cfg_select_option(array(\'None\', \'Standard\', \'Credit Note\'), ', now())");
tep_db_query("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) values ('Tax Class', 'MODULE_ORDER_TOTAL_COUPON_TAX_CLASS', '0', 'Use the following tax class when treating Discount Coupon as Credit Note.', '6', '0', 'tep_get_tax_class_title', 'tep_cfg_pull_down_tax_classes(', now())");
}

function remove() {
$keys = '';
$keys_array = $this->keys();
for ($i=0; $i<sizeof($keys_array); $i++) {
 $keys .= "'" . $keys_array[$i] . "',";
}
$keys = substr($keys, 0, -1);

tep_db_query("delete from " . TABLE_CONFIGURATION . " where configuration_key in (" . $keys . ")");
}
}
?>

Share this post


Link to post
Share on other sites

I have the option set to give a GV for a new customer. In the email that is sent out, the links in the message are just plain text. Does anyone know what I need to change to make them actuall links?

 

Jack

Share this post


Link to post
Share on other sites

Jackmcs: sounds like you have your email set to text only


(my knowledge is so small you would think that an ant was a genius in comparison)

Share this post


Link to post
Share on other sites

Hi Sorry, I haven't had a chance to read through the 60+ pages in this thread :) so don't shoot me if this is already covered.

 

I can't seem to get a coupon with restrict_to_products has a product with attributes.

 

I.e.

I have a 50% coupon "FIFTY"

WHERE: Valid Product List :: 1,7

 

1 x You've Got Mail $34.99

1 x Matrox G200 MMS

- Memory: 4 mb

- Model: Value $299.99

 

Sub-Total: $334.98

Flat Rate (Best Way): $5.00

Discount Coupons:FIFTY: -$17.50

FL TAX 7.0%: $12.07

Total: $334.55

 

Is this a bug/feature?? Anyone have a fix for it?

Share this post


Link to post
Share on other sites
Jackmcs: sounds like you have your email set to text only

I have the option set to true for html emails. Plus, the message contains text that is in bold like Permanent Cart. It is just the links that are not coming out correctly. If I compose an email containing a link from the admin panel that comes through ok. So for some reason, it is just the email being sent from the GV contribution. I went into gv_mail.php and disabled the part where it checks for text or html and just left the $mimemessage->add_html($message); in but got the same result. Can you point to somewhere else in the code that I could look at that might be causing this problem?

 

Jack

Share this post


Link to post
Share on other sites

Also, just curious if any of you all have had to combat the problem where a customer sign's up.. gets a gift voucher. Doesn't purchase but rather signs up with another e-mail address.. (gets another gift voucher) and so on and so forth then right before checkout uses the codes to get his voucher balance high enough to purchase without spending a red ?

 

I just tried it. It worked like a charm. Speaking of which.. does Amazon give you a gift voucher for registering on their site? :>

Share this post


Link to post
Share on other sites

Well, I just installed: ccgv_510b

 

All is working well, purchase of vouchers gets placed into the customer's voucher balance, etc... the only problem is: although a customer has a voucher balance, there is NO TICK BOX on the payment page, or no way for them to use the voucher balance.

 

I am using ms2.2 latest milestone. Any idea why the tick box is not showing up?

 

Thanks,

Priest

Share this post


Link to post
Share on other sites

probably your sort order priest


(my knowledge is so small you would think that an ant was a genius in comparison)

Share this post


Link to post
Share on other sites

Here is my sort order:

 

Discount Vouchers 740

Gift Vouchers 9

Low Order Fee

Shipping 2

Sub-Total 1

Tax 3

Total 900

 

And here are my Gift Voucher values:

Display Total

true

Sort Order

9

Queue Purchases

false

Include Shipping

true

Include Tax

true

Re-calculate Tax

none

Tax Class

none

Credit Including Tax

false

 

Also, is there one certain file which contains the code for this "Tick Box?" I want to try re-verifying the changes to that file or possible upload the file that came with the latest contribution to see if maybe that is where the error is.

 

Thanks,

Priest

Share this post


Link to post
Share on other sites

change your sort order to

 

Gift Vouchers 740

Discount Vouchers 9

Low Order Fee

Shipping 2

Sub-Total 1

Tax 3

Total 900


(my knowledge is so small you would think that an ant was a genius in comparison)

Share this post


Link to post
Share on other sites

That fixed the problem! Of course, I am still having the same problem I've been having since several versions back: when the GV is applied and the remaining balance is $0.00, I get the error:

 

There has been an error processing your credit card. Please try again.

 

And this loops back to the payment page when instead it should bypass any contact to 2CheckOut and go directly to the checkout_success.php page.

 

I am using the pm2checkout contribution which changes it up so that customers do not have to type in their 2CO credit card information on my site, instead it prompts for the info once the order details are passed to the secure 2CO page.

 

I've been combating this by making GV not include shipping so that there is always an amount to be paid, but I'd like to look into this a bit further so that I don't have to resort to that.

 

Anyway, as always, thanks for your help Strider!

 

-Priest-

Share this post


Link to post
Share on other sites

EDIT: I just reverted back to the original 2CheckOut payment module (the one that comes with the OSC download and requires you to input your card details on the site) and I still encounter the same "credit card error" so maybe it just doesn't like 2CO or the 2CO module!?

 

-Priest-

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×