---
displayed_sidebar: servicesSidebar
---

import ParameterTypes from "@site/src/components/ParameterTypes"

# ProductCategoryService

Provides layer to manipulate product categories.

## constructor

### Parameters

<ParameterTypes parameters={[
  {
    "name": "__namedParameters",
    "type": "`InjectedDependencies`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

___

## Properties

<ParameterTypes parameters={[
  {
    "name": "__configModule__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__container__",
    "type": "`any`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "__moduleDeclaration__",
    "type": "`Record<string, unknown>`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "eventBusService_",
    "type": "[EventBusService](services.EventBusService.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "manager_",
    "type": "`EntityManager`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productCategoryRepo_",
    "type": "TreeRepository&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62; & `object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "transactionManager_",
    "type": "`undefined` \\| `EntityManager`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.CREATED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"product-category.created\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.DELETED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"product-category.deleted\"",
    "expandable": false,
    "children": []
  },
  {
    "name": "Events.UPDATED",
    "type": "`string`",
    "description": "",
    "optional": false,
    "defaultValue": "\"product-category.updated\"",
    "expandable": false,
    "children": []
  }
]} />

___

## Accessors

### activeManager\_

#### Returns

<ParameterTypes parameters={[
  {
    "name": "EntityManager",
    "type": "`EntityManager`",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

## Methods

### addProducts

Add a batch of product to a product category

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "productCategoryId",
    "type": "`string`",
    "description": "The id of the product category on which to add the products",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productIds",
    "type": "`string`[]",
    "description": "The products ids to attach to the product category",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the product category on which the products have been added",
    "expandable": false,
    "children": []
  }
]} />

___

### atomicPhase\_

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.

#### Type Parameters

<ParameterTypes parameters={[
  {
    "name": "TResult",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "TError",
    "type": "`object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "work",
    "type": "(`transactionManager`: `EntityManager`) => Promise&#60;TResult&#62;",
    "description": "the transactional work to be done",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "isolationOrErrorHandler",
    "type": "`IsolationLevel` \\| (`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "the isolation level to be used for the work.",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "maybeErrorHandlerOrDontFail",
    "type": "(`error`: `TError`) => Promise&#60;void \\| TResult&#62;",
    "description": "Potential error handler",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;TResult&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the result of the transactional work",
    "expandable": false,
    "children": []
  }
]} />

___

### create

Creates a product category

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "productCategoryInput",
    "type": "`CreateProductCategoryInput`",
    "description": "parameters to create a product category",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "created product category",
    "expandable": false,
    "children": []
  }
]} />

___

### delete

Deletes a product category

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "productCategoryId",
    "type": "`string`",
    "description": "is the id of the product category to delete",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "a promise",
    "expandable": false,
    "children": []
  }
]} />

___

### fetchReorderConditions

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "productCategory",
    "type": "[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "input",
    "type": "`UpdateProductCategoryInput`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "shouldDeleteElement",
    "type": "`boolean`",
    "description": "",
    "optional": false,
    "defaultValue": "false",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ReorderConditions",
    "type": "`ReorderConditions`",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### listAndCount

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

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "selector",
    "type": "[TreeQuerySelector](../../medusa/types/medusa.TreeQuerySelector.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "Filter options for product category.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "Configuration for query.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "treeSelector",
    "type": "[QuerySelector](../../medusa/types/medusa.QuerySelector.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "Filter options for product category tree relations",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)[], number]&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "an array containing the product category as\n  the first element and the total count of product category that matches the query\n  as the second element.",
    "expandable": false,
    "children": []
  }
]} />

___

### performReordering

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "repository",
    "type": "TreeRepository&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62; & `object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "conditions",
    "type": "`ReorderConditions`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### removeProducts

Remove a batch of product from a product category

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "productCategoryId",
    "type": "`string`",
    "description": "The id of the product category on which to remove the products",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productIds",
    "type": "`string`[]",
    "description": "The products ids to remove from the product category",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the product category on which the products have been removed",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve

Retrieves a product category by id.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "productCategoryId",
    "type": "`string`",
    "description": "the id of the product category to retrieve.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "the config of the product category to retrieve.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "selector",
    "type": "[Selector](../../medusa/types/medusa.Selector.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "treeSelector",
    "type": "[QuerySelector](../../medusa/types/medusa.QuerySelector.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the product category.",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieveByHandle

Retrieves a product category by handle.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "handle",
    "type": "`string`",
    "description": "the handle of the category",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "config",
    "type": "[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "the config of the product category to retrieve.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "selector",
    "type": "[Selector](../../medusa/types/medusa.Selector.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "treeSelector",
    "type": "[QuerySelector](../../medusa/types/medusa.QuerySelector.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the product category.",
    "expandable": false,
    "children": []
  }
]} />

___

### retrieve\_

A generic retrieve for fining product categories by different attributes.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "config",
    "type": "[FindConfig](../../medusa/interfaces/medusa.FindConfig.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "the config of the product category to retrieve.",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "selector",
    "type": "[Selector](../../medusa/types/medusa.Selector.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  },
  {
    "name": "treeSelector",
    "type": "[QuerySelector](../../medusa/types/medusa.QuerySelector.mdx)&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "description": "",
    "optional": false,
    "defaultValue": "{}",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "the product category.",
    "expandable": false,
    "children": []
  }
]} />

___

### shiftSiblings

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "repository",
    "type": "TreeRepository&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62; & `object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "conditions",
    "type": "`ReorderConditions`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;void&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### shouldRetryTransaction\_

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "err",
    "type": "`Record<string, unknown>` \\| `object`",
    "description": "",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "boolean",
    "type": "`boolean`",
    "optional": true,
    "defaultValue": "",
    "description": "",
    "expandable": false,
    "children": []
  }
]} />

___

### transformParentIdToEntity

Accepts an input object and transforms product\_category\_id
into product\_category entity.

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "productCategoryInput",
    "type": "`CreateProductCategoryInput` \\| `UpdateProductCategoryInput`",
    "description": "params used to create/update",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;CreateProductCategoryInput \\| UpdateProductCategoryInput&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "transformed productCategoryInput",
    "expandable": false,
    "children": []
  }
]} />

___

### update

Updates a product category

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "productCategoryId",
    "type": "`string`",
    "description": "id of product category to update",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  },
  {
    "name": "productCategoryInput",
    "type": "`UpdateProductCategoryInput`",
    "description": "parameters to update in product category",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "Promise",
    "type": "Promise&#60;[ProductCategory](../../entities/classes/entities.ProductCategory.mdx)&#62;",
    "optional": false,
    "defaultValue": "",
    "description": "updated product category",
    "expandable": false,
    "children": []
  }
]} />

___

### withTransaction

#### Parameters

<ParameterTypes parameters={[
  {
    "name": "transactionManager",
    "type": "`EntityManager`",
    "description": "",
    "optional": true,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />

#### Returns

<ParameterTypes parameters={[
  {
    "name": "ProductCategoryService",
    "type": "`object`",
    "description": "Provides layer to manipulate product categories.",
    "optional": false,
    "defaultValue": "",
    "expandable": false,
    "children": []
  }
]} />
