Developer forum

Forum » Development » Creating product partslist items

Creating product partslist items

Tom Kamphuis
Reply

Hi guys,

I was wondering if there's any way for creating / updating the product partslist automatically. I'm building an application which receives a product with BOM products attached from a feed and I'd like to fill the DW parts list with these BOM products.

Cheers,
Tom


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

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:

  1. 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.
  2. 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

Votes for this answer: 1
 
Tom Kamphuis
Reply

Great! Thanks Jeppe, your first part of the answer helped me already. Concerning the Order bit, we'll get to that but I'm sure we can use your recommendation as well.

Cheers,
Tom

 

You must be logged in to post in the forum