Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Discount Coupon Codes


kgt

Recommended Posts

Dear,

 

I have installed this contribution, but still there is one thing that doesn't go right in my eyes.

 

I give free shipping to my customers if they buy for 75? or more. When they order something from 75.10? for example, they will only be able to choose the free shipping at checkout.

Only after that, they will have to enter their code to benefit from the discount. So the total of the order will be under 75?, but still they will receive the free shipping.

 

Does anyone know how this can be solved?

Thank you so much for helping me out!

 

Regards,

Vicky

 

This should be easy enough to solve. Give me a few hours and I'll see if I can post a quick solution.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Would the fact that I dont have any tax on my items cause a problem with this contrib?

 

I am looking for something that will let me do the following.

 

- Set a discount code that I can give to people that will give them 10% off the final price (before shipping) indeffinately (or for given period of time) (This is not set to a certain person and can be used as many times as they want and by as many people that want to use it.)

 

- Create gift vouchers that can be given to people (2 differnent types if possible)

- for a specific person

- NOT for a specific person

These can either have a time limit on them or not.

 

Will this contrib be able to do the above?

 

I'm not sure exactly what your tax problem is. Perhaps you can give a detailed description?

 

As far as your other question:

 

I don't know what you mean by "Create gift vouchers that can be given to people (2 differnent types if possible)" as it's very vague. The answer to "NOT for a specific person" and "These can either have a time limit on them or not." is yes. The answer to "for a specific person" is no.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Ok, i'll try and check the topic now and then and hope you can find a solution for me!

Thank you!

Regards,

Vicky

 

In checkout_confirmation.php line 109-111 find this code:

 

		if( count( $error_message ) < 1 ) { //if we have passed all tests (no error message), register the coupon in the session
		if (!tep_session_is_registered('coupon')) tep_session_register('coupon');
		$coupon = tep_db_prepare_input( $HTTP_POST_VARS['coupon'] );

 

And right after it, add this code:

 

			//check if there is free shipping
		if( MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true' ) {
			include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
			//if free shipping is enabled, make sure te discount does not bring the order total below free shipping limit
			if( $order->info['shipping_method'] == FREE_SHIPPING_TITLE ) { //if free shipping is the selected shipping method
				if( ( $order->info['total'] - $order->info['shipping_cost'] ) < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER ) { //if the discount lowers the total below the free shipping limit
					tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( 'Your order total is now below the free shipping minimum.' ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method
				}
			}
		}

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

I am still getting the same error code when I try to generate a coupon. No matter what I put in the blanks.

 

Thanks Troy

 

Make sure lines 93-133 in admin/coupons.php looks like this:

 

	switch ($action) {
  case 'insert':
	tep_db_query($sql = "insert into " . TABLE_DISCOUNT_COUPONS . " (
				coupons_id,
				coupons_description,
				coupons_discount_percent,
				date_start,
				date_end,
				max_use,
				min_order,
				number_available)
				values ('" .
				( !empty( $HTTP_POST_VARS["coupons_id"] ) ? tep_db_input( $HTTP_POST_VARS["coupons_id"] ) : createRandomCoupon() ). "', '" .
				tep_db_input( $HTTP_POST_VARS['coupons_description'] ) . "', '" .
				tep_db_input( $HTTP_POST_VARS['coupons_discount_percent'] ) ."', " .
				( !empty( $HTTP_POST_VARS['date_start'] ) ? '"'.parseDate( $HTTP_POST_VARS['date_start'], DATE_FORMAT_SHORT ).'"' : 'null' ). ", ".
				( !empty( $HTTP_POST_VARS['date_end'] ) ? '"'.parseDate( $HTTP_POST_VARS['date_end'], DATE_FORMAT_SHORT ).'"' : 'null' ). ", ".
				( !empty( $HTTP_POST_VARS['max_use'] ) ? (int)$HTTP_POST_VARS['max_use'] : 0 ).", ".
						( !empty( $HTTP_POST_VARS['min_order'] ) ? $HTTP_POST_VARS['min_order'] : 0 ).", ".
						( !empty( $HTTP_POST_VARS['number_available'] ) ? (int)$HTTP_POST_VARS['number_available'] : 0 ).")");
	tep_redirect( tep_href_link( FILENAME_DISCOUNT_COUPONS, 'page=' . $HTTP_GET_VARS['page'] ) );
	break;
  case 'update':
	tep_db_query($sql = "update " . TABLE_DISCOUNT_COUPONS . " set
				coupons_description = '" . tep_db_input( $HTTP_POST_VARS['coupons_description'] ) . "',
				coupons_discount_percent = '" . tep_db_input( $HTTP_POST_VARS['coupons_discount_percent'] ) . "',
				date_start = " . ( !empty( $HTTP_POST_VARS['date_start'] ) ? '"'.parseDate( $HTTP_POST_VARS['date_start'], DATE_FORMAT_SHORT ).'"' : 'null' ) . ",
				date_end = " .( !empty( $HTTP_POST_VARS['date_end'] ) ? '"'.parseDate( $HTTP_POST_VARS['date_end'], DATE_FORMAT_SHORT ).'"' : 'null' ). ",
						max_use = " .( !empty( $HTTP_POST_VARS['max_use'] ) ? (int)$HTTP_POST_VARS['max_use'] : 0 ). ",
						min_order = ".( !empty( $HTTP_POST_VARS['min_order'] ) ? $HTTP_POST_VARS['min_order'] : 0 ). ",
						number_available = " .( !empty( $HTTP_POST_VARS['number_available'] ) ? (int)$HTTP_POST_VARS['number_available'] : 0 ). "
				where coupons_id = '" . tep_db_input( $HTTP_POST_VARS['coupons_id'] ) . "'");
	tep_redirect(tep_href_link(FILENAME_DISCOUNT_COUPONS, 'page=' . $HTTP_GET_VARS['page'] . '&cID=' . $HTTP_POST_VARS['coupons_id']));
	break;
  case 'deleteconfirm':
	$coupons_id = tep_db_prepare_input($HTTP_GET_VARS['cID']);
	tep_db_query($sql = "delete from " . TABLE_DISCOUNT_COUPONS . " where coupons_id = '" .$coupons_id. "'");
	tep_db_query($sql = "delete from " . TABLE_DISCOUNT_COUPONS_TO_ORDERS . " where coupons_id = '" .$coupons_id. "'");
	tep_redirect(tep_href_link(FILENAME_DISCOUNT_COUPONS, 'page=' . $HTTP_GET_VARS['page']));
	break;
}

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

This looks like exactly what I will need for my site! However, before I try to install it, I was wondering if this will work together with Vger's Authorize.net AIM contribution. I just installed that and got it working, but in the support forum for that contribution people had said they had problems with the CCGV coupon contriubtion working with it, and that's why I am looking for alternate coupon contributions. Has anybody else installed the authorize.net AIM contribution with this and got it to work, or is it a waste of time? Thanks so much.

 

~Zach

Link to comment
Share on other sites

This looks like exactly what I will need for my site! However, before I try to install it, I was wondering if this will work together with Vger's Authorize.net AIM contribution. I just installed that and got it working, but in the support forum for that contribution people had said they had problems with the CCGV coupon contriubtion working with it, and that's why I am looking for alternate coupon contributions. Has anybody else installed the authorize.net AIM contribution with this and got it to work, or is it a waste of time? Thanks so much.

 

I cannot say for sure, since I haven't tested it and don't really have time to test, but I think it will work. The reason why is the difference between how and when CCGV and Discount Coupon Codes calculate the discount.

 

I believe CCGV calculates the discount in the order_total module. DCC calculates the discount in the order class. This means that when the order object is created, DCC applies the discount to the actual order total. So when the authorize.net module looks up the order total, it gets a total with the discount applied.

 

CCGV calculates and applies the discount at a later stage of code execution: just before the total lines actually get displayed. I suspect that if people are having trouble getting the two modules to work together it's because of this facet of how CCGV works (or it may have changed since I last looked at it). There are positives and negatives to both approaches (calculating the discount "later" vs "earlier" in terms of code execution).

 

I would set up a test site to test the two contributions together before you make changes to your live site - unless you're still developing it and it doesn't matter. Backup before you make the changes so you can easily restore to a working state.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Thanks kgt, great explanation. I'll give it a try and see if it works.

 

One thing I was just wondering about this contribution though, on what page does the customer enter their code? (ex. checkout_shipping, checkout_payment, etc) Thanks.

 

~Zach

Link to comment
Share on other sites

In checkout_confirmation.php line 109-111 find this code:

 

		if( count( $error_message ) < 1 ) { //if we have passed all tests (no error message), register the coupon in the session
		if (!tep_session_is_registered('coupon')) tep_session_register('coupon');
		$coupon = tep_db_prepare_input( $HTTP_POST_VARS['coupon'] );

 

And right after it, add this code:

 

			//check if there is free shipping
		if( MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING == 'true' ) {
			include(DIR_WS_LANGUAGES . $language . '/modules/order_total/ot_shipping.php');
			//if free shipping is enabled, make sure te discount does not bring the order total below free shipping limit
			if( $order->info['shipping_method'] == FREE_SHIPPING_TITLE ) { //if free shipping is the selected shipping method
				if( ( $order->info['total'] - $order->info['shipping_cost'] ) < MODULE_ORDER_TOTAL_SHIPPING_FREE_SHIPPING_OVER ) { //if the discount lowers the total below the free shipping limit
					tep_redirect( tep_href_link( FILENAME_CHECKOUT_SHIPPING, 'error_message=' . urlencode( 'Your order total is now below the free shipping minimum.' ), 'SSL' ) ); //redirect to the shipping page to reselect the shipping method
				}
			}
		}

 

 

I couldn't find the module free shipping. where can I get it? I am having troubles with this also. Thank you.

Link to comment
Share on other sites

Thanx, that solved it.

 

 

 

hi again, it seems that I'm running into another problem right now, generating the coupon code and applying it to the price to get the discount seem to work well, but the problem that I'm having now is when ever the order is confirmed at check out and the customer is being transfered to paypal for payment processing, after the payment when the customer clicks on the return to murchant button, the program is login the customer off and takes them back to the log your self in or creat a new account..........and the transaction do not get recorded, but the payment gets processed

 

I've done test runs for paypal before and all went well before the insalation of the discount coupon contri.

 

any ideas about what might be causing this problem? thank you so much for your help :)

Link to comment
Share on other sites

hi again, it seems that I'm running into another problem right now, generating the coupon code and applying it to the price to get the discount seem to work well, but the problem that I'm having now is when ever the order is confirmed at check out and the customer is being transfered to paypal for payment processing, after the payment when the customer clicks on the return to murchant button, the program is login the customer off and takes them back to the log your self in or creat a new account..........and the transaction do not get recorded, but the payment gets processed

 

I would suspect that the installation of this contribution and paypal not working anymore is actually just coincidence. Read through this thread for starters:

 

http://www.oscommerce.com/forums/index.php?sho...184766&st=0

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

...

Thank you so much, this really helped!

I've just tested it myself and it is really wonderful!

I'm so happy!!! :D :D :D :D :D :D :D

 

You did a great job. :thumbsup: I really like this contribution, and so do my customers!

I hope you will also be able to give us the opportunity to give an amount discount instead of percentage :blush: ...

 

Thank you and I will check out often!

 

Regards,

Vicky

Link to comment
Share on other sites

This looks like exactly what I will need for my site! However, before I try to install it, I was wondering if this will work together with Vger's Authorize.net AIM contribution. I just installed that and got it working, but in the support forum for that contribution people had said they had problems with the CCGV coupon contriubtion working with it, and that's why I am looking for alternate coupon contributions. Has anybody else installed the authorize.net AIM contribution with this and got it to work, or is it a waste of time? Thanks so much.

 

~Zach

 

No problem with the Anet AIM contribution, I have both (and about 30 other contribs) working in harmony.

 

This is one of the best contributions I've added.

 

I had a bit of trial and error getting it looking proper but with the "Display Subtotal with Applied Discount" set to true and the Discount Coupon getting the highest sort order of "1" the price, discount, subtotal, shipping and tax all look correct.

Link to comment
Share on other sites

I was wondering if the following is possible:

 

I use this contribution to give percentage discount to my customers.

Some products already have discount prices in the shop, but I don't want my customers to get extra discount for these items...

 

So the discount of this contribution should only count for non-promotional items.

Thanks for keeping me informed!

 

Best regards,

Vicky

Link to comment
Share on other sites

I added this contribution to my store and thought everything was working flawlessly until I started double-checking prices.

 

Come to find out somehow it would take the cart contents and multiply it by 2 and display that amount as the sub-total. For example if I had an (1) item in my cart that was listed at $120, the sub-total would display $240, and yes I double checked to make sure there was only 1 in the cart.

 

So after removing the edited files back to good clean copies I figured out which file was causing this. It was includes/classes/order.php

 

I copied the code straight over and have gone through it and cannot figure out why it is causing this. I have narrowed it down to this particular peice of code causing the issue.

 

 //$shown_price = tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty'];

	//kgt - discount coupon -----------------------------------------------------------------------
	$applied_discount = 0;
	$this_actual_shown_price = null;
if( !empty( $this->info['coupon'] ) ) {
  $check_code_query = tep_db_query($sql = "select * from " . TABLE_DISCOUNT_COUPONS . " where coupons_id = '" . $this->info['coupon'] . "'");
  $check_code = tep_db_fetch_array($check_code_query);
  $applied_discount = tep_add_tax( $this->products[$index]['final_price'] * $check_code['coupons_discount_percent'], $this->products[$index]['tax'] ) * $this->products[$index]['qty'];
  //$applied_discount = $this->products[$index]['final_price'] * $check_code['coupons_discount_percent'] * $this->products[$index]['qty'];
  if( isset( $this->info['applied_discount'][$this->products[$index]['tax_description']] ) ) {
	  $this->info['applied_discount'][$this->products[$index]['tax_description']] += $applied_discount;
	  } else {
	  $this->info['applied_discount'][$this->products[$index]['tax_description']] = $applied_discount;
	}
	if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_DISPLAY_SUBTOTAL == 'false' ) {
	  $this_actual_shown_price = (tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty']) - $applied_discount;
	  //$this_actual_shown_price = ( $this->products[$index]['final_price'] * $this->products[$index]['qty'] ) - $applied_discount;
	  $applied_discount = 0;
	}
}
$shown_price = (tep_add_tax($this->products[$index]['final_price'], $this->products[$index]['tax']) * $this->products[$index]['qty']) - $applied_discount;
//$shown_price = ( $this->products[$index]['final_price'] * $this->products[$index]['qty'] ) - $applied_discount;
$this->info['subtotal'] += $shown_price;
if( isset( $this_actual_shown_price ) ) $shown_price = $this_actual_shown_price;
//end kgt - discount coupon ------------------------------------------------------------------------

 

Any ideas?

Link to comment
Share on other sites

Hi guys!

I have installed this wonderful contribution but the weirdest thing happened:

when I apply a coupon of, let's say, $10, I get the following calaulation at the checkout_confirmation stage:

 

 

 

(the product costs $99...)

 

Discount Coupon jhkjhk applied: -$990.00

Sub-Total: $-891.00

Online Delivery $0.00

Total: $-891.00

 

 

How can I solve it?

 

Warm regards,

Elad

Link to comment
Share on other sites

Hi guys!

I have installed this wonderful contribution but the weirdest thing happened:

when I apply a coupon of, let's say, $10, I get the following calaulation at the checkout_confirmation stage:

(the product costs $99...)

 

Discount Coupon jhkjhk applied: -$990.00

Sub-Total: $-891.00

Online Delivery $0.00

Total: $-891.00

How can I solve it?

 

Warm regards,

Elad

 

Read the manual for detailed information on how to use the discounts. You cannot yet use fixed discounts. By putting in 10.00, you have specified a discount percent of 1000%, which is a discount of $990.00.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

Read the manual for detailed information on how to use the discounts. You cannot yet use fixed discounts. By putting in 10.00, you have specified a discount percent of 1000%, which is a discount of $990.00.

 

 

True. Thank you for that.

 

so is there any way I can reduce a fixed $10 from the item and not a % amount?

 

(Also, it might be good to change the dscription on the admin panel as it pretty confusing:

 

"Discount amount: $___ (Enter a dollar amount to take off the order price)" )

Link to comment
Share on other sites

I added this contribution to my store and thought everything was working flawlessly until I started double-checking prices.

 

Come to find out somehow it would take the cart contents and multiply it by 2 and display that amount as the sub-total. For example if I had an (1) item in my cart that was listed at $120, the sub-total would display $240, and yes I double checked to make sure there was only 1 in the cart.

 

So after removing the edited files back to good clean copies I figured out which file was causing this. It was includes/classes/order.php

 

I copied the code straight over and have gone through it and cannot figure out why it is causing this. I have narrowed it down to this particular peice of code causing the issue.

 

This code is only causing the issue in that it's the code that calculates the discount amount. The problem is stemming from somewhere else. It's difficult to tell for sure without doing some debugging. In includes/modules/order_total/ot_discount_coupons.php, uncomment this line:

 

//print_r( $order ); //kgt - use this to debug order object contents

 

It will print valuable information out when you go through the checkout process. Please copy and paste that information to me in an email.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

True. Thank you for that.

 

so is there any way I can reduce a fixed $10 from the item and not a % amount?

 

(Also, it might be good to change the dscription on the admin panel as it pretty confusing:

 

"Discount amount: $___ (Enter a dollar amount to take off the order price)" )

 

You're using the latest file added to the contribution. The additions to the contributions are not moderated, so anyone may add files. The person who added this either missed including some changes, or didn't understand how this contribution works. Perhaps he/she is watching this thread an may offer assistance.

 

I'm afraid I personally cannot help with this, as the code you downloaded is not even close to working as far as I can tell.

Contributions

 

Discount Coupon Codes

Donations

Link to comment
Share on other sites

I figured it out, systematcally debugging each line of code it finally dawned on me.

 

$this->info['subtotal'] += $shown_price;

 

That was from the multiple vendor shipping module and that was doubling it up. After removing that line everything works flawlessly.

 

Next question, if I want to have alpha-numeric coupon codes, do I just change the field type in the db?

Link to comment
Share on other sites

After looking into it, the randomly generated coupon codes are alphanumeric but upon further inspection, when I try to enter that into the checkout page it comes back and says invalid coupon code.

 

Any ideas?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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...