Product units

In Dynamicweb, you can create product units – like kilo, pair, and box – and let customers choose between ordering e.g. a pack, a box and a pallet of pencils. On each product you can then define precisely what is in a box for that product. Then, when the customer adds a box of pencils to cart and buys it, the correct number of pencils will be subtracted from the stock level of the product.

To create a product unit:

  • Go to Settings > Ecommerce > Product Catalog > Product units
  • Click New product unit in the toolbar
  • Provide a name for the product unit
  • Save

You can only create new product units when the default ecommerce language is selected in the toolbar. It can then be localized to other ecommerce languages by changing the language context and saving the product unit with a localized name. If you do not localize a product unit, no label will be rendered in frontend for that product unit in that language context. Read more about ecommerce languages here.

You can only create new product units when your default language is selected in the toolbar.

Once a product unit has been created, you can create language-specific version of it by changing the language and saving the product unit in the new language.

If you don’t, no unit category label will be rendered in the frontend for that language. Read more about languages in Dynamicweb.

The product units you create here are not automatically available in frontend for all products – which is good, because not all products are sold in a box, you know – but must be explicitly added to each product manually or as a part of an integration. There are two reasons for this:

  • Not all products are sold in all units – a box of beer is called a crate and you don’t buy a six pack of socks
  • The contents of a box can vary wildly from product to product – a box of socks doesn’t contain the same number of items as a box of pencils

To add units to a product:

  1. Go to PIM or Ecommerce and open a product
  2. Click the Units button in the toolbar
  3. Create a base unit – this could be piece, box or bottle, depends on the product
  4. Create additional units and define how many of the base unit each product unit corresponds to

Once you’ve specified which units are available for a products you can add unit stock via the stock matrix – which will make them available in your templates

Product units are priced using the price matrix – which works in the same manner as the stock matrix, in that you create an entry for each combination of product unit, currency, variant, etc.

To add a specific unit to cart use a cart command with the UnitId parameter – here’s an example using the add-command from a ProductViewModel template.

<!-- Add to cart form with unit selector--> <form method="post"> <input type="hidden" name="ProductId" value="@Model.Id" /> <select id="UnitId" name="UnitId"> @foreach (var unit in Model.UnitOptions) { <option value="@unit.Id">@unit.Name</option> } </select> <button " type="submit" name="CartCmd" value="Add">Add to cart</button> </form>