Skip to main content
Inspiring
December 1, 2009
Answered

cfif in an array

  • December 1, 2009
  • 1 reply
  • 1434 views

Could someone help me figure our what I am doing wrong?  I have an array for shopping cart items that if the SKU matches a certain SKU I need to replace that price.  This is what I have tried, but it will not work. Everything is looping correctly and everything else works exept my cfif statements:

<cfif Session.Cart.SKU[ThisItem] EQ "WL6114-1" OR Session.Cart.SKU[ThisItem] EQ "WM6113-1" OR Session.Cart.SKU[ThisItem] EQ "WU6176-1">
   
    <cfif Session.Cart.Descrip[ThisItem] EQ "s"><cfset Retail = 45></cfif>
    <cfif Session.Cart.Descrip[ThisItem] EQ "m"><cfset Retail = 47></cfif>
    <cfif Session.Cart.Descrip[ThisItem] EQ "l"><cfset Retail = 49></cfif>
    <cfif Session.Cart.Descrip[ThisItem] EQ "xl"><cfset Retail = 51></cfif>
    <cfif Session.Cart.Descrip[ThisItem] EQ "xxl"><cfset Retail = 53></cfif>
<cfelse>

<cfset Retail=Session.Cart.UnitPrice[ThisItem]>
   
</cfif>

    This topic has been closed for replies.
    Correct answer Dan_Bracuk

    That is what I can't make any sense out of. Because looking at the results in the shopping cart, Session.Cart.Descrip[ThisItem] is passed

    and is equal to any of the above choices. So the variable retail should be set. I don't know. I thought maybe I was missing something obvious, it should work.


    I troubleshoot if/else problems like this:

    if the variable is the expected value

    output yes

    else

    output the variable and the expected value.

    By the way, check for leading or trailing spaces.  They might be messing you up.

    1 reply

    ilssac
    Inspiring
    December 1, 2009

    Do you really have different arrays for every structure cart key?  It's allowed, it's possible, but I would sure find it confusing.  I'm wondering if you don't have the array node and the structure node acidentily reversed.

    I would have expected to see something more like this...

    Seccion.Cart[ThisItem].SKU

    Session.Cart[ThisItem].Descrip

    Session.Cart[ThisItme].UnitPrice

    But if your code accuratly described your data model, then HOW does it not work?  What ouput do you get?  What output did you expect?

    brianismAuthor
    Inspiring
    December 1, 2009

    Well this is actually coming from an old Cartweaver system.  I was told before not to post chunks of code from a purchased system.

    With this code below and choosing a product with the appropriate SKU to trigger the CFIF I get:

    Variable RETAIL is undefined.

    <cfif Session.Cart.SKU[ThisItem] EQ "WL6114-1" OR Session.Cart.SKU[ThisItem] EQ "WM6113-1" OR Session.Cart.SKU[ThisItem] EQ "WU6176-1">
       
        <cfif Session.Cart.Descrip[ThisItem] EQ "s"><cfset Retail = 45></cfif>
        <cfif Session.Cart.Descrip[ThisItem] EQ "m"><cfset Retail = 47></cfif>
        <cfif Session.Cart.Descrip[ThisItem] EQ "l"><cfset Retail = 49></cfif>
        <cfif Session.Cart.Descrip[ThisItem] EQ "xl"><cfset Retail = 51></cfif>
        <cfif Session.Cart.Descrip[ThisItem] EQ "xxl"><cfset Retail = 53></cfif>
    <cfelse>

    <cfset Retail=Session.Cart.UnitPrice[ThisItem]>
       
    </cfif>

    But if I add the cfset to the top like so it pulls the correct data.  There is something not working in the Session.Cart.Descrip cfif statements.

    <cfif Session.Cart.SKU[ThisItem] EQ "WL6114-1" OR Session.Cart.SKU[ThisItem] EQ "WM6113-1" OR Session.Cart.SKU[ThisItem] EQ "WU6176-1">


         <cfset Retail=Session.Cart.UnitPrice[ThisItem]>


        <cfif Session.Cart.Descrip[ThisItem] EQ "s"><cfset Retail = 45></cfif>
        <cfif Session.Cart.Descrip[ThisItem] EQ "m"><cfset Retail = 47></cfif>
        <cfif Session.Cart.Descrip[ThisItem] EQ "l"><cfset Retail = 49></cfif>
        <cfif Session.Cart.Descrip[ThisItem] EQ "xl"><cfset Retail = 51></cfif>
        <cfif Session.Cart.Descrip[ThisItem] EQ "xxl"><cfset Retail = 53></cfif>
    <cfelse>

    <cfset Retail=Session.Cart.UnitPrice[ThisItem]>
       
    </cfif>

    ilssac
    Inspiring
    December 1, 2009

    What that "something" is is the important problem.

    Looking at the original error, I would sumise that your code is running through a path that provides no setting of the 'retail' variable.

    Examining the original code that path would seem to be an SKU value of WL6114-1, WM6113-1 OR WU6176-1 but that item then does  NOT have a Description of s,m,l,xl NOR xxl.

    Your solution of adding the <cfset...> before that block of ifs just means that this case will get the same value for the retail variable as every other SKU.