The Foxy forums are on the move!

We're in the process of moving our forums over to a new system, and so these forums are now read-only.
If you have a question about your store in the meantime, please don't hesitate to reach out to us via email.

Multiple Parent and Child Products with limits

bewsterbewster Member
I'm needing the following and wondering if foxycart can do this. I've done some sample setups but can't get it to perform how I need to. Selling individual items is pretty straight forward. The following is my scenario.

I sell boxes of cookies but each box can be custom built. For instance I sell cookies in 12, 24, and 36 counts. In each box you can choose from over a dozen different options (sugar, chocolate chip, peanut butter, etc) up to the box size they choose (12,24, or 36).

A person may buy 2 12-count boxes or 1 12-count and 1 24-count boxes. Each box can have different types of cookies.

Any suggestions, blogs, or tutorials related to this?
  • fc_adamfc_adam FoxyCart Team

    Good question!

    There are a couple different ways you could approach this - but you'd essentially be using our product bundling functionality to achieve it.

    If you have a single page where customers can build out a box - you could let them create a single box as part of a single add to cart. If they select a 12 count box, allow them to select the different flavours they want to include up to that limit. In the add to cart form you'd set up a parent product as the box size, and then child products linked to the parent using the parent_code attribute. When added to the cart, the child products wouldn't be editable, the customer would need to remove that box and add a new one to the cart from your site, but they could order multiples of that box. To allow a customer to add multiple boxes of the same size with different contents, you would also need to dynamically set the parent code to be a unique string for each add to cart, to ensure that the boxes aren't joined together.

    We helped a user with a similar set up just recently - if you wanted to take this approach we could share some javascript with you for that.

    On the more advanced end, you could also allow the customer to build out the box on demand in the cart - also allowing them to make changes in the cart. This would require some decent custom coding, as there are a few aspects to it and we don't currently support total quantity limits for product bundles. We can provide some more specific advice if you're interested in taking this approach - but you would essentially be using javascript to add in some custom validations on the cart and checkout. The validations would look at each parent product, and calculate the total quantity of child products present, working out if it's a complete box or not. If you detect any that aren't complete, you could show warnings and prevent a checkout from happening. You could also prevent a quantity change in the cart if it would exceed the box limit.

    On your own site, you could dynamically show the different boxes the customer has in their cart, allowing them to add additional products into them as desired - only showing those that still have room available.

    Both approaches would allow you to have bundles of products in the cart - but both have a bit of a different experience for the customer. The first approach would be simpler in execution, but the latter does provide perhaps more flexibility for the customer. If you'd like any additional details on either approach, let us know and we'll do our best to help out.
  • SparkySparky Member
    edited September 2019
    Hey Adam and all - can you give me some help with this? I have a similar situation: I want to change some of my products so that they come bundled with coffee. I need them to select the coffee options (do they want medium roast, darker roast, a surprise or decaf plus whole bean or ground?)

    I'm OK if they don't want the coffee, so NO child product can be an option. The price will not be adjusted - it's the same price whether the child product is picked or not.

    Or is the 1:, 2:, 3:, 4:, etc… product option the better way to set this up?

  • fc_adamfc_adam FoxyCart Team

    If the coffee is bundled with the product, we'd recommend setting it up as a bundled product, setting the parent code of the child product (the coffee) to match the code of the parent product. You would also want to use the 1:, 2: prefixes though too, so that you can add both products to the cart at the same time.

    As a quick example of what the HTML could look like:
    <form action="" method="post" accept-charset="utf-8">
    <input type="hidden" name="name" value="My Product" />
    <input type="hidden" name="price" value="10" />
    <input type="hidden" name="code" value="sku123" />

    <input type="hidden" name="2:name" value="Bonus Coffee" />
    <input type="hidden" name="2:price" value="0" />
    <input type="hidden" name="2:parent_code" value="sku123" />
    <input type="hidden" name="2:quantity_max" value="1" />
    <input type="hidden" name="2:quantity" value="0" />

    <label for="bonus">
    <input id="bonus" type="checkbox" name="2:quantity" value="1" /> Would you like to include some free coffee?
    <div class="free-bonus" style="display:none;">
    <label for="style">Style</label>
    <select id="style" name="2:style">
    <option value="Medium">Medium Roast</option>
    <option value="Dark">Darker Roast</option>
    <option value="Surprise">Surprise Me</option>
    <option value="Decaf">Decaf</option>
    <label for="grind">Whole Bean or Ground?</label>
    <select id="grind" name="2:Grind">
    <option value="Whole Bean">Whole Bean</option>
    <option value="Coarse">Coarse Grind</option>
    <option value="Medium">Medium Grind</option>
    <option value="Fine">Fine Grind</option>
    <option value="Extra Fine">Extra Fine Grind</option>
    <input type="submit" value="Add a Cool Example" class="submit" />
    The form would also need some javascript to hide and show the free product options:
    $(function() {
    $("#bonus").on("click", function() {
    You can see the form adds two products to the cart, and has a checkbox to allow the customer to specify if they want to add a bonus coffee or not. If they do, it sets that second products quantity to 1 (otherwise it's 0 so it doesn't add), and shows the two dropdowns for the customer to customise their bonus.

    There will probably need to be some additional HTML for formatting and styling - but that should hopefully point you in the right direction!
  • You people are so helpful and awesome! Thanks - I will try this out. :smiley:
Sign In or Register to comment.