/** * Get all sources * @param CategoryInterface $category * * @return array */ public function getAllSources(CategoryInterface $category = null) { $sources = []; if ($this->isValid()) { $categories = $category === null ? $this->categoryManager->getTrees() : $category->getChildren(); foreach ($categories as $category) { $sources[] = ['id' => $category->getCode(), 'text' => sprintf('%s (%s)', $category->getLabel(), $category->getCode())]; $sources = array_merge($sources, $this->getAllSources($category)); } } return $sources; }
/** * Returns category label with|without children count * including|excluding sub-categories * * @param CategoryInterface $category * @param bool $withCount * @param bool $includeSub * @param string $relatedEntity * * @return string */ protected function getLabel(CategoryInterface $category, $withCount = false, $includeSub = false, $relatedEntity = 'product') { $label = $category->getLabel(); if ($withCount) { $label = $label . ' (' . $this->countProducts($category, $includeSub, $relatedEntity) . ')'; } return $label; }
/** * Get category label. * * @param CategoryInterface $category * @param string $localeCode * * @return string */ protected function getCategoryLabel(CategoryInterface $category, $localeCode) { $category->setLocale($localeCode); return $category->getLabel(); }