Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[Contribution] Discount Coupon Codes


kgt

Recommended Posts

Hallo,

 

I have no problem with this contribution, but something in my mind, I cannot figure out.

Is it possible to offer different shipping discounts on item quantity, without an input of the customer?

I can do this for one code, but if there are more codes.

 

For example:

2 items 10% shipping discount code 1

3 items 20% shipping discount code 2 etc.

 

My idea was, would it be possible to get the quantity value of the shopping basket automaticly in the input field of the coupon.

So I can make a hidden field and the customer get automaticly his discount, depending on his order quantity.

 

I hope, my english is understandable.

 

It would nice, if somebody could reply, thank you.

 

Nico

Link to comment
Share on other sites

I am running v2.2 RC2a, and I have encountered a really weird problem. My coupon code will work for all categories except for 1 in my shop. I do not have any category/product/manufacturer/customer exclusions set for the coupon code, and nothing I do will allow the coupon code to work for any products in this one category. Do you have any idea why the coupon code will not apply to this one category?

Link to comment
Share on other sites

  • 2 weeks later...

Hi everyone, I have a question which I can't seem to find the answer here or in google... I have been using this addon since about 2009 and have noticed the size of the discount_coupons_to_customers table is HUGE.

 

Almost 400k rows in this table alone and over 7 mg... Our total DB is just over 40 mg.

 

We have approx. 200 coupon and most of these are "customer specific" - so we use customer exclusions to keep people from handing out their coupons friends and relatives or, for that matter, publishing these coupons on coupon sites.

 

Is there a better way to handle this maybe? What are others doing? I guess I could use SPPC...

 

Or are we doing something wrong with the exclusion... It looks to enter each customers who is excluded (we have over 10,000 customers) in 1 row per coupon...

 

Maybe I missing something in the logic, but I would have presumed ALL are excluded and add only those who are NOT?

 

Link to comment
Share on other sites

Hi

 

I'm not fully sure this is the correct fix for my setup, but I was having a rounding issue when using Paypal Standard. Personally I don't mind if the order total is off by 0.01 even if I loose that 1 cent. But I just couldn't be okay with my order totals saying one thing and then once I sent the data over to Paypal, the total price would be different.

 

Turned out the problem for my setup (Display subtotal with applied discount and Display discount with discounted tax applied) was that the shown subtotal on my confirmation page was where things were off. The calculated subtotal (and discount, taxt, total etc) were fine. It was just the rounded amount shown to the customer for the subtotal was off by one cent.

 

The fix for me was to perform the rounding as the subtotal is being aggregated in $order->cart() in the $products loop.

 

I noticed that the default OSC code was performing the roundon each product's total in that loop, so why not the discount code?

 

Hope this helps somebody.

 

in includes/classes/order.php

in the kgt - discount coupons edit in cart() (app. line 320)

 

change:

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

 

to:

$this->info['subtotal'] += round($shown_price['shown_price'], 2);

 

 

so that the kgt - discount coupon edit now looks like this:

 //kgt - discount coupons
 if( is_object( $this->coupon ) ) {
	 $applied_discount = 0;
	 $discount = $this->coupon->calculate_discount( $this->products[$index], $valid_products_count );
	 if( $discount['applied_discount'] > 0 ) $valid_products_count++;
	 $shown_price = $this->coupon->calculate_shown_price( $discount, $this->products[$index] );
	 $this->info['subtotal'] += round($shown_price['shown_price'], 2);
	 $shown_price = $shown_price['actual_shown_price'];
 } else {
	 $shown_price = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty']);
	 $this->info['subtotal'] += $shown_price;
 }
 //end kgt - discount coupons

Link to comment
Share on other sites

Hi everyone, I have a question which I can't seem to find the answer here or in google... I have been using this addon since about 2009 and have noticed the size of the discount_coupons_to_customers table is HUGE.

 

Almost 400k rows in this table alone and over 7 mg... Our total DB is just over 40 mg.

 

We have approx. 200 coupon and most of these are "customer specific" - so we use customer exclusions to keep people from handing out their coupons friends and relatives or, for that matter, publishing these coupons on coupon sites.

 

Is there a better way to handle this maybe? What are others doing? I guess I could use SPPC...

 

Or are we doing something wrong with the exclusion... It looks to enter each customers who is excluded (we have over 10,000 customers) in 1 row per coupon...

 

Maybe I missing something in the logic, but I would have presumed ALL are excluded and add only those who are NOT?

 

Hi greasemonkey,

 

Not sure if this would help or not, but I have a similar situation (where I am giving a discount to certain customers only). My thinking is when I create a new discount, it generates a unique discount code. I set the normal discount parameters, but then give the generated discount code to one customer only. For my purposes, I also set the Max Use to 1 and Available to 1. This way only that one customer can use the coupon one time only. The could give away their unique coupon code, but they could never use more than one time.

 

For multiple customers (like your 200), I'm planning on creating a script to automatically generate multiple coupons with unique coupon codes. Then I can simply hand out a seperate coupon code to each customer.

 

Hope this helps :)

-Art

Link to comment
Share on other sites

  • 2 weeks later...

Just added coupon discount 334 to an almost clean OScommerce 2.3.3 (ideal , SHP and SEO ultimate)

 

The strange thing is, when a client puts a discount code in the field at checkout_payment.php (valid or non valid code) it just goes to checkout_confirmation.php without the discount calculated.

 

If however the customer enters something in the comments about the order (entry above discount) and then puts a code in the discount field, the discount will be taken to the checkout_confirmation.php.

(And when filling in a non valid discount coupon, on top of the page there will be an error notification that the code is not valid.)

So only if a comment is filled in it will accept the discount? Looks like the function the check coupon does not work here.

 

(i removed everything and installed it twice to be sure, but no difference)

 

Anyone else had this problem? and has a solution for this?

Link to comment
Share on other sites

@@boltje It sounds as though you've put the discount code within the comment if block at the top of checkout_confirmation.php.

 

Like this:

 


if (!tep_session_is_registered('comments')) tep_session_register('comments');
if (tep_not_null($HTTP_POST_VARS['comments'])) {

$comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);

//kgt - discount coupons
if (!tep_session_is_registered('coupon')) tep_session_register('coupon');
//this needs to be set before the order object is created, but we must process it after
$coupon = tep_db_prepare_input($HTTP_POST_VARS['coupon']);
//end kgt - discount coupons


}

 

Make sure that the discount coupon code is below the ending bracket of the comment block.

Edited by christoph2k
Link to comment
Share on other sites

There is a bug with the code in the catalog/includes/classes/discount_coupon.php file.

 

Lines 56/57 should be:

AND ( coupons_date_start <= CURDATE() OR coupons_date_start = '0000-00-00 00:00:00' )
AND ( coupons_date_end >= CURDATE() OR coupons_date_end = '0000-00-00 00:00:00' )" );

 

As opposed to:

AND ( coupons_date_start <= CURDATE() OR coupons_date_start IS NULL )
AND ( coupons_date_end >= CURDATE() OR coupons_date_end IS NULL )" );

Link to comment
Share on other sites

@@boltje It sounds as though you've put the discount code within the comment if block at the top of checkout_confirmation.php.

 

Like this:

 


if (!tep_session_is_registered('comments')) tep_session_register('comments');
if (tep_not_null($HTTP_POST_VARS['comments'])) {

$comments = tep_db_prepare_input($HTTP_POST_VARS['comments']);

//kgt - discount coupons
if (!tep_session_is_registered('coupon')) tep_session_register('coupon');
//this needs to be set before the order object is created, but we must process it after
$coupon = tep_db_prepare_input($HTTP_POST_VARS['coupon']);
//end kgt - discount coupons


}

 

Make sure that the discount coupon code is below the ending bracket of the comment block.

 

Thnx Chris,

 

but it seems there is a little problem with the latest Ideal 1.5A Module (dutch payment)

 

In checkout_process.php a part of the IDEAL module (just before the discount coupon should be added) I found a problem.

One of the If statements was not closed well.

A few code was not executed because of this, part of it was the kgt discount module.

Link to comment
Share on other sites

  • 1 month later...

Hello!

 

Having a very serious issue with this module and Internet Explorer... everything runs great overall. The discount is applied, Paypal shows the correct discount... even the order history shows the correct amount. That's all perfect. What the problem is with the order email. The email comes in showing no discount applied... which I'm sure will be a shell shock for those who put a code in saving a lot of money and see they seemed to have paid the full amount.

 

Here's some screenshots:

 

FROM INTERNET EXPLORER:

BOX 1) checkout_confirmation.php showing correct discount.

BOX 2) Paypal's site showing correct discount.

BOX 3) The Order email (my redone version) with no discount showing up.

BOX 4) Just to make sure, I overwrote paypal_standard.php so it was default with the discount coupon code applied, and here's what the plain default email showed up as also not showing the discount.

 

http://www.momentscapture.com/ImageTemp/OSC-DC-IE.jpg

 

 

FROM CHROME:

BOX 1) This is the same modified email as above, but with the whole process done in Chrome. Note that now the discount shows up.

 

http://www.momentscapture.com/ImageTemp/OSC-DC-Chrome.jpg

 

 

I figure this has something to do with paypal_standard.php and some session variable, but for the life of me I cannot figure it out. HELP PLEASE! I've searched high and low trying to figure this out...

 

Britt

Edited by p51
Link to comment
Share on other sites

Wanted to also add that I've only tested Internet Explorer and Chrome so far. Again, the email shows the CORRECT discount when I do the whole process with CHROME. The email DOESN'T show the discount at all in the email when I used INTERNET EXPLORER for the whole process. I've tried to manually add the discount code with no luck and have tried to fidget with the paypal_standard.php code to get this to work... but thus far I just can't seem to get anything to register from Internet Explorer. Just another reason I can't stand IE anymore...

Link to comment
Share on other sites

Hi, I've added this module to my website, and I cant get it to recognise voucher codes that I've entrered with the admin module.

 

Any ideas? Is this a common problem?

 

What have I missed :)

 

Thanks

Mike

www.bestexhaust.com.au

Link to comment
Share on other sites

Hi, I've added this module to my website, and I cant get it to recognise voucher codes that I've entrered with the admin module.

 

Any ideas? Is this a common problem?

 

What have I missed :)

 

Thanks

Mike

www.bestexhaust.com.au

 

Hi Mike

 

Unfortunately, the Discount Coupon Codes contribution page has a whole lot of extras added and bugfixes so many of the downloads at the top are not "full" packages.

The last "full packages" on that page are:

Discount Coupon Codes 3.34 FR by delete13 (dated 26 Jul 2010) and SambaMambo (dated 19 Feb 2010)

Discount Coupon Codes 3.34 (Español) by escri2 (dated 17 Nov 2009)

 

Everything above these posts are extra features and bugfixes pertaining to specific payment gateways (ie Paypal Standard etc).

 

The one I installed was the (Español) by escri2 and then the "PayPal Website Payments Standard Discount + show the orders details" by sunrise9 (dated 30 Apr 2013) since I use PayPal Website Payments Standard for my site. If you use the same, make sure to download my addition "PayPal Website Payments Standard Discount + show the orders details - Fixed" (amseek - dated 21 May 2013) which is a bugfix for the one submitted by sunrise9.

 

I have everything working great with these installed.

 

As an added note, the two "V3.34 - Admin login page error" posts by dontlike2pay do not apply to the (Español) version I downloaded. The "MeFindCoupon" thing is completely not applicable either (it's a Windows shortcut link to the guy's home setup). Not sure why it was posted, but hey, it's a contribution nonetheless. It's the thought that counts :)

 

Okay, I hope this maybe clears things up a bit and helps you out :thumbsup:

 

-Art

Link to comment
Share on other sites

  • 2 weeks later...

One quick question: How can I echo the total discount amount on e.g. the checkout_confirmation.php page (besides the output in order_total)?

Found out by myself now!!! Very easy if you understand how coupons work! Here's the code for calling the coupon amount:

array_sum($order->coupon->applied_discount)

Edited by mightyx
Link to comment
Share on other sites

  • 2 weeks later...

Found out by myself now!!! Very easy if you understand how coupons work! Here's the code for calling the coupon amount:

array_sum($order->coupon->applied_discount)

 

:P Nice one... -see, this is why I should always read subsequent posts before going off and tinkering away to find the answer. You are 100% correct on that.

array_sum($order->coupon->applied_discount)

is the right answer

 

That was a piece I needed to fix for the paypal_standard module. The original addon had hard-coded (includes/modules/payment/paypal_standard.php - app. line 313)

$parameters['discount_amount_1'] =number_format($order->coupon->applied_discount['Unknown tax rate'],2);

instead which would only ever apply a discount if your tax rate was set to 'Unknown tax rate'.

 

Glad you found it. Those payment and shipping mods being included into the master module classes are pretty hard to find your way through. :D

 

-Art

Link to comment
Share on other sites

  • 1 month later...

Hi there,

 

I think I'm missing something with this mod.

 

I've tripled checked my installation and everything seems to be fine. I can add the module, add a discount code, it knows when I've entered a wrong code, but when it gets to checkout_confirmation.php it doesn't show at all. I echoed array_sum($order->coupon->applied_discount) and its 0.

 

I've been going through all the forums I can find to see if anyone else has had this problem.

 

The only thing that I can find is that in include/calsses/order.php I found this code

 

$shown_price = $currencies->calculate_price($this->products[$index]['final_price'], $this->products[$index]['tax'], $this->products[$index]['qty']);
$this->info['subtotal'] += $shown_price;

 

Instead of this code in the instructions

 

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

 

I also didn't run any SQL because it said

The installation should now be complete. The module will automatically create the database tables needed, there is no SQL script you need to run, unless the script encountered an error creating the tables (this can happen if the user osCommerce connects with does not have CREATE TABLE permissions). See the common problems section if you need to manually run the create table statements.

And since I can go into the admin and see my coupon code I assume everything is working well.

 

Please help, I'm really lost with this.

Link to comment
Share on other sites

Hey,

 

I've successfully installed the module under osCommerce 2.2 MS-2, everything works great including admin functionality. But there is a problem with displaying & processing the coupon on the checkout_confirmation.php page and the DEBUG comments don't show even though I marked it true in the module config.

 

I used the "Discount Coupon Codes v3.34 FR" by delete13

 

I think it's not passing this check:

if( tep_not_null( $coupon ) && is_object( $order->coupon ) )

 

I also tested echo'ing the following line inside the checkout_confirmation.php, which also returns 0

<?php
/* kgt - discount coupons */
if( MODULE_ORDER_TOTAL_DISCOUNT_COUPON_STATUS == 'true' ) {
?>
<!-- <?php print_r( array_sum($order->coupon->applied_discount) ); ?> -->
<?php
}
?>

 

I made sure it's not stuck inside some other if statement or something, and I double checked the installation files.

 

Any help or thoughts would be much appreciated, I've been digging on this for almost a week now!

 

Thanks,

Draco

Link to comment
Share on other sites

Ok, so I tracked the problem with the help of @@imop =)

 

And I concluded that the problem lies within the ot_discount_coupon.php file

Exactly in this block:

function process() {
 global $order, $currencies;
 if( is_object( $order->coupon ) ) {
   // the rest of the processing here...
 } else $this->enabled = false;
}

 

So I believe the discount details are not displayed on the checkout_confirmation.php page because the module's enabled is false.

 

So how can I debug $order->coupon inside ot_discount_coupon.php

 

Looking forward to receiving answers or thoughts =)

Thanks,

Draco

Edited by draco003
Link to comment
Share on other sites

Ok, so I tracked the problem with the help of @@imop =)

 

And I concluded that the problem lies within the ot_discount_coupon.php file

Exactly in this block:

function process() {
global $order, $currencies;
if( is_object( $order->coupon ) ) {
// the rest of the processing here...
} else $this->enabled = false;
}

 

So I believe the discount details are not displayed on the checkout_confirmation.php page because the module's enabled is false.

 

So how can I debug $order->coupon inside ot_discount_coupon.php

 

Looking forward to receiving answers or thoughts =)

Thanks,

Draco

 

New findings:

The above assumptions were wrong!

 

I found out that the customers table contained a field called: order_total_allowed which doesn't have the ot_discount_coupon.php in it!

 

That's why it was never processed by order_total module.

 

I'll proceed with the database and keep you posted.

 

Thanks,

Draco

Link to comment
Share on other sites

New findings:

The above assumptions were wrong!

 

I found out that the customers table contained a field called: order_total_allowed which doesn't have the ot_discount_coupon.php in it!

 

That's why it was never processed by order_total module.

 

I'll proceed with the database and keep you posted.

 

Thanks,

Draco

 

Solution:

 

I went to Customers Groups section under Admin, http://www.shop.com/catalog/admin/customers_groups.php

 

Clicked on the required customer group, then under the Order Total Modules I ticked the "Discount Coupon"

 

Now it shows up, and everything works great!

 

Thanks every one especially the original contributor @@kgt and thanks to @@imop for giving me a push ;)

 

In case any one is wondering this installation is osCommerce v2.2 MS-2

 

Peace,

Draco

Link to comment
Share on other sites

  • 2 weeks later...

I've downloaded from http://addons.oscommerce.com/info/7644 the 2.3.3 version. I'm going to hack together the updates since the last full version for myself, so I figure I will upload my full package for anyone else who needs it. Are there any known issues with this version I should know about before I undertake this? Looking at the 2.2 version (where it looks like most of the dev is happening) there might be a PayPal issue?

 

Cheers

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