Developer forum

Forum » Development » Form for adding BOM/configurable products

Form for adding BOM/configurable products

Martin Moen
Reply

I'm trying to add a configurable product to the basket, but I'm struggeling with getting the options into the basket.

I have this structure:

  • Main product (PROD1)
    • First Config Group
      • Option 1 (OPT11)
      • Option 2 (OPT12)
    • Second Config Group
      • Option 1 (OPT21)
      • Option 2 (OPT22)

I have no problem listing the product, config groups and options. But I cant find out how the form fields should look.

This is what I got now:

<form method="post" action="/Default.aspx?ID=@GetPageIdByNavigationTag("CartService")&amp;LayoutTemplate=Swift_MiniCart.cshtml">
<input type="hidden" name="redirect" value="false" />
<input type="hidden" name="cartcmd" value="add" />
<input type="hidden" name="ProductId" value="PROD1">
<input type="hidden" id="Quantity" name="Quantity" value="1" />
<button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary js-add-to-cart-button" title="Add to cart" id="AddToCartButtonBom_PROD1">Add</button
</form>

And it does add my main configurable product to the basket, but no options.
So I added the options:

<form method="post" action="/Default.aspx?ID=@GetPageIdByNavigationTag("CartService")&amp;LayoutTemplate=Swift_MiniCart.cshtml">
<input type="hidden" name="redirect" value="false" />
<input type="hidden" name="cartcmd" value="add" />
<input type="hidden" name="ProductId" value="PROD1">
<input type="hidden" id="Quantity" name="Quantity" value="1" />

<!-- Loop config groups -->
<select name="">

<!-- Loop config group options -->
<option name="" value="">Option name</option>
<!-- Loop config group options end -->


</select>

<!-- Loop config groups end -->


<button type="button" onclick="swift.Cart.Update(event)" class="btn btn-primary js-add-to-cart-button" title="Add to cart" id="AddToCartButtonBom_PROD1">Add</button
</form>

The thing I'm missing I guess is the name and value for the options, and the name for the select.
What values should be there? Does anyone have an example of the produced HTML for a configurable product?


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

Hi Martin

Have a look at this thread: https://doc.dynamicweb.com/forum/swift/swift/swift-and-bom-products

It has a sample template that can be used for reference.

We are currently implementing BOM for ProductViewmodel and the webapi - we have the pull request in GIT right now so it will probably be out with next 9.16 release. That will make rendering of BOMs easier in Swift and headless scenarios.

For adding the BOM to cart, there are currently no changes - so check out the template attached in the zip of the above thread. Also there are other threads on the forum with information about adding BOMs - i.e. to control quantity and using variants in the configuration options.

BR Nicolai

 
Martin Moen
Reply

Thx! I have looket into the thread, but I think it is way too complex for my use.
Do you really need to include display groups, and category fields for it to work?

I miss a clean example of how it works. Do you know if there are any live solutions/sites that use configurable products?
Doesnt have to be Swift can be Rapido. Just want to see the generated HTML, so that I can get the correct naming for the input fields.

These are the form fields I try using now:


And it does add the product to the basket, but there is no information in the basket or admin saying which options have been chosen.
In this case PRODITEM38 and 39/40 are config group id's. And LIST11 is a config item. As far as I can see from the other examples, this should work. But it dont...

 
Martin Moen
Reply

Sorry, my mistake. Whn looking inside EcomOrderLines it looks like they are added after all...

They just dont show up in admin or in the basket.

 

You must be logged in to post in the forum