Once the products and SKUs have fractional units enabled, as outlined in the Enabling Fractional Units in Products and SKUs section, you can set the units in which they can be sold by specifying their UnitOfMeasure
.
You can retrieve the UnitOfMeasure
using the UnitOfMeasureDroplet
, as described in the Guide to Setting Up a Store, or by defining and configuring fractional quantities and units of measure as described in the next sections.
For additional detail on all of the classes described in this section, refer to the ATG Platform API Reference.
Unit of Measure Configuration Files
The unitsOfMeasure
values are configured in a configuration file, which identifies the types of measurement (for example liters, kilograms, etc.) and its values. The unitsOfMeasure
values can be one of the following types
:
options
: Allows you to configure the available unit breakdown for the unit of measure. For example, you could configure a customer selectable list of options as a quarter pound, a half pound or three quarters of a pound. Options can be localized by setting thei18n
property totrue
, which uses the value as a lookup key on the resource bundle.increments
: Allows you to configure unit increments that customers can select for a SKU or product. For example, you could configure a product of SKU to be sold in increments of .5 of a unit. Increment values enable you to create a stepper control that allows a customer to add incremental quantities of a product or SKU.
Configure the options and increments in the UnitOfMeasure
configuration file for the specific unit of measure. By default, the PoundsUnitOfMeasure
and the GallonsUnitOfMeasure
are configured to be options
types. For example:
$class=atg.commerce.units.UnitsOfMeasure type=options options= \ 0.25=oneQuarter, \ 0.5=oneHalf, \ 0.75=threeQuarters
The KilogramsUnitOfMeasure
and LitersUnitOfMeasure
are configured to be increment
types. For example:
$class=atg.commerce.units.UnitOfMeasure type=increment increment=0.1
By default, the units of measures provided are:
Unit of Measure | Type | Options | Increments |
---|---|---|---|
Pounds |
| 0.25 = ¼ pound | N/A |
Kilograms |
| N/A | 0.1 where 0.1 = 100gm |
Gallons |
| 0.25 = 1 quart | N/A |
Liters |
| N/A | 0.1 where 0.1 = 100ml |
UnitOfMeasureManager Class
The UnitOfMeasureManager
class is a manager class that returns a unit of measure’s configuration once the configuration files have been implemented. The UnitOfMeasureManager
class maps the unit of measure configurations identified by the configuration files using the unitsOfMeasure
ServiceMap
, where the value of the units are used as keys in a service map configured in CatalogTools
. The ServiceMap
allows you to identify the fractional quantities that have been configured. For example:
## ServiceMap of unitOfMeeasure to UnitOfMeasure unitsOfMeasure= \ pounds=PoundsUnitOfMeasure, \ kilograms=KilogramsUnitOfMeasure, \ gallons=GallonsUnitOfMeasure, \ liters=LitersUnitOfMeasure
Note that when new units of measure are added, you must update the ServiceMap
.
UnitOfMeasure Class
The UnitOfMeasure
class gets and sets the configuration of a unit of measure. It identifies the type of fractional unit used, such as options
or increments
, and the corresponding options (including the values and labels) or increments of the unit to be used. It also returns an ordered list of UnitOfMeasureOption
beans. The list is ordered in unit value by increasing order. The unit labels can be localized when the il8n
parameter is set to true
.
The UnitOfMeasure
class can be used to set localization when rendering products and SKUs in a product detail page’s input fields and data by calling the il8n
parameter. The UnitOfMeasureResources.properties
file contains the il8n
parameter, which is a boolean property that localizes unit labels when set to true
.
Use this class if you are not using the UnitOfMeasureDroplet
and want the value for a specific unit of measure. This class also returns options based on locale.
UnitOfMeasureOption Class
The UnitOfMeasureOption
class represents the unit of measure values and their associated labels. For example, 0.25 could be labeled as a “quarter gallon”. This class allows you to set unit values, labels and increments as well as identify if the labels should be localized.