9 use Magento\Catalog\Model\CategoryFactory as CategoryModelFactory;
18 private $coreRegistry;
33 private $isApplied =
false;
43 private $categoryFactory;
53 CategoryModelFactory $categoryFactory,
56 $this->coreRegistry = $coreRegistry;
57 $this->layer = $layer;
58 $this->categoryFactory = $categoryFactory;
68 $category = $this->getCategory();
69 if ($category->getId()) {
70 while ($category->getLevel() != 0) {
71 if (!$category->getIsActive()) {
74 $category = $category->getParentCategory();
89 $this->isApplied =
true;
90 $this->category =
null;
91 $this->categoryId = $categoryId;
99 private function isApplied()
101 return $this->isApplied;
109 public function getCategory()
111 if ($this->category ===
null) {
114 if ($this->categoryId !==
null) {
115 $category = $this->categoryFactory->create()
121 ->load($this->categoryId);
124 if ($category ===
null || !$category->getId()) {
125 $category = $this->getLayer()
126 ->getCurrentCategory();
129 $this->coreRegistry->register(
'current_category_filter', $category,
true);
130 $this->category = $category;
133 return $this->category;
143 if ($this->isApplied()) {
147 $category = $this->getCategory();
148 $pathIds = array_reverse($category->getPathIds());
149 $curCategoryId = $this->getLayer()
150 ->getCurrentCategory()
152 if (isset($pathIds[1]) && $pathIds[1] != $curCategoryId) {
163 private function getLayer()
setCategoryId($categoryId)
__construct(Registry $coreRegistry, CategoryModelFactory $categoryFactory, Layer $layer)