Thread: Promo Code

    #1
  1. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    16
    Rep Power
    0

    Promo Code


    I am trying to add a promo code to our website. What it is supposed to do is during checkout when a client enters the promo code it will reduce the cost of their order by 5%. Can anyone help me. Everything I have tried so far has failed.

    Thank you,


    Dave
  2. #2
  3. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    <%

    ' all checkout code and such would be here
    ' assume final cost is in a variable named "total"

    ' for testing purposes the line below will be 45 dollars
    total = 45

    ' retrieve form value if discount code submitted
    code = "bacon"
    formval = request.form("discount")

    ' is the discount code equal to code (bacon) then apply discount
    if (formval = code) and (session("discount") = "") then
    total = total - (total *.05)
    session("discount") = total
    end if

    ' is discount already applied then adjust total
    if session("discount") <> "" then total = session("discount")
    %>

    Your order is ready for checkout. The total is $<%=total%>.

    If you have a discount code, please enter it below.
    <form action="try.asp" method="post">
    Code: <input name="discount">
    <input type="submit" value="Apply">
    </form>


    A session is used because if the person were to reenter the promo code the price would go down 5% every attempt. If the session holds a value, that value is the price already reduced by 5%.
  4. #3
  5. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    change "try.asp" to whatever filename you're using....
  6. #4
  7. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    16
    Rep Power
    0
    Okay sqlconfused;

    I put in the information you gave me and my program now looks like this:

    Dim Promo as String
    Promo = "BNOV21"
    formval = request.form("discount")

    lblTotal.Text = GetItemTotal()
    If (formval = Promo) and (session("discount") = "" Then
    GetItemTotal() = GetItemTotal() - (GetItemTotal() * .05)
    session("discount") = GetItemTotal()
    end if
    lblTotal0.Text = RetailShip
    lblTotal1.Text = RetailShip + GetItemTotal()
    Itemlbl.Text = RetailShip


    If session("discount") <> then GetItemTotal() = session("discount")

    If objDT.Rows.Count = 0 Then

    lblTotal0.Text = "0.00"
    lblTotal1.Text = "0.00"

    End If

    <form action="try.asp" method="post"></form>
    Save an Additional 5% with A
    Promo Code:</td>
    <td style="height: 49px;">
    <input type="submit" value="Apply"></form></td>

    Now my error code is the following:

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30451: Name 'formval' is not declared.

    Source Error:



    Line 408im Promo as String
    Line 409:Promo = "BNOV21"
    Line 410:formval = request.form("discount")
    Line 411:
    Line 412: lblTotal.Text = GetItemTotal()


    Source File: E:\Queen Bee\Store\ShoppingCart.aspx Line: 410

    What did I do wrong?

    Thanks,


    Dave
  8. #5
  9. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    You are programming in asp.net and posting for help in the ASP forum not the ASP.Net forum.

    I don't program in asp.net but I'm going to suggest declaring the variable in the dim statement

    Dim Promo as String, formval
  10. #6
  11. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    Also change it around so that the discounted price is added to shipping, not the full price.

    Code:
    If session("discount") <> then GetItemTotal() = session("discount")
    
    lblTotal0.Text = RetailShip
    lblTotal1.Text = RetailShip + GetItemTotal()
    Itemlbl.Text = RetailShip
  12. #7
  13. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    16
    Rep Power
    0
    Thanks, I will move this to the asp.net forum.
  14. #8
  15. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    Let me know if the code works, I think it should.
  16. #9
  17. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    16
    Rep Power
    0
    Unfortunately I still get an error:

    This is the error I get:

    Server Error in '/' Application.
    --------------------------------------------------------------------------------

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: BC30068: Expression is a value and therefore cannot be the target of an assignment.

    Source Error:



    Line 412: lblTotal.Text = GetItemTotal()
    Line 413: If (formval = Promo) and (session("discount") = "") Then
    Line 414: GetItemTotal() = GetItemTotal() - (GetItemTotal() * .05)
    Line 415: session("discount") = GetItemTotal()
    Line 416: end if

    But at least it has changed the problem a little. Here is what my program looks like now when I get the error:

    Dim Promo as String, formval
    Promo = "BNOV21"
    formval = request.form("discount")

    lblTotal.Text = GetItemTotal()
    If (formval = Promo) and (session("discount") = "") Then
    GetItemTotal() = GetItemTotal() - (GetItemTotal() * .05)
    session("discount") = GetItemTotal()
    end if
    lblTotal0.Text = RetailShip
    lblTotal1.Text = RetailShip + GetItemTotal()
    Itemlbl.Text = RetailShip


    If session("discount") <> then GetItemTotal() = session("discount")

    If objDT.Rows.Count = 0 Then

    lblTotal0.Text = "0.00"
    lblTotal1.Text = "0.00"

    Thanks,


    Dave
  18. #10
  19. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    This has me stumped, I'm not an ASP.Net programmer.

    One obvious bug:

    If session("discount") <> "" then GetItemTotal() = session("discount")
  20. #11
  21. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    16
    Rep Power
    0
    I see it but what should that value be?
  22. #12
  23. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Oct 2012
    Posts
    49
    Rep Power
    2
    If session("discount") <> "" then GetItemTotal() = session("discount")

    The value is blank, if the session for the discount contains a value other than blank then that discount is applied to the GetItemTotal. So if they've entered a discount code, the session contains the 5% reduced price.

    In hindsight, it appears that your GetItemTotal may be an actual function rather than a variable (hence the brackets). This maybe the cause of your error. In any event you should put the session code in the routine that calculates the price.
  24. #13
  25. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jul 2012
    Posts
    16
    Rep Power
    0
    sqlconfused;

    I am hoping you can help me out a little more. I know you do not program .Net but no one on the .Net side is helping, they have not responded to my post at all, and you have. Here is my code:

    Dim Promo as String, formval
    Promo = "BNOV21"
    formval = request.form("discount")

    lblTotal.Text = GetItemTotal()
    If (formval = Promo) and (session("discount") = "") Then
    lblTotal.Text = GetItemTotal() - (GetItemTotal() * .05)
    session("discount") = GetItemTotal()
    end if
    lblTotal0.Text = RetailShip
    lblTotal1.Text = RetailShip + GetItemTotal()
    Itemlbl.Text = RetailShip


    If session("discount") <> "" then
    lblTotal.Text = session("discount")
    End If

    If objDT.Rows.Count = 0 Then

    lblTotal0.Text = "0.00"
    lblTotal1.Text = "0.00"
    End If

    It seems to pass compilation. But my input is still not working right. Here is what I have:

    Enter Promo Code for an additional 5% off</td>
    <td>
    <input name="Promo" type="text" /></td>
    <td class="auto-style1">
    <input name="Promo" type="submit" value="submit" /></td>

    When I click submit nothing is being submitted. What can I do?

    Thanks,


    Dave

Similar Threads

  1. IxWebHosting Promo Code For 25% Off Active For 2012
    By chanelc707 in forum Windows Web Hosting
    Replies: 0
    Last Post: September 4th, 2012, 06:37 PM
  2. Replies: 0
    Last Post: April 25th, 2011, 08:00 AM
  3. Promo Dates and Other - If Statements
    By badmp3 in forum ASP Development
    Replies: 1
    Last Post: December 20th, 2009, 06:04 AM
  4. Automated query for multiple promo codes
    By kabucek in forum Microsoft SQL Server
    Replies: 1
    Last Post: May 9th, 2009, 08:52 PM
  5. Macy's plans its biggest promo (USATODAY.com)
    By RSS_News_User in forum Business News
    Replies: 0
    Last Post: November 23rd, 2005, 06:05 AM

IMN logo majestic logo threadwatch logo seochat tools logo