LocalizingInventoryManager
is an implementation of the InventoryManager
interface that is used when you want to have more than one set of inventory data (and therefore more than one InventoryManager
). LocalizingInventoryManager
determines which data/manager set to use based on your customer’s locale
.
LocalizingInventoryManager
contains the following properties:
defaultLocaleKey
– the locale to use to determine whichInventoryManager
to use when the locale cannot be determined from the request.defaultInventoryManager
– theInventoryManager
to use when theInventoryManager
cannot be determined from the locale.inventoryManagers
– a Map pairinglocaleKeys
to their correspondingInventoryManager
components.useDefaultInventoryManager
– a Boolean property that determines whether to use thedefaultInventoryManager
if anInventoryManager
cannot be found for the user’s locale.
LocalizingInventoryManager
implements all the InventoryManager
methods twice:
once with the signature provided in the
InventoryManager
interfaceonce with an extra
pLocaleKey
String parameter
The methods with the InventoryManager
signatures call the second implementations, passing the value of the defaultLocaleKey
property as the extra parameter.
The second methods retrieve the proper InventoryManager
by calling the getInventoryManager
method with the localeKey
as the parameter. Then, they call the corresponding method in the InventoryManager
that was retrieved.
LocalizingInventoryManager
is compatible with the InventoryManager
interface because you can pass it the same parameters and it will use the default InventoryManager
to perform operations. You also can make your calls with the extra pLocaleKey
parameter, and use LocalizingInventoryManager
to handle multiple InventoryManager
instances.
The getInventoryManager
method takes the localeKey
parameter and checks the inventoryManagers
map for a corresponding InventoryManager
. If it finds one, it is returned. Otherwise, it checks the useDefaultInventoryManager
property. If true, it returns the DefaultInventoryManager
. If false, an error is thrown.