#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    4
    Rep Power
    0

    Question Session Variables -> Shopping cart


    Hi everrybody, i'm new here

    So, for one of my course, I must do a website, a shopping website.
    For that, I can only used session variables with urltoken and etc... but no cookies. (it's what the prof said)

    I've already make the indentification of user, it's done and it works perfectly. But I've a matter with the session variables for the shopping cart. I've read that article http://builder.com.com/5100-6387-105...tml?tag=search

    My matter is:
    In application.cfm

    <CFAPPLICATION clientmanagement="Yes" sessionmanagement="Yes" SETCLIENTCOOKIES="NO" SessionTimeout="30">



    <cfparam name="session.IsLoggedIn" DEFAULT="No">

    <cfparam name="session.login" DEFAULT="non connecté">
    <cfparam name="session.panierTab" type="data_type" DEFAULT=arrayNew(1)>


    <cfparam name="session.cpt" type="numeric" DEFAULT="0">

    </CFAPPLICATION>

    In mycart.cfm

    <cfset session.cpt=#session.cpt#+1>
    <cfset session.panierTab[#session.cpt#]=#url.pro#>
    <cfset panierTabTaille=ArrayLen(#session.panierTab#)>


    I'm just trying to increment a session variable, session.tmp, but that make error

    Element CPT is undefined in SESSION.


    The error occurred in E:\WWW\HTTP\cfm\panier.cfm: line 54

    52 :
    53 :
    54 : <cfset session.cpt=#session.cpt#+1>
    55 : <cfset session.panierTab[#session.cpt#]=#url.pro#>
    56 : <cfset panierTabTaille=ArrayLen(#session.panierTab#)>


    I really don't know why... cpt is already defined in session, no?

    Thanks for your help

    ps: Sorry for my english, i'm belgian
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,270
    Rep Power
    968
    First of all, you don't need all those pound signs. You only need pound signs when you are outputting a variable for display, or evaluating a dynamic expression. This would work and is cleaner:

    <cfset session.cpt = session.cpt + 1 />

    You probably want to lock this using <cflock> as this is succeptable to a race condition, but that's another issue.

    As to why the variable is not defined, it may be because your code is using the <cfapplication> tag incorrectly. You don't open and close this tag, you should use it without a closing tag.

    That should fix the problem of the session variable not being defined. But also know that you will need to pass the session.urlToken in all of your links and form fields if you have cookies disabled (as you do).
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    4
    Rep Power
    0
    Originally Posted by kiteless
    First of all, you don't need all those pound signs. You only need pound signs when you are outputting a variable for display, or evaluating a dynamic expression. This would work and is cleaner:

    <cfset session.cpt = session.cpt + 1 />

    You probably want to lock this using <cflock> as this is succeptable to a race condition, but that's another issue.

    As to why the variable is not defined, it may be because your code is using the <cfapplication> tag incorrectly. You don't open and close this tag, you should use it without a closing tag.

    That should fix the problem of the session variable not being defined. But also know that you will need to pass the session.urlToken in all of your links and form fields if you have cookies disabled (as you do).
    Hi thanks, that solve my matter Great

    I've other question

    I just want to add the product id to my cart, i'm doing that:

    <cfset session.cpt=session.cpt+1 />
    <cfset session.panierTab[session.cpt]=url.pro/>
    <cfset panierTabTaille=ArrayLen(session.panierTab)/>


    <cfloop index="i" from="1" to=#panierTabTaille#>
    <cfoutput>Affichage ligne[#i#] du panierTab : #ArrayToList(session.panierTab,",")#<br></cfoutput>
    </cfloop>

    But, I've received the following error

    You have attempted to dereference a scalar variable of type class java.lang.String as a structure with members.


    The error occurred in E:\WWW\HTTP\cfm\panier.cfm: line 55

    53 :
    54 : <cfset session.cpt=session.cpt+1 />
    55 : <cfset session.panierTab[session.cpt]=url.pro />
    56 : <cfset panierTabTaille=ArrayLen(session.panierTab) />
    57 :

    The variable url.pro is the id of my product, which is passing by url parameter.

    Thanks for you help
    Last edited by Le Veilleur; February 17th, 2004 at 02:47 PM.
  6. #4
  7. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,270
    Rep Power
    968
    If you want to insert and retrieve something based on a "key" such as a product ID, you would need to use a structure instead of an array. Arrays are indexed by number (ie 1, 2, 3, etc.). Structures are referenced by key, which can be a number, a string, etc.

    If you want to stick with using an array, you'd simply append the value to the array instead of trying to put it in by the item's ID, like this:

    <cfset arrayAppend( session.cpt, url.pro ) />
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    4
    Rep Power
    0
    Originally Posted by kiteless
    If you want to insert and retrieve something based on a "key" such as a product ID, you would need to use a structure instead of an array. Arrays are indexed by number (ie 1, 2, 3, etc.). Structures are referenced by key, which can be a number, a string, etc.

    If you want to stick with using an array, you'd simply append the value to the array instead of trying to put it in by the item's ID, like this:

    <cfset arrayAppend( session.cpt, url.pro ) />
    My probleme persits

    In application.cfm
    <cfparam name="session.panierTab" DEFAULT="arrayNew()">

    And my cart.cfm


    <cflock timeout="30" scope="session">


    <cfset session.panierTab = arrayAppend( session.panierTab, structNew() )>
    <cfset panierTabTaille=ArrayLen(session.panierTab) />

    <cfset session.panierTab[panierTabTaille].pro_id = pro_id>
    <cfset session.panierTab[panierTabTaille].pro_marque = pro_marque>
    <cfset session.panierTab[panierTabTaille].pro_modele = pro_modele>
    <cfset session.panierTab[panierTabTaille].pro_quanti = 1>

    <!-- Affichage du panier -->
    <cfloop index="i" from="1" to="#arrayLen( session.panierTab )#">
    <cfoutput>Affichage ligne[#i#] du panierTab : #ArrayToList(session.panierTab,",")#<br></cfoutput>
    </cfloop>
    </cflock>


    The error

    Object of type class java.lang.String cannot be used as an array


    The error occurred in E:\WWW\HTTP\cfm\panier.cfm: line 60

    58 :
    59 :
    60 : <cfset session.panierTab = arrayAppend( session.panierTab, structNew() )>
    61 : <cfset panierTabTaille=ArrayLen(session.panierTab) />
    62 :

    I juste make what is write in this article
    http://builder.com.com/5100-6387-105...tml?tag=search

    Thank for helpling me
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    4
    Rep Power
    0
    I fixed my matter

    thanks

IMN logo majestic logo threadwatch logo seochat tools logo