close ad
WARNING PC USERS: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Discount Codes

Thread began 10/14/2009 9:06 am by Alf | Last modified 11/24/2014 12:42 pm by Jason Byrnes | 4341 views | 17 replies |

Alf

Discount Codes

Hi

First Question
can you get get discount codes from a database? I wanted to extend my CMS for the client allowing them to create discount codes with different discounts (i.e discount code 'Forces' gives 10% off sub-total - discount code 'Wholesale' gives 10% off sub-total)

Secondly Question ...more important....
Can some one tell me how to add a text field for customers to add a discount code and how this can be activated when they click 'update cart'?

Thanks as ever

Alf

Sign in to reply to this post

Jason ByrnesWebAssist

First off, you should follow the solution recipe for static coupon codes to get coupon codes working. That tutorial can be found In the Solution Recipes section of the eCart Support Page titled "Creating a Coupon system for your eCart store":
ecart/


To convert that to be database driven:

1) Create a table in your database to hold the coupon codes. it should have a structure similar to:
couuponID - Auto Number, Primary key Column.
couponCode - varchar
couponAmount - double


To add a coupon code of "test" that will give a 10% discount, you would create the follwoing record:
couponID | couponCode | couponAmount
1 | test | 0.10

2) Next is to add a recordset to the page to lookup the coupon amount based on the code the user enters.

On the server behaviors panel, click the plus button and select Recordset. In Simple view, set the record set to use the coupon table we created. Set the name of the recordset to "rsCoupon" In the Filtering Section, set it to filter the couponCode column Equal to the Form Variable txtPromoCode, this is name of the text box created in the coupon code system tutorial.

3) Now we need to create another session variable to hold the discount amount. On the server behaviors panel, click the plus button and select eCart -> General -> Set Session Value. Set the trigger to "recordset rsCoupon Not Empty". Set the name of the session variable to "PromoAmount". Click the lightning bolt next to value, expand the rsCoupon recordset and select the couponAmount column.

4) The PromoCode session variable needs to be modified as well. Set the trigger to "recordset rsCoupon Not Empty" so it will only get set if the promcode sexists in the database.

5) The last step is to modify the Promotional Discount rule in eCart. Remove the "If Session variable == WebAssist" triger.

Add a new trigger "Session variable exists "PromoCode""

Add another trigger "Session variable exists "PromoAmount""

Then Modify the charge rule "Bases on Cart SubTotal "Times" "$_SESSION['PromoAmount']"

so that the discount will use the value stored in the session variable from the database.

Sign in to reply to this post

Alf

Discount Codes

Hi Jason

Thanks for the feedback, I have the code working manually, still got to tie it in with the database.

I have a different Discount Question.
I have a client side cart where they take phone orders
They want a free text box where they can input discounts (numerically) for friends an family

I've set this up adding a session 'FriendsDiscount' on the cart page

if (!session_id()) session_start();
if((((isset($_POST["FriendsDiscount"]))?$_POST["FriendsDiscount"]:"") != "")) {
$_SESSION["FriendsDiscount"] = "".$_SESSION['FriendsDiscount'] ."";
}

however I'm having problems with the discount code.
I have the following:
Condition: Total number of items > 0
Calculation: Based on the cart subtotal -minus- $_SESSION['FriendsDiscount']

If I type a discount of 10.00 into my FriendsDiscount text field for a product costing £50.00 I get a total (after discount) of £10.00

Any suggestions

thanks

Alf

Sign in to reply to this post

Jason ByrnesWebAssist

Your setting the value of the Friends Discount Session to be equal to the value of the ffreind Discount Session:

$_SESSION["FriendsDiscount"] = "".$_SESSION['FriendsDiscount'] ."";



should'nt it be equal to the value of the friends Discount form element?:
$_SESSION["FriendsDiscount"] = "".$_POST["FriendsDiscount"] ."";




if (!session_id()) session_start();
if((((isset($_POST["FriendsDiscount"]))?$_POST["FriendsDiscount"]:"") != "")) {
$_SESSION["FriendsDiscount"] = "".$_POST["FriendsDiscount"] ."";
}


sounds to me like somewhere along the way, the friends discount session variable got set to 40.

In future for trouble shooting, I find it helps to echo values to the page so you know what is being used behind the scenes:
<?php echo("The Session FriendsDiscount is equal to: ".isset($_SESSION["FriendsDiscount"])?$_SESSION["FriendsDiscount"]:"Nothing"); ?>
<?php echo("The Post FriendsDiscount is equal to: ".isset($_POST["FriendsDiscount"])?$_POST["FriendsDiscount"]:"Nothing"); ?>

Sign in to reply to this post

Alf

Screen Grab

Hi Jason

thanks for the speedy response

I've taken you advice and echoed the session (please see image attached) but still get a strange figure from the discount rule

As you will see:
the subtotal is 79.00
the discount amount entered is 20
the discount result returns -59.00
the delivery charge is a flat rate of £7.99
giving a total of £27.99


I wanted a total of 86.99

thanks

Alf

Sign in to reply to this post

Ray BorduinWebAssist

It looks like you set up your discount as:

Subtotal minus 20

when really you should just use:

Flat Rate: 20

Sign in to reply to this post

Alf

discounts

Hi Ray

Its not a flat charge

Its manually added at the discretion of the client

What I've noticed is if I enter the discounted price that I want the user to pay in the FriendsDiscount field I get the the right info. in the rest of the cart - see diagram

In the FriendsDiscount I typed in the discounted price I wanted them to pay in this case 69.00

What I'd like is for this to work in reverse so I can type in the amount of discount I want to give them

thanks

Alf

Sign in to reply to this post

Alf

solved

Hi Ray

I should have listen more carefully

Flat rate is the solution

thanks again

Alf

Sign in to reply to this post

Jamie

This post has been deleted.

Alf

Discounts from database

Hi Jason

I've followed the instructions as best as possible but get the following code when setting the CouponAmount session and the rs being not empty


PHP Notice: Undefined variable: totalRows_rsCoupons in C:\inetpub\wwwroot\littleme\phone\cart.php on line 29


Any suggestions?

Originally Said By: Jason Byrnes
  First off, you should follow the solution recipe for static coupon codes to get coupon codes working. That tutorial can be found In the Solution Recipes section of the eCart Support Page titled "Creating a Coupon system for your eCart store":
ecart/


To convert that to be database driven:

1) Create a table in your database to hold the coupon codes. it should have a structure similar to:
couuponID - Auto Number, Primary key Column.
couponCode - varchar
couponAmount - double


To add a coupon code of "test" that will give a 10% discount, you would create the follwoing record:
couponID | couponCode | couponAmount
1 | test | 0.10

2) Next is to add a recordset to the page to lookup the coupon amount based on the code the user enters.

On the server behaviors panel, click the plus button and select Recordset. In Simple view, set the record set to use the coupon table we created. Set the name of the recordset to "rsCoupon" In the Filtering Section, set it to filter the couponCode column Equal to the Form Variable txtPromoCode, this is name of the text box created in the coupon code system tutorial.

3) Now we need to create another session variable to hold the discount amount. On the server behaviors panel, click the plus button and select eCart -> General -> Set Session Value. Set the trigger to "recordset rsCoupon Not Empty". Set the name of the session variable to "PromoAmount". Click the lightning bolt next to value, expand the rsCoupon recordset and select the couponAmount column.

4) The PromoCode session variable needs to be modified as well. Set the trigger to "recordset rsCoupon Not Empty" so it will only get set if the promcode sexists in the database.

5) The last step is to modify the Promotional Discount rule in eCart. Remove the "If Session variable == WebAssist" triger.

Add a new trigger "Session variable exists "PromoCode""

Add another trigger "Session variable exists "PromoAmount""

Then Modify the charge rule "Bases on Cart SubTotal "Times" "$_SESSION['PromoAmount']"

so that the discount will use the value stored in the session variable from the database.  
Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...