Posted on 21/08/2015 09:34:38
Hi Tom,
It depends on what you want to do.
If you want to display the information in a product list or a product details view, then you can manipulate the Product.Items
collection. You also need to make sure that the Product.Type
is BOM
.
If you want to add a custom parts list to an order, which I assume will be your ultimate goal, then it's a bit more tricky. There are two ways to do it:
- Create the orderline yourself from the bottom. There are currently no helper methods to create a parts list orderline from a product instance. They either take a product instance and cannot handle BOM or they can handle BOM but take product ids. You can create a base orderline from the main product and manually add the parts list products, which leads me to the second option.
- Use either
CartCatch.OrderLineBuilder
or Order.CreateOrderLine
to create a base orderline. Then add the parts list product orderlines to the OrderLine.BOMOrderLines
on the base orderline you created earlier. See below for an example of how we create a parts list orderline internally.
I'd recommend option 2 and using CartCatch.OrderLineBuilder
.
This is how we build a parts list orderline internally:
// This code will be run for each parts list product to add.
// Assume that the product to add (bomProduct) is given.
var bomLine = new OrderLine();
bomLine.SetProductInformation(bomProduct);
bomLine.BOM = true;
bomLine.Quantity = bomQuantity;
bomLine.Order = currentCart; // Could be Dynamicweb.eCommerce.Common.Context.Cart
bomLine.ParentLineID = parentOrderLineId;
bomLine.Reference = referenceUrl; // Could be the page that added the product, or can be left out
bomLine.SetOrderLineType(OrderLineType.Product);
- Jeppe