Help Simplify CFIF conditional

Ask a Question related to Coldfusion - Advanced Techniques, Design and Development.

  1. #1

    Default Help Simplify CFIF conditional

    I have an eCommerce site which sells apparel, any given shirt my have 1 to 5
    sizes. When the admin enters S,M,L,XL into the backend it creates one field
    record (an array of 4 items). On the page I loop thru the array to display a
    input box for each size so the user can designate how many of each size they
    want (with a little js under it that tallies and evaluates the Quantity field).

    The problem its thus; When u submit the page it sends the form to a page that
    puts the values into Session vars (also arrays) so I am filling the
    SESSION.Cart.sizes var with (for example) "form.size1, form.size2,form.size3"
    and then I can parse the array back out in the "show cart page" so the user,
    and the order taker can see what amt of each size the user wanted.

    So if I account for 7 possible sizes (s-4xl) I need conditional logic to
    account for missing items in an array that has maybe only 3 or 4 sizes. At
    first I thought it was a simple as a series of IsDefined conditions but really
    ANY slot could be empty and any combination of any number of slots could exist.
    The logic and math are a bit complex, I assume.
    Is there an easier way to check for existance and value of (potentially) 7
    items in an array?

    bigbrain28 Guest

  2. Similar Questions and Discussions

    1. Simplify code help wanted
      I want to simplify the following code. First I am reading in 6 values that do not change. Then I have 8 shifting values which are to be read in...
    2. Simplify hatch effects
      Illustrator 10 Windows 2.4 Ghz processor 1.5 GB RAM I used the hatch effects to create this "marble" texture, but it slows down my computer too...
    3. Simplify Tool
      Hi, When drawing two «polygons» sharing a border and then trying to simplify this common border with Object/path/simplify in Illustrator 9 the...
    4. Can you alter or simplify a 3D mapped object?
      I need to wrap a logo around a cylinder in a line art drawing so I did a simple 3D revolved cylinder and mapped on the logo (which is vector art...
    5. Proposal: Array#to_h, to simplify hash generation
      Hi -talk, Ruby has wonderful support for chewing and spitting arrays. For instance, it's easy to produce an array from any Enumerable using...
  3. #2

    Default Re: Help Simplify CFIF conditional

    "Is there an easier way to check for existance and value of (potentially) 7
    items in an array?"

    - No. There is no 'isDefined' for array items. You can use workarounds like
    just referencing all array elements as if they existed and surrounding it in a
    try/catch block. You could also write your own UDF (may be one already on
    cflib.org).

    I would say you need to rethink your data structure. I would recommend using
    something like an array of structs to hold your items. You could in turn, wrap
    this in a CFC and have methods like 'totalCart', 'deleteItem', 'addItem',
    etc... you use to manipulate the cart. You really should not have empty items
    in the array if you're storing your shopping cart data correctly.

    hth

    BSterner Guest

  4. #3

    Default Re: Help Simplify CFIF conditional

    You may want to also look at your database design. It sounds like you're database table is storing redundant data, and/or sizes that may or may not apply to every catalog item.
    BSterner Guest

  5. #4

    Default Re: Help Simplify CFIF conditional

    Thanks for the comments, however, the cart is "CartWeaver" and not of my
    design. We purchased it prior to my ability to create one, so these additional
    functions, such as Quantity based pricing and parsing various sizes per SKU
    were hacks I had to develop. The cart is an array of structs, but I am
    evaluating one of the Arrays with an array whose length is contingent on
    availible sizes for that sku. This is why I was looking for an easy was to say
    "4sm 4med 6lg, and Xl is empty and xxl is not here either..." without writing a
    conditional for every permutation...

    bigbrain28 Guest

  6. #5

    Default Re: Help Simplify CFIF conditional

    Check out this....

    [url]http://cflib.org/udf.cfm?ID=632[/url]
    BSterner Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139