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

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

How do I get coupon code in db?

Thread began 7/21/2009 5:22 pm by dan361579 | Last modified 3/18/2010 1:16 pm by Eric Mittman | 1723 views | 11 replies |

dan361579

How do I get coupon code in db?

I've got a session variable named "PromoCode" that is an input form on the shopping cart page. Works fine for entering a manual discount code and getting that discount rule plugged into the cart math.

I have a database field named "CouponCode" in the MySQLdb Orders table. VarChar(20).

All works fine until I attempt to plug the coupon code text into the db. I'm not able to find where in eCart to bind the text box (or the _$Session[PromoCode] variable) with the Coupon Code into it to a field that will be inserted into that record of the orders table after the order is submitted to the Gateway.

I'm not exactly sure when the order enters the mySQLdb either, but I imagine its after the ping back from the Gateway saying all is fine with the cc.

I'm okay if I have to manually add code, but I'm not sure where to do that either.

All help appreciated.
Thank you!

PS: What I'm truly trying to accomplish is to id a buyer with the coupon code so that I can redirect some of the purchase price to a charity. This is a fund raiser for the charity. I've entered a discount of 1 cent to use the above method only as a means of trapping a coupon code. If someone has a way of trapping the coupon code without using the eCart discount rules, that's fine too. All I want to do is get what is entered into the text box inserted into the db field of that purchase record (Orders table) so that I can tell which buyers were sent by the charity and forward the money we've agreed upon.

Sign in to reply to this post

Ray BorduinWebAssist

If you already have a session variable called "PromoCode" and you are already inserting your orders summary into a orders table, then all you need to do is:

1) Update your database table and add a column to store the promocode
2) Go to the confirm page and update the "store cart summary in database" server behavior and set the value of the promocode column to come from the promocode session variable.

Sign in to reply to this post

dan361579

Not quiet there yet.

Thanks Ray,

I'm just a bit more ignorant than the reply suggests. lol. Here is a snippet of how I implemented the server action.

In the $WA_fieldNamesStr variable I inserted the column |CouponCode| to the list of db field names.

Then I went to $WA_fieldValuesStr and inserted "PromoCode" into the string of variables as shown below:

$WA_fieldValuesStr = "".session_id() ."" . "|". "".((isset($_SESSION["PromoCode"]))?$_SESSION["PromoCode"]:"") ."" . "|" . "".((isset($_POST["email"]))?$_POST["email"]:"") ."" . "|" ...string goes on....

Then I went to $WA_columnTypesStr below and inserted |',none,' '| to account for the new PromoCode field here too.

I then ran a live transaction. The transaction posts to the db, but the CouponCode field is empty. It used to say NULL, so something is different because now it's just blank. I get no errors, but I'm thinking the syntax of the $WA_fieldValuesStr is wrong where I've inserted the field.

BTW, what's this syntax mean? ((isset(true/false))?superglobal:"")
It looks like an if then where the "?" is "THEN" and the ":" would be an assignment of something if the superglobal wasn't already set, but I'm unsure of the "?" and the ":" usage. I've looked on line and in my PHP manual, but can't find an answer.

Thank you!!

Sign in to reply to this post

Ray BorduinWebAssist

it is a shorthand if statement:

(boolean)?truevalue:falsevalue

it means: if (boolean) then return truevalue else return falsevalue

so ? is then and : is else effectively and the if is implied.

Sign in to reply to this post

dan361579

Did the other statements look right to you?

Thanks Ray,

How about the other actions I took? Did the syntax look fine on the $WA_fieldValuesStr statement in the segment relating to PromoCode variable value for insertion into the db? I'm wondering if I should have used $_Post[PromoCode]since that's all of the other segments of the string use it. I'm unsure if that's my problem. If the syntax is fine, then my issue is elsewhere.

Thank you!!

Sign in to reply to this post

Ray BorduinWebAssist

I would recommend using the server behaviors to be sure the syntax is correct since it can be hard to spot a typo. I don't see an immediate issue.

Sign in to reply to this post

b364131

variable value not inserting into db

I'm having the same type of issue. I've added a company code to the checkout page. The information is inputed and seems to be written to the session variable because I can display it on the confirm page. However, when inserting into the database, the value is always blank.

For testing purposes, I inserted the Last name value into the company field in the "store summary in database" server behavior and the value is inserted into the database so that procedure is working..but I cannot get the company value inserted into the db.

It seems as though the session variable is blank...and even though I can display the value in a field on the confirm page, I can't get the either the session variable or field value on the confirm page to post to the database

Sign in to reply to this post

Eric Mittman

You were able to get the last name inserted into this field in your db so it seems that this should work. How is your last name value set, did you use the posted binding or a session variable? If you have your company value setup like the lastname is then it should get inserted into the db like the last name. Let us know about these details and if you can post back with a copy of the page you are inserting on minus any of the sensitive details like logins, passwords or signatures.

Sign in to reply to this post

b364131

I set it as a session variable...it seems like it is the same as the last name field.
I've attached the checkout and confirm pages.

Thank you for looking at them.

Attached Files
cart.zip
Sign in to reply to this post

Eric Mittman

It looks like you are not setting the company value from your checkout form in a session variable. You will need to add in some code like this into the top of your confirm page:

php:
<?php

if (!session_id()) session_start();
if(
$_SERVER["REQUEST_METHOD"] == "POST")     {
  
$_SESSION["company1"] = "".((isset($_POST["company1"]))?$_POST["company1"]:"")  ."";
}
?>



This will set a session variable named company1 that will hold the value that the user entered on the checkout form.

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