Manages the product catalogue for an account: products, SKUs, product parameters and their options, categories, ecommerce stores and inventory locations. It also creates and updates product and category images, calculates a product's popularity score from view and order history, and supports bulk creation and searching of SKUs. Registered as the "catalogManager" service, so app developers reach it from server-side JavaScript by name. Most lookups fall back to the parent organisation hierarchy when nothing is found locally, and most mutating methods fire a DefaultIndexedItemUpdatedEvent so search indexes stay in sync with the change.
Group: Managers
Properties
| Property | Returns | Description |
|---|---|---|
| categories | List<Category> | All categories defined in the current organisation. |
| ecomStores | List<ECommerceStore> | The account's ecommerce stores, excluding any whose website has been deleted. |
| inventoryLocations | List<InventoryLocation> | The inventory locations defined in the current organisation. |
| parentOrgsWithProducts | List<Pair> | The ancestor organisations of the current organisation, including itself, that have at least one product, as ID and formatted-name pairs. |
| stores | List<ECommerceStore> | All of the account's ecommerce stores, including any whose website has been deleted. Unlike getEcomStores, this does not filter out stores with deleted websites. |
Methods
createSku(Product product, String name, String title, BigDecimal baseCost) · createAlias(ProductSku mainSku, String aliasCode, String aliasTitle, Organisation distOrg) · addOrUpdateProductImage(Product product, String imageName, String imageHash) · addOrUpdateCategoryImage(Category cat, String imageHash) · addProductParameter(Product product, String title, String code) · deleteProductParameter(ProductParameter pp) · deleteProductParameterOption(ParameterOption ppo) · findParameterOption(Long id) · addProductParameterOption(ProductParameter productParameter, String title, String code) · undeleteSku(ProductSku sku, String newSkuCode) · deleteSku(ProductSku sku) · deleteProduct(Product product, Profile deleteBy) · productCount(ECommerceStore store) · findSkus(Product p) · findSku(Long skuId) · findSkuByProductAndOption(Product p, List<ParameterOption> opts) · findSku(String skuCode) · findDistSku(String skuCode, Organisation distributorOrg) · findSkuInHierarchy(String skuCode) · findSkuInHierarchy(Long skuId) · findProductByName(String productCode) · findProductById(Long id) · findProductInStore(String name, ECommerceStore store) · findProductInStoreById(Long productId, ECommerceStore store) · findProductInStore(Product p, ECommerceStore store) · findSkuInStore(Long id, ECommerceStore store) · findProductByAssetId(String assetId) · findCategoryByAssetId(String assetId) · findProductsByCategory(Category cat) · stockForSku(ECommerceStore store, ProductSku sku, InventoryLocation loc) · createAssetForProduct(Product p, ContentType type) · createAssetForCategory(Category cat, ContentType type) · findProductAssetTypes() · findCategoryAssetTypes() · checkCreateStore(String title, String storeName, String websiteName) · createStore(String storeName, String title, Website website) · addToStore(String productCode, String storeName) · addToStore(Product product, ECommerceStore store) · addProductToCategory(Category category, Product product) · removeProductFromCategory(Category category, Product product) · checkCreateCategory(String name, String title) · getOrCreateCategory(String name, String title) · checkCreateProduct(String name, String title, String category) · getOrCreateProduct(String name, String title, String category) · fireProductUpdated(Product p) · fireProductDeleted(Product p) · newProductSearchBuilder() · searchProducts(String storeName, String query, String category, String sortField, Boolean asc) · searchProducts(ECommerceStore store, String query, Category c, String sortField, Boolean asc) · searchProducts(String storeName, String query, String category, Integer startPrice, Integer endPrice, String sortField, Boolean asc) · searchProducts(ECommerceStore store, String query, Category cat, Integer startPrice, Integer endPrice, String sortField, Boolean asc) · searchProducts(KSearchQuery kSearchQuery, Organisation prodLibOrg, List<Organisation> suppliers, SearchProperties searchProperties) · countSearchProducts(KSearchQuery kSearchQuery, Organisation prodLibOrg, List<Organisation> suppliers) · searchSkus(SkuSearchBuilder b, SearchProperties props) · findSkus(SkuSearchBuilder b, int maxResults) · newSkuSearchBuilder() · locations(ProductSku sku, ECommerceStore store) · locations(ProductSku sku) · findProductInLocation(InventoryLocation location, ProductSku sku) · removeProductInLocation(ProductInLocation pil) · removeProductsFromStore(List<ProductInEComStore> pies) · fireProductInLocationRemoved(ProductInLocation pil) · attributeNames() · attributeTitle(String name) · getEcomStores() · getStores() · findStore(String name) · storeUpdated(ECommerceStore store) · findStore(Long id) · findStoresByWebsite(Website website) · findProductCategories(Product product) · getCategories() · findRootCategories() · findCategory(String code) · findCategory(long id) · updateProductCustomField(long id, FormContext fc) · findInventoryLocation(String code) · findInventoryLocationById(Long id) · getInventoryLocations() · createInventoryLocation(String name, String title) · addToLocation(ProductSku sku, InventoryLocation loc) · updateStock(ProductSku sku, InventoryLocation loc, Long quantity) · deleteInventoryLocation(InventoryLocation loc) · deleteCategory(Category cat) · deleteStore(ECommerceStore store) · newProductBuilder(String productCode) · newProductSkuBuilder(Product product, String skuCode) · countOfOrders(ProductInEComStore pis, Date start, Date finish) · calcPopularity(ProductInEComStore pis, Date now) · matchAndSaveProductImage(String newName, InputStream inputStream) · deleteAllImages() · getParentOrgsWithProducts() · variants(Product p) · createMissingSkus(String skuMode, String costMode, String query, Long stockQuantity) · startCreatingMissingSkusProcess(String skuMode, String costMode, String query, Long stockQuantity) · findProductCategoryContent(String categoryName) · isInCategory(Product product, Category category)
createSku(Product product, String name, String title, BigDecimal baseCost)
Returns: ProductSku
Creates a new SKU for the given product with the given code, display title and base cost, and persists it.
| Parameter | Description |
|---|---|
product | the product the new SKU belongs to |
name | the SKU's code, used as its unique identifier |
title | the SKU's display title |
baseCost | the SKU's base cost, before any pricing rules are applied |
createAlias(ProductSku mainSku, String aliasCode, String aliasTitle, Organisation distOrg)
Returns: ProductSku
Creates and saves a new SKU that is an alias for the given main SKU, sharing its product but with its own code, display title and distributor organisation. Used to give a distributor its own SKU code for an existing product without duplicating the product itself.
| Parameter | Description |
|---|---|
mainSku | the SKU the new alias points to |
aliasCode | the alias SKU's own code |
aliasTitle | the alias SKU's own display title |
distOrg | the distributor organisation the alias is created for |
addOrUpdateProductImage(Product product, String imageName, String imageHash)
Returns: ItemImage
Adds a new image to the product under the given name, or updates the existing image with that name if the given hash differs from the stored one. The hash identifies the image content in the blob store.
| Parameter | Description |
|---|---|
product | the product to add or update the image on |
imageName | the name of the image, used to find an existing image with the same name |
imageHash | the content hash of the image data |
addOrUpdateCategoryImage(Category cat, String imageHash)
Returns: void
Sets the category's main image hash to the given value, but only when the category currently has no image or its existing hash already equals the given one. The hash identifies the image content in the blob store.
| Parameter | Description |
|---|---|
cat | the category to set the main image on |
imageHash | the content hash of the image data |
addProductParameter(Product product, String title, String code)
Returns: ProductParameter
Adds a new product parameter (for example "Colour" or "Size") to the product, used to define the variant dimensions that SKUs are built from.
| Parameter | Description |
|---|---|
product | the product to add the parameter to |
title | the parameter's display title |
code | the parameter's unique code within the product |
deleteProductParameter(ProductParameter pp)
Returns: void
Deletes a product parameter (for example "Colour"), first removing all of its options. Removing an option fails if any active, non-deleted SKU is still linked to it. Saves the owning product and fires a product updated event.
| Parameter | Description |
|---|---|
pp | the product parameter to delete |
deleteProductParameterOption(ParameterOption ppo)
Returns: void
Deletes a single option of a product parameter (for example the "Red" option of a "Colour" parameter). Fails if any active, non-deleted SKU is still linked to the option. Saves the owning product parameter and product, and fires a product updated event.
| Parameter | Description |
|---|---|
ppo | the product parameter option to delete |
findParameterOption(Long id)
Returns: ParameterOption
Finds a product parameter option by its database ID.
| Parameter | Description |
|---|---|
id | the ID of the parameter option to find |
addProductParameterOption(ProductParameter productParameter, String title, String code)
Returns: ParameterOption
Adds a new option (for example "Red") to a product parameter (for example "Colour") and saves it.
| Parameter | Description |
|---|---|
productParameter | the product parameter to add the option to |
title | the option's display title |
code | the option's unique code within the parameter |
undeleteSku(ProductSku sku, String newSkuCode)
Returns: void
Restores a previously soft-deleted SKU, giving it the given new code.
| Parameter | Description |
|---|---|
sku | the soft-deleted SKU to restore |
newSkuCode | the code to give the restored SKU |
deleteSku(ProductSku sku)
Returns: void
Deletes the given SKU. Hard-deletes it if no orders or line items reference it, otherwise soft-deletes it so order history stays intact.
| Parameter | Description |
|---|---|
sku | the SKU to delete |
deleteProduct(Product product, Profile deleteBy)
Returns: void
Soft-deletes the given product, recording who deleted it and when.
| Parameter | Description |
|---|---|
product | the product to delete |
deleteBy | the profile performing the deletion |
productCount(ECommerceStore store)
Returns: long
Counts the number of products in the given ecommerce store, using a database count rather than loading the products themselves.
| Parameter | Description |
|---|---|
store | the store to count products in |
findSkus(Product p)
Returns: List<ProductSku>
Returns the non-deleted SKUs belonging to the given product.
| Parameter | Description |
|---|---|
p | the product to find SKUs for |
findSku(Long skuId)
Returns: ProductSku
Finds a SKU by its numeric database ID, scoped to the current account.
| Parameter | Description |
|---|---|
skuId | the ID of the SKU to find |
findSkuByProductAndOption(Product p, List<ParameterOption> opts)
Returns: ProductSku
Finds the SKU of the given product that matches the given combination of parameter options.
| Parameter | Description |
|---|---|
p | the product to find the SKU in |
opts | the combination of parameter options the SKU must match |
findSku(String skuCode)
Returns: ProductSku
Finds a SKU by its code (alphanumeric). Only looks in the current organisation, not its parents.
| Parameter | Description |
|---|---|
skuCode | the code of the SKU to find |
findDistSku(String skuCode, Organisation distributorOrg)
Returns: ProductSku
Finds a SKU by its code and distributor organisation, for SKUs created as distributor-specific aliases.
| Parameter | Description |
|---|---|
skuCode | the code of the SKU to find |
distributorOrg | the distributor organisation the SKU was created for |
findSkuInHierarchy(String skuCode)
Returns: ProductSkuBean
Finds a SKU by its code, searching the current organisation and then its ancestor organisations until a match is found. Returns a simple bean representation rather than the full entity.
| Parameter | Description |
|---|---|
skuCode | the code of the SKU to find |
findSkuInHierarchy(Long skuId)
Returns: ProductSkuBean
Finds a SKU by its numeric database ID and returns a simple bean representation of it. Validates that the SKU belongs to the current account or one of its ancestor organisations.
| Parameter | Description |
|---|---|
skuId | the ID of the SKU to find |
findProductByName(String productCode)
Returns: Product
Finds a product by its unique name (code) within the current organisation.
| Parameter | Description |
|---|---|
productCode | the product's name |
findProductById(Long id)
Returns: Product
Finds a product by its numeric database ID, searching the current organisation and then its ancestor organisations, up to twenty levels, until a match is found.
| Parameter | Description |
|---|---|
id | the ID of the product to find |
findProductInStore(String name, ECommerceStore store)
Returns: ProductInEComStore
Finds the product-in-store record for the product with the given name in the given store.
| Parameter | Description |
|---|---|
name | the name of the product to find |
store | the store to look in |
findProductInStoreById(Long productId, ECommerceStore store)
Returns: ProductInEComStore
Finds the product-in-store record for the product with the given ID in the given store.
| Parameter | Description |
|---|---|
productId | the ID of the product to find |
store | the store to look in |
findProductInStore(Product p, ECommerceStore store)
Returns: ProductInEComStore
Finds the product-in-store record linking the given product to the given store.
| Parameter | Description |
|---|---|
p | the product to find |
store | the store to look in |
findSkuInStore(Long id, ECommerceStore store)
Returns: ProductSku
Finds a SKU by its ID, returning it only if its product is present in the given store.
| Parameter | Description |
|---|---|
id | the ID of the SKU to find |
store | the store the SKU's product must be in |
findProductByAssetId(String assetId)
Returns: Product
Finds a product by the unique ID of its associated content asset.
| Parameter | Description |
|---|---|
assetId | the unique ID of the product's asset |
findCategoryByAssetId(String assetId)
Returns: Category
Finds a category by the unique ID of its associated content asset.
| Parameter | Description |
|---|---|
assetId | the unique ID of the category's asset |
findProductsByCategory(Category cat)
Returns: List<Product>
Finds all products in the given category.
| Parameter | Description |
|---|---|
cat | the category to search |
stockForSku(ECommerceStore store, ProductSku sku, InventoryLocation loc)
Returns: Long
Looks up the available stock quantity for the given SKU at the given inventory location, within the given store.
| Parameter | Description |
|---|---|
store | the store the stock lookup is scoped to |
sku | the SKU to check stock for |
loc | the inventory location to check stock at |
createAssetForProduct(Product p, ContentType type)
Returns: Asset
Creates a new content asset of the given type for the product, using the product's name as the asset's name, and links it to the product by ID. Saves and flushes the product.
| Parameter | Description |
|---|---|
p | the product to create the asset for |
type | the type of content asset to create |
createAssetForCategory(Category cat, ContentType type)
Returns: Asset
Creates a new content asset of the given type for the category, using the category's name as the asset's name, and links it to the category by ID. Saves and flushes the category.
| Parameter | Description |
|---|---|
cat | the category to create the asset for |
type | the type of content asset to create |
findProductAssetTypes()
Returns: Set<ContentType>
Returns the content types that can be used for a product's asset.
findCategoryAssetTypes()
Returns: Set<ContentType>
Returns the content types that can be used for a category's asset.
checkCreateStore(String title, String storeName, String websiteName)
Returns: boolean
Creates a new ecommerce store with the given name, title and website, unless a store with that name already exists in the current organisation. Fires an index update event when a store is created.
| Parameter | Description |
|---|---|
title | the display title for the new store |
storeName | the unique name for the new store |
websiteName | the name of the website the store belongs to |
createStore(String storeName, String title, Website website)
Returns: ECommerceStore
Creates a new ecommerce store with the given name, title and website. Fires an index update event and invalidates the cached store-name lookup.
| Parameter | Description |
|---|---|
storeName | the unique name for the new store |
title | the display title for the new store |
website | the website the store belongs to |
addToStore(String productCode, String storeName)
Returns: ProductInEComStore
Adds the product with the given code to the store with the given name, both looked up in the current organisation.
| Parameter | Description |
|---|---|
productCode | the code of the product to add |
storeName | the name of the store to add it to |
addToStore(Product product, ECommerceStore store)
Returns: ProductInEComStore
Adds the given product to the given store, creating a product-in-store record. Fires an index update event when the record is created.
| Parameter | Description |
|---|---|
product | the product to add |
store | the store to add it to |
addProductToCategory(Category category, Product product)
Returns: boolean
Adds the given product to the given category. Fires a product updated event when the product is added.
| Parameter | Description |
|---|---|
category | the category to add the product to |
product | the product to add |
removeProductFromCategory(Category category, Product product)
Returns: boolean
Removes the given product from the given category. Fires a product updated event when the product is removed.
| Parameter | Description |
|---|---|
category | the category to remove the product from |
product | the product to remove |
checkCreateCategory(String name, String title)
Returns: boolean
Creates a new category with the given name and title, unless a category with that name already exists in the current organisation.
| Parameter | Description |
|---|---|
name | the unique name for the new category |
title | the display title for the new category |
getOrCreateCategory(String name, String title)
Returns: Category
Finds the category with the given name in the current organisation, or creates and saves a new one with the given name and title if none exists.
| Parameter | Description |
|---|---|
name | the unique name of the category to find or create |
title | the display title to use if a new category is created |
checkCreateProduct(String name, String title, String category)
Returns: boolean
Creates a new product with the given name and title if none exists yet in the current organisation, and adds it to the named category if one is found. If the product already exists, it is instead added to the named category if one is found. Fires a product updated event whenever the product is created or its category membership changes.
| Parameter | Description |
|---|---|
name | the unique name for the product |
title | the display title for the product, used only when creating a new product |
category | the name of the category to add the product to, if it can be found |
getOrCreateProduct(String name, String title, String category)
Returns: Product
Finds the product with the given name in the current organisation, or creates and saves a new one with the given name and title if none exists. Adds the product to the named category if one is found, and fires a product updated event whenever the product is created or its category membership changes.
| Parameter | Description |
|---|---|
name | the unique name of the product to find or create |
title | the display title to use if a new product is created |
category | the name of the category to add the product to, if it can be found |
fireProductUpdated(Product p)
Returns: void
Fires an index update event for the given product, so search picks up the change. Does nothing if the product is null.
| Parameter | Description |
|---|---|
p | the product that was updated |
fireProductDeleted(Product p)
Returns: void
Fires an index update event marking the given product as deleted, so search removes it. Does nothing if the product is null.
| Parameter | Description |
|---|---|
p | the product that was deleted |
newProductSearchBuilder()
Returns: ProductSearchBuilder
Creates a new, empty builder for searching products in the catalogue.
searchProducts(String storeName, String query, String category, String sortField, Boolean asc)
Returns: List<ProductInStoreBean>
Searches for products in the named store and optional category, sorted by the given field, looking the store and category up in the current root organisation.
| Parameter | Description |
|---|---|
storeName | the name of the store to search in |
query | the search term or phrase, optional |
category | the name of the category to search in, optional |
sortField | the name of a property to sort by |
asc | true for ascending order, false for descending |
searchProducts(ECommerceStore store, String query, Category c, String sortField, Boolean asc)
Returns: List<ProductInStoreBean>
Searches for products in the given store and optional category, sorted by the given field.
| Parameter | Description |
|---|---|
store | the store to search in |
query | the search term or phrase, optional |
c | the category to search in, optional |
sortField | the name of a property to sort by |
asc | true for ascending order, false for descending |
searchProducts(String storeName, String query, String category, Integer startPrice, Integer endPrice, String sortField, Boolean asc)
Returns: List<ProductInStoreBean>
Searches for products in the named store and optional category within a price range, sorted by the given field.
| Parameter | Description |
|---|---|
storeName | the name of the store to search in |
query | the search term or phrase, optional |
category | the name of the category to search in, optional |
startPrice | the minimum price to include, optional |
endPrice | the maximum price to include, optional |
sortField | the name of a property to sort by |
asc | true for ascending order, false for descending |
searchProducts(ECommerceStore store, String query, Category cat, Integer startPrice, Integer endPrice, String sortField, Boolean asc)
Returns: List<ProductInStoreBean>
Searches for products in the given store and optional category within a price range, sorted by the given field.
| Parameter | Description |
|---|---|
store | the store to search in |
query | the search term or phrase, optional |
cat | the category to search in, optional |
startPrice | the minimum price to include, optional |
endPrice | the maximum price to include, optional |
sortField | the name of a property to sort by |
asc | true for ascending order, false for descending |
searchProducts(KSearchQuery kSearchQuery, Organisation prodLibOrg, List<Organisation> suppliers, SearchProperties searchProperties)
Returns: List<Product>
Searches for products matching the given query within the given product library organisation and optional suppliers, scoped to the current organisation.
| Parameter | Description |
|---|---|
kSearchQuery | the parsed search query |
prodLibOrg | the product library organisation to search within |
suppliers | the supplier organisations to restrict the search to, optional |
searchProperties | paging and sorting options for the result page |
countSearchProducts(KSearchQuery kSearchQuery, Organisation prodLibOrg, List<Organisation> suppliers)
Returns: long
Counts the products matching the given query within the given product library organisation and optional suppliers, scoped to the current organisation.
| Parameter | Description |
|---|---|
kSearchQuery | the parsed search query |
prodLibOrg | the product library organisation to search within |
suppliers | the supplier organisations to restrict the search to, optional |
searchSkus(SkuSearchBuilder b, SearchProperties props)
Returns: List<ProductSku>
Searches for SKUs matching the given criteria within the current organisation only. Products shared down from parent organisations are not included, even if their SKUs would otherwise match.
| Parameter | Description |
|---|---|
b | the search criteria to match SKUs against |
props | paging and sorting options for the result page |
findSkus(SkuSearchBuilder b, int maxResults)
Returns: List<ProductSku>
Searches for SKUs matching the given criteria, including through parent organisations. Accepts only a single result limit rather than a page size and offset, so it does not support pagination.
| Parameter | Description |
|---|---|
b | the search criteria to match SKUs against |
maxResults | the maximum number of matching SKUs to return |
newSkuSearchBuilder()
Returns: SkuSearchBuilder
Creates a new, empty builder for searching SKUs in the catalogue.
locations(ProductSku sku, ECommerceStore store)
Returns: List<ProductInLocation>
Finds all inventory location records for the given SKU. The store parameter is accepted for compatibility but is not used to filter the results.
| Parameter | Description |
|---|---|
sku | the SKU to find location records for |
store | not used |
locations(ProductSku sku)
Returns: List<ProductInLocation>
Finds all inventory location records for the given SKU.
| Parameter | Description |
|---|---|
sku | the SKU to find location records for |
findProductInLocation(InventoryLocation location, ProductSku sku)
Returns: ProductInLocation
Finds the inventory location record linking the given SKU to the given inventory location.
| Parameter | Description |
|---|---|
location | the inventory location to look in |
sku | the SKU to find |
removeProductInLocation(ProductInLocation pil)
Returns: void
Deletes the given inventory location record, removing the SKU from that location.
| Parameter | Description |
|---|---|
pil | the inventory location record to delete |
removeProductsFromStore(List<ProductInEComStore> pies)
Returns: void
Deletes the given product-in-store records, removing each product from its store. Fires an index update event for each one removed.
| Parameter | Description |
|---|---|
pies | the product-in-store records to delete |
fireProductInLocationRemoved(ProductInLocation pil)
Returns: void
Fires an index update event marking the given inventory location record as deleted. Does nothing if pil is null.
| Parameter | Description |
|---|---|
pil | the inventory location record that was removed |
attributeNames()
Returns: List<Pair<String,String>>
Returns the custom attribute names defined for the account, as name/title pairs. These are configured in ecommerce settings, and the result is cached on the root folder for the life of the request.
attributeTitle(String name)
Returns: String
Looks up the display title for the given attribute name, from the account's configured attribute names.
| Parameter | Description |
|---|---|
name | the attribute name to look up |
getEcomStores()
Returns: List<ECommerceStore>
The account's ecommerce stores, excluding any whose website has been deleted.
getStores()
Returns: List<ECommerceStore>
All of the account's ecommerce stores, including any whose website has been deleted. Unlike getEcomStores, this does not filter out stores with deleted websites.
findStore(String name)
Returns: ECommerceStore
Finds an ecommerce store by its name within the current organisation. The store's ID is cached briefly by name to speed up repeated lookups.
| Parameter | Description |
|---|---|
name | the name of the store to find |
storeUpdated(ECommerceStore store)
Returns: void
Invalidates the entire store-name lookup cache, so subsequent findStore calls re-read from the database. Call this after a store's name changes.
| Parameter | Description |
|---|---|
store | the store that was updated |
findStore(Long id)
Returns: ECommerceStore
Finds an ecommerce store by its numeric database ID, within the current organisation.
| Parameter | Description |
|---|---|
id | the ID of the store to find |
findStoresByWebsite(Website website)
Returns: List<ECommerceStore>
Finds the ecommerce stores belonging to the given website, provided the website belongs to the current organisation.
| Parameter | Description |
|---|---|
website | the website to find stores for |
findProductCategories(Product product)
Returns: List<Category>
Finds the categories the given product belongs to that are owned by the current organisation, ignoring categories owned by other organisations.
| Parameter | Description |
|---|---|
product | the product to find categories for |
getCategories()
Returns: List<Category>
All categories defined in the current organisation.
findRootCategories()
Returns: List<Category>
Finds the top-level categories in the current organisation, that is, categories with no parent category.
findCategory(String code)
Returns: Category
Finds a category by its unique name (code) within the current organisation.
| Parameter | Description |
|---|---|
code | the category's name |
findCategory(long id)
Returns: Category
Finds a category by its numeric database ID, within the current organisation.
| Parameter | Description |
|---|---|
id | the ID of the category to find |
updateProductCustomField(long id, FormContext fc)
Returns: Product
Updates the product with the given ID from the field1, field2 and field3 parameters in the given form context, and saves it. Fires a product updated event.
| Parameter | Description |
|---|---|
id | the ID of the product to update |
fc | the form context to read the field1, field2 and field3 parameters from |
findInventoryLocation(String code)
Returns: InventoryLocation
Finds an inventory location by its unique name (code) within the current organisation.
| Parameter | Description |
|---|---|
code | the location's name |
findInventoryLocationById(Long id)
Returns: InventoryLocation
Finds an inventory location by its numeric database ID, within the current organisation.
| Parameter | Description |
|---|---|
id | the ID of the inventory location to find |
getInventoryLocations()
Returns: List<InventoryLocation>
The inventory locations defined in the current organisation.
createInventoryLocation(String name, String title)
Returns: InventoryLocation
Creates and saves a new inventory location with the given name and title in the current organisation.
| Parameter | Description |
|---|---|
name | the unique name for the new inventory location |
title | the display title for the new inventory location |
addToLocation(ProductSku sku, InventoryLocation loc)
Returns: boolean
Adds the given SKU to the given inventory location, unless it is already there.
| Parameter | Description |
|---|---|
sku | the SKU to add |
loc | the inventory location to add it to |
updateStock(ProductSku sku, InventoryLocation loc, Long quantity)
Returns: ProductInLocation
Updates how much of the given SKU is held at the given inventory location, creating the stock record when the SKU has never been held there before, and re-indexing the SKU. The quantity is the count on hand, not a movement, and must not be null: a null stock figure reads as "this account does not do stock control", which makes the checkout skip its insufficient-stock check.
| Parameter | Description |
|---|---|
sku | the SKU to set the quantity for |
loc | the inventory location the stock is held at |
quantity | the quantity now on hand at that location, zero or more |
deleteInventoryLocation(InventoryLocation loc)
Returns: void
Deletes the given inventory location, along with the stock records held at it. The SKUs themselves are untouched; only the record of how much of each was held there goes with the location. Pricing rules refer to a location by name and are not checked here, so deleting a location a PricingRulesSet names makes checkout fail for the stores using it. Neither the location nor its stock records are Auditable, so there is no restore path.
| Parameter | Description |
|---|---|
loc | the inventory location to delete |
deleteCategory(Category cat)
Returns: void
Deletes the given category. The category's products are not deleted: their membership of it is removed, any sub-categories are detached rather than deleted with it, and any product using it as a brand has its brand cleared. Fires an index update event for each product that was in it, so search stops reporting the category against them.
| Parameter | Description |
|---|---|
cat | the category to delete |
deleteStore(ECommerceStore store)
Returns: void
Deletes the given ecommerce store, recording who deleted it and when. Stores are deleted softly, so the orders placed through it keep pointing at a store which still exists; it simply stops being returned by the finders. The products stay in the catalogue; only this shop front for them goes. Also invalidates the cached store-name lookup, so a store of the same name can be created again afterwards, and removes the store's products from the search index - nothing indexes the store itself, so its product-in-store documents would otherwise keep answering store searches for a store that no longer exists.
| Parameter | Description |
|---|---|
store | the store to delete |
newProductBuilder(String productCode)
Returns: ProductBuilder
Creates a new builder for creating a product with the given code in the current organisation.
| Parameter | Description |
|---|---|
productCode | the code for the new product |
newProductSkuBuilder(Product product, String skuCode)
Returns: ProductSkuBuilder
Creates a new builder for creating or updating a SKU with the given code on the given product.
| Parameter | Description |
|---|---|
product | the product the SKU belongs to |
skuCode | the code for the SKU |
countOfOrders(ProductInEComStore pis, Date start, Date finish)
Returns: Long
Counts how many orders have been placed for the given product-in-store, optionally within a date range.
| Parameter | Description |
|---|---|
pis | the product-in-store to count orders for |
start | the start of the date range, optional |
finish | the end of the date range, optional |
calcPopularity(ProductInEComStore pis, Date now)
Returns: Long
Calculates a product-in-store's popularity score at the given date and time, combining a decayed view-count component and a decayed order-count component, each weighted and half-lifed by the account's ecommerce settings.
| Parameter | Description |
|---|---|
pis | the product-in-store to calculate popularity for |
now | the date and time to calculate the score as of |
matchAndSaveProductImage(String newName, InputStream inputStream)
Returns: MatchImageNameResult
Attempts to match an uploaded image's file name against a product, a product-and-ordinal combination, a product option, a product SKU or a variant code, and saves the image against whichever it matches first. Does nothing and returns null if the file name has no extension, the input stream is null, or the file is not a recognised image type.
| Parameter | Description |
|---|---|
newName | the file name of the uploaded image, including its extension |
inputStream | the image data |
deleteAllImages()
Returns: int
Deletes every product image in the current account, along with clearing the image hash from every parameter option and SKU. Fires a product updated event for each affected product.
getParentOrgsWithProducts()
Returns: List<Pair>
The ancestor organisations of the current organisation, including itself, that have at least one product, as ID and formatted-name pairs.
variants(Product p)
Returns: List<Variant>
Builds the full set of variant lines for the given product: one line per combination of its parameter options, matched to an existing SKU where one exists, plus a line for any SKU that does not correspond to a current combination of options.
| Parameter | Description |
|---|---|
p | the product to build variants for |
createMissingSkus(String skuMode, String costMode, String query, Long stockQuantity)
Returns: int
Creates SKUs for any variant combinations of products matching the given search query that do not already have one. The SKU code and cost are either built by combining the product's own code or cost with its parameter options, or left blank/zero and built purely from the options, depending on skuMode and costMode. If stockQuantity is given, the new SKUs are stocked at that quantity in every inventory location. Fires a product updated event for each affected product.
| Parameter | Description |
|---|---|
skuMode | "combine" to seed the SKU code from the product's own code, any other value to build it purely from the variant's parameter options |
costMode | "combine" to seed the SKU cost from the product's own base cost, any other value to build it purely from the variant's parameter options |
query | the search query used to select which products to process |
stockQuantity | the stock quantity to apply to new SKUs in every inventory location, or null to skip stocking them |
startCreatingMissingSkusProcess(String skuMode, String costMode, String query, Long stockQuantity)
Returns: AsyncJob
Enqueues an asynchronous job that runs createMissingSkus in the background, for use when the operation may take too long to run within a request.
| Parameter | Description |
|---|---|
skuMode | "combine" to seed the SKU code from the product's own code, any other value to build it purely from the variant's parameter options |
costMode | "combine" to seed the SKU cost from the product's own base cost, any other value to build it purely from the variant's parameter options |
query | the search query used to select which products to process |
stockQuantity | the stock quantity to apply to new SKUs in every inventory location, or null to skip stocking them |
findProductCategoryContent(String categoryName)
Returns: ProductCategoryContent
Finds the content configuration for products and SKUs in the named category, if any has been defined in the account's query configuration. The returned object controls how fields are presented.
| Parameter | Description |
|---|---|
categoryName | the name of the category to find content configuration for |
isInCategory(Product product, Category category)
Returns: boolean
Checks whether the given product is in the given category.
| Parameter | Description |
|---|---|
product | the product to check |
category | the category to check membership of |