Jump to content

Recommended Posts

Hi,

I was hoping for some advice, code, solutions or references:

Goal:

I need to build a 'decision tree' or otherwise find a module that creates one in a Prestashop website we've developed. Its sole purpose should be to lead customers down a path (of questions with each 2-3 answers, that lead to more questions/the result). The end-goal is to have the customer be presented with a product that best suits his/her needs, based on which questions were answered. Desirably/preferably the result should then be shown AND/OR emailed to the person that has filled in the 'form', or answered the tree.

The problem:
I've searched the internet high and low for a module/component/plugin that could build such a tree - as my coding skills in creating one is a little limited. I have thus far found a coding example, and even though it successfully builds a part of a tree (or a single branch), I believe that it is simply going to become too complicated to build multiple branches. This tree can be seen on http://profitek.co.za/content/45-tester-tree-branches

 

Please, if anybody has any advice on how to get a Decision Tree built (most certainly preferably through an interface), please share your thoughts, ideas or leads that I can follow.

This topic is relevant for today (19/12/2014).

Thank you very much

Link to comment
Share on other sites

The Code that is currently being used to create the current Decision Tree looks as follows (Apologies for the bad indenting, as is copy pasted from the source):


----------------------------------------------------THE HTML

<form action="#" id="unique_id" class="productFilter"><fieldset class="step1 option0"><legend>Mount</legend>
<p><input id="question_1" name="group_1" type="radio" /> <label for="question_1">79 Inch Rackmount</label></p>
<p><input id="question_2" name="group_1" type="radio" /> <label for="question_2">Dinrail Mount</label></p>
</fieldset><fieldset class="hide step2 option1"><legend>Ethernet</legend>
<p><input id="question_1_1" name="group_2" type="radio" /> <label for="question_1_1">Fast Ethernet</label></p>
<p><input id="question_1_2" name="group_2" type="radio" /> <label for="question_1_2">Gigabit Ethernet</label></p>
</fieldset><fieldset class="hide step2 option2"><legend>Ethernet</legend>
<p><input id="question_2_1" name="group_3" type="radio" /> <label for="question_2_1">N/A</label></p>
<p><input id="question_2_2" name="group_3" type="radio" /> <label for="question_2_2">N/A</label></p>
</fieldset><fieldset class="hide step3 option11"><legend>Port Count</legend>
<p><input id="question_1_1_1" name="group_4" type="radio" /> <label for="question_1_1_1">8 Ports</label></p>
<p><input id="question_1_1_2" name="group_4" type="radio" /> <label for="question_1_1_2">24 Ports</label></p>
</fieldset><fieldset class="hide step3 option12"><legend>Port Count</legend>
<p><input id="question_1_2_1" name="group_5" type="radio" /> <label for="question_1_2_1">4 FO Ports</label></p>
<p><input id="question_1_2_2" name="group_5" type="radio" /> <label for="question_1_2_2">16 FO Ports</label></p>
</fieldset><fieldset class="hide step4 option111"><legend>Power Input</legend>
<p><input id="question_1_1_1_1" name="group_8" type="radio" /> <label for="question_1_1_1_1">Single Power Input</label></p>
<p><input id="question_1_1_1_2" name="group_8" type="radio" /> <label for="question_1_1_1_2">Redundant Power Input</label></p>
</fieldset><fieldset class="hide step4 option112"><legend>Power Input</legend>
<p><input id="question_1_1_2_1" name="group_9" type="radio" /> <label for="question_1_1_2_1">Single Power Input</label></p>
<p><input id="question_1_1_2_2" name="group_9" type="radio" /> <label for="question_1_1_2_2">Redundant Power Input</label></p>
</fieldset><fieldset class="hide step4 option121"><legend>Port Count</legend>
<p><input id="question_1_2_1_1" name="group_10" type="radio" /> <label for="question_1_2_1_1">Single Power Input</label></p>
<p><input id="question_1_2_1_2" name="group_10" type="radio" /> <label for="question_1_2_1_2">Redundant Power Input</label></p>
</fieldset><fieldset class="hide step4 option122"><legend>Temp Range</legend>
<p><input id="question_1_2_2_1" name="group_11" type="radio" /> <label for="question_1_2_2_1">Standard</label></p>
<p><input id="question_1_2_2_2" name="group_11" type="radio" /> <label for="question_1_2_2_2">Extended</label></p>
</fieldset><fieldset class="hide step5 option1221"><legend>Power Input</legend>
<p><input id="question_1_2_2_1_1" name="group_12" type="radio" /> <label for="question_1_2_2_1_1">Power Input 24/36/48 VAC</label></p>
<p><input id="question_1_2_2_1_2" name="group_12" type="radio" /> <label for="question_1_2_2_1_2">Power Input 110/230 VAC</label></p>
</fieldset></form>
<p>Lorizzle ipsizzle doggy sit amizzle, shizzlin dizzle adipiscing nizzle. Nullizzle sapien velizzle, nizzle break yo neck, yall, suscipizzle da bomb, dizzle vizzle, sheezy.</p>
<a title="A button, fo shizzle." href="#" class="buttonGreen"><span>Click me. Do it. Now!</span></a>
 
-----------------------------------------------------------------------THE SCRIPT
<script>// <![CDATA[
var base = {
 productFilterSetup: function() {
 $('.productFilter').each(
 function() {
 var tmp = new base.filterGroup(this);
 tmp.setup();
 });
 },
 filterGroup: function(filter_group) {
 var me = this;
 me.target_element = filter_group;
 me.active_element_index = 0;
 me.setup = function() {
 $(filter_group).find('input[type=radio]').bind('click', function() {
 me.update(this);
 });
 };
 me.update = function(target_radio) {
 var fieldsets = $(me.target_element).find('fieldset'),
 len = fieldsets.length,
 i = 0,
 j = 0,
 radios, 
 radios_len, 
 options = [],
 options_buffer = '',
 num_of_steps = 0;
 
 for (i = 1; i <= num_of_steps + 1; i += 1) {
 if ($('fieldset.step' + i).length > 0) {
 num_of_steps += 1;
 }
 }
 
 for (i = 0; i < num_of_steps; i += 1) {
 if ($(target_radio).parents('fieldset.step' + (i + 1)).length > 0) {
 for (j = i; j < num_of_steps; j += 1) {
 $('fieldset.step' + (j + 2) + ' input[type=radio]').attr('checked', false);
 }
 }
 }
 
 for (i = 0; i < len; i += 1) {
 radios = $(fieldsets).find('input[type=radio]');
 radios_len = radios.length;
 for (j = 0; j < radios_len; j += 1) {
 if ($(radios[j]).is(':checked')) {
 options.push(j + 1);
 }
 }
 }
 fieldsets.addClass('hide');
 $('fieldset.option0').removeClass('hide');
 for (i = 0; i < options.length; i += 1) {
 options_buffer += options;
 $('fieldset.option' + options_buffer).removeClass('hide');
 }
 };
 }
};
 
$(
function() {
 base.productFilterSetup();
});
// ]]>
</script>
 
---------------------------------------------------------THE CSS
<style>
fieldset {margin:10px 0;}
.hide {display:none;}
</style>
Link to comment
Share on other sites

×
×
  • Create New...