Skip to main content
Skip to main content

ProductCategoryService

Provides layer to manipulate product categories.

Constructors

constructor

**new ProductCategoryService**(«destructured»)

Parameters

__namedParametersInjectedDependenciesRequired

Properties

__configModule__Record<string, unknown>
__container__anyRequired
__moduleDeclaration__Record<string, unknown>
eventBusService_EventBusServiceRequired
manager_EntityManagerRequired
productCategoryRepo_TreeRepository<ProductCategory> & &#123; addProducts: Method addProducts ; findOneWithDescendants: Method findOneWithDescendants ; getFreeTextSearchResultsAndCount: Method getFreeTextSearchResultsAndCount ; removeProducts: Method removeProducts &#125;Required
transactionManager_undefined | EntityManagerRequired
EventsobjectRequired
Events.CREATEDstringRequired

Default: "product-category.created"

Events.DELETEDstringRequired

Default: "product-category.deleted"

Events.UPDATEDstringRequired

Default: "product-category.updated"

Accessors

activeManager_

Protected get**activeManager_**(): EntityManager

Returns

EntityManager

EntityManagerEntityManagerRequired

Methods

addProducts

**addProducts**(productCategoryId, productIds): Promise&#60;void&#62;

Add a batch of product to a product category

Parameters

productCategoryIdstringRequired
The id of the product category on which to add the products
productIdsstring[]Required
The products ids to attach to the product category

Returns

Promise<void>

PromisePromise<void>Required
the product category on which the products have been added

atomicPhase_

Protected **atomicPhase_**<TypeParameter TResult, TypeParameter TError>(work, isolationOrErrorHandler?, maybeErrorHandlerOrDontFail?): Promise&#60;TResult&#62;

Wraps some work within a transactional block. If the service already has a transaction manager attached this will be reused, otherwise a new transaction manager is created.

TResultobjectRequired
TErrorobjectRequired

Parameters

work(transactionManager: EntityManager) => Promise<TResult>Required
the transactional work to be done
isolationOrErrorHandlerIsolationLevel | (error: TError) => Promise<void | TResult>
the isolation level to be used for the work.
maybeErrorHandlerOrDontFail(error: TError) => Promise<void | TResult>
Potential error handler

Returns

Promise<TResult>

PromisePromise<TResult>Required
the result of the transactional work

create

**create**(productCategoryInput): Promise&#60;[ProductCategory](/references/services/classes/ProductCategory)&#62;

Creates a product category

Parameters

productCategoryInputCreateProductCategoryInputRequired
parameters to create a product category

Returns

Promise<ProductCategory>

PromisePromise<ProductCategory>Required
created product category

delete

**delete**(productCategoryId): Promise&#60;void&#62;

Deletes a product category

Parameters

productCategoryIdstringRequired
is the id of the product category to delete

Returns

Promise<void>

PromisePromise<void>Required
a promise

fetchReorderConditions

Protected **fetchReorderConditions**(productCategory, input, shouldDeleteElement?): [ReorderConditions](/references/services/types/ReorderConditions)

Parameters

productCategoryProductCategoryRequired
A product category can be used to categorize products into a hierarchy of categories.
shouldDeleteElementbooleanRequired

Default: false

Returns

ReorderConditions

ReorderConditionsobjectRequired

listAndCount

**listAndCount**(selector, config?, treeSelector?): Promise&#60;[[ProductCategory](/references/services/classes/ProductCategory)[], number]&#62;

Lists product category based on the provided parameters and includes the count of product category that match the query.

Parameters

Filter options for product category.
Configuration for query.
treeSelectorQuerySelector<ProductCategory>Required
Filter options for product category tree relations

Default: {}

Returns

Promise<[ProductCategory[], number]>

PromisePromise<[ProductCategory[], number]>Required
an array containing the product category as the first element and the total count of product category that matches the query as the second element.

performReordering

Protected **performReordering**(repository, conditions): Promise&#60;void&#62;

Parameters

repositoryTreeRepository<ProductCategory> & &#123; addProducts: Method addProducts ; findOneWithDescendants: Method findOneWithDescendants ; getFreeTextSearchResultsAndCount: Method getFreeTextSearchResultsAndCount ; removeProducts: Method removeProducts &#125;Required
conditionsReorderConditionsRequired

Returns

Promise<void>

PromisePromise<void>Required

removeProducts

**removeProducts**(productCategoryId, productIds): Promise&#60;void&#62;

Remove a batch of product from a product category

Parameters

productCategoryIdstringRequired
The id of the product category on which to remove the products
productIdsstring[]Required
The products ids to remove from the product category

Returns

Promise<void>

PromisePromise<void>Required
the product category on which the products have been removed

retrieve

**retrieve**(productCategoryId, config?, selector?, treeSelector?): Promise&#60;[ProductCategory](/references/services/classes/ProductCategory)&#62;

Retrieves a product category by id.

Parameters

productCategoryIdstringRequired
the id of the product category to retrieve.
the config of the product category to retrieve.

Default: {}

selectorSelector<ProductCategory>Required

Default: {}

treeSelectorQuerySelector<ProductCategory>Required

Default: {}

Returns

Promise<ProductCategory>

PromisePromise<ProductCategory>Required
the product category.

retrieveByHandle

**retrieveByHandle**(handle, config?, selector?, treeSelector?): Promise&#60;[ProductCategory](/references/services/classes/ProductCategory)&#62;

Retrieves a product category by handle.

Parameters

handlestringRequired
the handle of the category
the config of the product category to retrieve.

Default: {}

selectorSelector<ProductCategory>Required

Default: {}

treeSelectorQuerySelector<ProductCategory>Required

Default: {}

Returns

Promise<ProductCategory>

PromisePromise<ProductCategory>Required
the product category.

retrieve_

Protected **retrieve_**(config?, selector?, treeSelector?): Promise&#60;[ProductCategory](/references/services/classes/ProductCategory)&#62;

A generic retrieve for fining product categories by different attributes.

Parameters

the config of the product category to retrieve.

Default: {}

selectorSelector<ProductCategory>Required

Default: {}

treeSelectorQuerySelector<ProductCategory>Required

Default: {}

Returns

Promise<ProductCategory>

PromisePromise<ProductCategory>Required
the product category.

shiftSiblings

Protected **shiftSiblings**(repository, conditions): Promise&#60;void&#62;

Parameters

repositoryTreeRepository<ProductCategory> & &#123; addProducts: Method addProducts ; findOneWithDescendants: Method findOneWithDescendants ; getFreeTextSearchResultsAndCount: Method getFreeTextSearchResultsAndCount ; removeProducts: Method removeProducts &#125;Required
conditionsReorderConditionsRequired

Returns

Promise<void>

PromisePromise<void>Required

shouldRetryTransaction_

Protected **shouldRetryTransaction_**(err): boolean

Parameters

errRecord<string, unknown> | &#123; code: string &#125;Required

Returns

boolean

booleanboolean

transformParentIdToEntity

Protected **transformParentIdToEntity**(productCategoryInput): Promise&#60;[CreateProductCategoryInput](/references/services/types/CreateProductCategoryInput) \| [UpdateProductCategoryInput](/references/services/types/UpdateProductCategoryInput)&#62;

Accepts an input object and transforms product_category_id into product_category entity.

Parameters

params used to create/update

Returns

Promise<CreateProductCategoryInput | UpdateProductCategoryInput>

transformed productCategoryInput

update

**update**(productCategoryId, productCategoryInput): Promise&#60;[ProductCategory](/references/services/classes/ProductCategory)&#62;

Updates a product category

Parameters

productCategoryIdstringRequired
id of product category to update
productCategoryInputUpdateProductCategoryInputRequired
parameters to update in product category

Returns

Promise<ProductCategory>

PromisePromise<ProductCategory>Required
updated product category

withTransaction

**withTransaction**(transactionManager?): [ProductCategoryService](/references/services/classes/ProductCategoryService)

Parameters

transactionManagerEntityManager

Returns

ProductCategoryService

ProductCategoryServiceProductCategoryServiceRequired
Was this section helpful?