2 Replies - 362 Views - Last Post: 07 May 2014 - 08:20 PM Rate Topic: -----

#1 Dustinius  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-May 14

Help Displaying # of Product Available

Posted 07 May 2014 - 01:31 PM

I am trying to get the pages of an eCommerce website to display the number of products available (in stock) when different product options (color and size) are selected from option lists. So far the page will display the correct number for products with a size and color option, products with just a size option and products without any options. It will not display the correct number when products only have a color option to select. There is no error message. Here are the sections of code...

<cfif prodOpts.recordCount GTE 1>
  <cfoutput query="prodOpts" group="colorHex">
    <cfset colorList = listAppend(VARIABLES.colorList,prodOpts.color,"|")>
    <cfset colorHexList = listAppend(VARIABLES.colorHexList,prodOpts.colorHex,"|")>
    <cfset tmpSizeList = ''>
    <cfset tmpQtyList = ''>
    <cfoutput>
      <cfset tmpSizeList = listAppend(VARIABLES.tmpSizeList,prodOpts.size)>
      <cfset tmpQtyList = listAppend(VARIABLES.tmpQtyList,prodOpts.quantity)>
    </cfoutput>
    <cfset sizeList = listAppend(VARIABLES.sizeList,VARIABLES.tmpSizeList,"|")>
    <cfset qtyList = listAppend(VARIABLES.qtyList,VARIABLES.tmpQtyList,"|")>
  </cfoutput>
<cfelseif prodOpts.recordCount EQ 1 AND VARIABLES.sizeList EQ "">
  <cfset qtyList = prodOpts.quantity>
<cfelse>
  <cfset qtyList = 0>
</cfif>


function showQuantity(idx){
  document.getElementById('quantityAvailable').value = '';
  var sizeListAry = sizeList.split(',');
  var numAvail = sizeListAry[idx-1];
  if (numAvail != undefined) {
    setMaxQty(sizeListAry[idx-1]);
  }else{
    setMaxQty('');
  }
}

function setMaxQty(val){
  document.getElementById('quantityAvailable').innerHTML = val;
  document.getElementById('maxQty').value = val;
}


and this code displays it on the page...

<p>Available Quantity:</p><div class="wrapper" id="quantityAvailable"></div>


Thanks for any help you can give with this.

Is This A Good Question/Topic? 0
  • +

Replies To: Help Displaying # of Product Available

#2 Craig328  Icon User is offline

  • I make this look good
  • member icon

Reputation: 1926
  • View blog
  • Posts: 3,471
  • Joined: 13-January 08

Re: Help Displaying # of Product Available

Posted 07 May 2014 - 04:53 PM

Dustinius, welcome to DIC.

After looking briefly at your code and re-reading what your issue is, I'm not sure the issue you have is a code issue so much as it is a logic issue. You've included the code that builds your various lists of items and you include the JS code that ends up displaying a count but you haven't included any of the logic code that determines when the JS functions are called or under what conditions the function is invoked.

Further, the two code blocks you've pasted here don't interact with one another. Independently they seem correct enough but, lacking the business logic (which is really what you're describing when you say "[i]t will not display the correct number when products only have a color option to select") they don't contain enough logic to start to be able to help.

What have you tried to do to figure out the issue? In fact, I'd ask if you have the skill level necessary to troubleshoot this. I ask that because if you understood the code you posted then locating the logic issue ought to be a relatively straightforward task. Have you considered simply reaching out to a local CF developer for their assistance? I know the first impulse is to handle it yourself but sometimes folks lack the knowledge for how to do that. Because it's an e-commerce application, I'd suggest that maybe you'd want someone knowledgeable about such things to maybe fix this for you...so you don't inadvertently introduce a code weakness that a hacker could exploit.

Of course, if I'm mistaken about my supposition please feel free to post back here with further comment as to what you've tried to do to troubleshoot and the pertinent code snippets and we'll see what we can do.

Good luck!

This post has been edited by Craig328: 07 May 2014 - 04:54 PM

Was This Post Helpful? 1
  • +
  • -

#3 Dustinius  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 07-May 14

Re: Help Displaying # of Product Available

Posted 07 May 2014 - 08:20 PM

I think you are talking about this function in the code.
function getSize(color){
  var col = color.toLowerCase();
  var sizeOps = '';
  document.getElementById('availSizes').innerHTML = sizeOps;
  switch (col) {
  <cfoutput><cfloop list="#VARIABLES.sizeList#" index="size" delimiters="|"><cfset i++>
  case '#lCase(listGetAt(VARIABLES.colorList,i,'|'))#':
    sizeOps = '<cfloop list="#size#" index="s"><div class="sizeBox">#s#</div></cfloop>';
    sizeLoader('size','Select,#size#');
    sizeList = '#listGetAt(VARIABLES.qtyList,i,'|')#';
    break;
  </cfloop></cfoutput>
  default:
    sizeOps = '<div class="sizeBox" style="border:0;">Please select a color</div>';
    sizeLoader('size','Select');
    sizeList = '';
    break;
  }
  document.getElementById('availSizes').innerHTML = '<p>Available Sizes:</p>' + sizeOps;
  


I have been dissecting the code to find the part that you are describing as the business logic and I believe the problem is that this part of the code lacks a case where the product has a color option but no size option. I inherited this project and I am not the original programmer so the ways things are done here is a little different than how I would do it. In any case I think I am close to finding the a solution and just need to create a case in that function where there is a color option but no size option.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1