CategoryService

This service class contains methods related to Category models.
All public functions are available in the Twig template renderer.

Namespace

IO\Services

Properties
Type Name Description

CategoryRepositoryContract

$categoryRepository

This repository is used to manipulate Category models.

WebstoreConfigurationRepositoryContract

$webstoreConfigurationRepository

This repository is used to read the webstore configuration.

ContactRepositoryContract

$contactRepository

This repository is used to manipulate Contact models.

Category

$currentCategory

The current Category model.

array

$currentCategoryTree

The full branch of the category with parents, e.g. Plants → Edible → Tomatoes.

AuthGuard

$authGuard

Guard class to check for login status.

array

$currentItem

An item.

int

$webstoreId

The current webstore id.

``

$cache

Methods
public __construct($categoryRepository, $webstoreConfigurationRepository, $authGuard, $contactRepository)

CategoryService constructor.

Parameters

Type

Name

Description

CategoryRepositoryContract

$categoryRepository

This repository is used to manipulate Category models.

WebstoreConfigurationRepositoryContract

$webstoreConfigurationRepository

This repository is used to read the webstore configuration.

AuthGuard

$authGuard

Guard class to check for login status.

ContactRepositoryContract

$contactRepository

This repository is used to manipulate Contact models.

public setCurrentCategoryID($catID)

Set the current category by id.

Parameters

Type

Name

Description

int

$catID

The id of the current category

public setCurrentCategory($cat)

Set the current category by id.

Parameters

Type

Name

Description

Category

$cat

The current category

public getCurrentCategory():Category

Gets the current category or null if not set

public get($catID, $lang = null):Category

Get a category by id

Parameters

Type

Name

Description

int

$catID

The category id

string

$lang

The language to get the category (ISO-639-1)

public getForPlentyId($catID, $lang = null, $plentyId = null):Category

Gets a category by id and plentyId

Parameters

Type

Name

Description

int

$catID

The category id

string

$lang

The language to get the category (ISO-639-1)

int

$plentyId

The plentyId to which the category has to be linked

public getChildren($categoryId, $lang = null):array
Deprecated!

This method will not be supported in the future. Please refrain from using it as soon as possible.

Get child categories of a given category referenced by id

Parameters

Type

Name

Description

int

$categoryId

The category id, which children should be fetched

string

$lang

The language in ISO-639-1 format

public getCurrentCategoryChildren($categoryId = null):mixed

Gets the children of the given categoryId or the current category if no categoryId is given.

Parameters

Type

Name

Description

int

$categoryId

public findInCategoryTree($categoryTree, $branch = [], $level = 1):mixed

Recursively iterate through category tree and return the category with the given id.

Parameters

Type

Name

Description

Services

$categoryTree

A tree containing all categories

array

$branch

The current branch of the categoryTree

int

$level

The current depth of the recursion

public getURL($category, $lang = null, $webstoreId = null):string

Return the URL for a given category.

Parameters

Type

Name

Description

Category

$category

The category to get the URL for

string

$lang

The language to get the URL for (ISO-639-1)

int

$webstoreId

public getURLById($categoryId, $lang = null):string

Return the url for a given category id.

Parameters

Type

Name

Description

int

$categoryId

Id of category to fetch

string

$lang

Language in format ISO-639-1

public getDetails($category, $lang):CategoryDetails

Get CategoryDetails of the given category for a given language

Parameters

Type

Name

Description

Category

$category

The category model

string

$lang

The language in format ISO-639-1

public isCurrent($category):bool

Check whether a category is referenced by the current route

Parameters

Type

Name

Description

Category | array

$category

The category to check

public isOpen($category):bool

Check whether any child of a category is referenced by the current route

Parameters

Type

Name

Description

Category | array

$category

The category to check

public isActive($category = null):bool

Check whether a category or any of its children is referenced by the current route

Parameters

Type

Name

Description

mixed

$category

The category to check

public getItems($category = null, $params = [], $page = 1):array

Get items for the given or current category

Parameters

Type

Name

Description

Category

$category

The category of which you want items of (null means currentCategory)

array

$params

The parameters for the repository

int

$page

The desired page, always >0

public getNavigationTree($type = null, $lang = null, $maxLevel = 2, $customerClassId):array

Return the sitemap tree as an array

Parameters

Type

Name

Description

mixed

$type

Only return categories of given types

string

$lang

The language to get sitemap tree for

int

$maxLevel

The deepest category level to load

int

$customerClassId

The customer class id to get tree

public getPartialTree($categoryId, $type = \IO\Constants\CategoryType::ALL):array

Builds a partial tree of starting from the given category id

Parameters

Type

Name

Description

int

$categoryId

The category id

string

$type

The type of category, see /IO/Constants/CategoryType

public getNavigationList($type = [], $lang = null):array

Return the sitemap list as an array

Parameters

Type

Name

Description

string | array

$type

Only return categories of given type, see /IO/Constants/CategoryType

string

$lang

The language to get sitemap list for (ISO-639-1)

public getHierarchy($catID, $bottomUp = false, $filterCategories = false):array

Returns a list of all parent categories including given category.

Parameters

Type

Name

Description

int

$catID

The category id to get the parents for or 0 to use current category

bool

$bottomUp

Set true to order result from bottom (deepest category) to top (= level 1)

bool

$filterCategories

Filter categories

public isVisibleForWebstore($category, $webstoreId = null, $lang = null):bool

Check if a category is visible for a webstore.

Parameters

Type

Name

Description

Category

$category

Category model to check

int

$webstoreId

WebstoreId for filtering result (not plentyId)

string

$lang

Language for filtering result (ISO-639-1)

public setCurrentItem($item)

Setter for current item array.

Parameters

Type

Name

Description

array

$item

An item.

public getCurrentItem():array

Getter for current item array.

public isHidden($categoryId):bool

Check wether a category is hidden or not

Parameters

Type

Name

Description

int

$categoryId

The id of the category to check

public fromMemoryCache()
public resetMemoryCache($key = null)
Parameters

Type

Name

Description

``

$key