Bundle different item based on parent item variation

njwfxnjwfx Member
Hi

I have a parent item that comes in two sizes.

I want to bundle an item with it but a different item for each of the parent item sizes.

I tried this code

<input type="hidden" name="name" value="Parent Product" />
<input type="hidden" name="price" value="115" />
<input type="hidden" name="weight" value="1.6" />
<input type="hidden" name="code" value="parentcode" />


<select name="Size" id="select-size">
<option value="Standard: 45 x 70cm{p-20|w-0.37|c+1}">Standard - $95 </option>
<option value="King: 48 x 90cm{c+2}">King - $115 </option>
</select>


<input type="hidden" name="2:name" value="Bundle product size 1" />
<input type="hidden" name="2:code" value="bprod1" />
<input type="hidden" name="2:price" value="0" />
<input type="hidden" name="2:weight" value="0.001" />
<input type="hidden" name="2:parent_code" value="parentcode1" />
<input type="hidden" name="2:quantity_min" value="1" />
<input type="hidden" name="2:quantity_max" value="999" />

<input type="hidden" name="3:name" value="Bundle product size 2" />
<input type="hidden" name="3:code" value="bprod2" />
<input type="hidden" name="3:price" value="0" />
<input type="hidden" name="3:weight" value="0.001" />
<input type="hidden" name="3:parent_code" value="parentcode2" />
<input type="hidden" name="3:quantity_min" value="1" />
<input type="hidden" name="3:quantity_max" value="999" />


but it gives the eror that:
"The parent code must match the code of another product in the cart"

If I just have one of the bundle blocks e.g.


<input type="hidden" name="2:name" value="Bundle product size 1" />
<input type="hidden" name="2:code" value="bprod1" />
<input type="hidden" name="2:price" value="0" />
<input type="hidden" name="2:weight" value="0.001" />
<input type="hidden" name="2:parent_code" value="parentcode1" />
<input type="hidden" name="2:quantity_min" value="1" />
<input type="hidden" name="2:quantity_max" value="999" />


Then it works fine and has no problems adding the bundled product to the 'parentcode1' size variation

Can you let me know what I need to do to make this work

Thanks
Comments
  • fc_marijafc_marija FoxyCart Team
    Hi @njwfx -

    The bundled products don't support that type of configuration, but you can use JavaScript to dynamically change the child product to make it work. Your HTML will look something like this:

    <form action="https://YOUR-STORE-DOMAIN.foxycart.com/cart" method="post">
    <input type="hidden" name="name" value="Parent Product" />
    <input type="hidden" name="price" value="115" />
    <input type="hidden" name="weight" value="1.6" />
    <input type="hidden" name="code" value="parentcode" />
    <select name="Size" id="select-size" required>
    <option value="">Select a Size</option>
    <option value="Standard: 45 x 70cm{w-0.37|p-20}">Standard - $95 </option>
    <option value="King: 48 x 90cm">King - $115 </option>
    </select>
    <input type="hidden" name="2:name" value="" id="child_name" />
    <input type="hidden" name="2:code" value="" id="child_code"/>
    <input type="hidden" name="2:price" value="0" />
    <input type="hidden" name="2:weight" value="0.001" />
    <input type="hidden" name="2:parent_code" value="parentcode" />
    <input type="hidden" name="2:quantity_min" value="1" />
    <input type="hidden" name="2:quantity_max" value="999" />
    <input type="submit" value="Add Dynamic Bundled Item" />
    </form>
    And the JavaScript would look like this (place before closing </body> tag).

    $( "#select-size" ).change(function() {
    var selected_val = $(this).val();
    var selected = selected_val.substring(0, (selected_val.indexOf(':')));
    $( "#child_name" ).val($("#select-size option:selected").text());
    $( "#child_code" ).val(selected);
    });
    Want to try that out and let us know how it goes?
Sign In or Register to comment.