Note that there are some explanatory texts on larger screens.

plurals
  1. POClean way to build & update SKU combinations from JSON, keep stock, minimize DB queries?
    primarykey
    data
    text
    <p>My database has records per SKU, giving product options (id's actually, but for clarity I'm showing actual values): </p> <pre> --------------------------------------------------------- id color size material stock --------------------------------------------------------- 1 blue m cotton 3 2 blue s cotton 5 3 blue xl plastic 6 4 white l plastic 1 5 white m plastic 9 </pre> <p>I would like to show select boxes for each option that update the others upon change, so you can only select possible combinations (ie. choosing 'plastic' renders white(l+m) and blue(xl) )</p> <p>I can do this with jQuery/Ajax but that requires queries to the db for every select-box change, rebuilding all other select-boxes. It's mainly the db queries I want to minimize, so I considered building a JSON representation of the above table, cache it, use it for the selects. I'd update the JSON result only when <em>total</em> stock changes (which is available from another table with a single query).</p> <p>The problem is I can not figure out how to do that properly; I'm not very skilled in JS and keep bumping into walls. I'm not even sure it's the right approach, how to get the right ID for the chosen combination posted back etc. Yet I'm quite convinced this is a rather common problem, or so it seems. But searching surprisingly did not give me similar problems; just a lot 'one select updates the other through ajax' info.</p> <p>So my question is: how would one tackle this problem efficiently? </p> <p><strong>EDIT: Some additional info:</strong> this is for a product detail page where we only show the options (SKU's) for that single 'master' product.</p> <p>I also found this <a href="http://snipplr.com/view.php?codeview&amp;id=26338" rel="nofollow">cascading</a> approach which is close. Problem is I can not copy that approach since my 'blue' or 'white' is not unique, or so it seems.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload