public function testCanShowFalse() { /** @var $category \Magento\Catalog\Model\Category */ $category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Category'); $this->assertFalse($this->_helper->canShow($category)); $category->setId(1); $this->assertFalse($this->_helper->canShow($category)); $category->setIsActive(true); $this->assertFalse($this->_helper->canShow($category)); }
/** * Retrieve Visitor/Customer Last Viewed URL * * @return string */ public function getLastViewedUrl() { $productId = $this->_catalogSession->getLastViewedProductId(); if ($productId) { try { $product = $this->productRepository->getById($productId); } catch (NoSuchEntityException $e) { return ''; } /* @var $product \Magento\Catalog\Model\Product */ if ($this->_catalogProduct->canShow($product, 'catalog')) { return $product->getProductUrl(); } } $categoryId = $this->_catalogSession->getLastViewedCategoryId(); if ($categoryId) { try { $category = $this->categoryRepository->get($categoryId); } catch (NoSuchEntityException $e) { return ''; } /* @var $category \Magento\Catalog\Model\Category */ if (!$this->_catalogCategory->canShow($category)) { return ''; } return $category->getCategoryUrl(); } return ''; }
/** * @return array */ protected function _getItemsData() { $this->_requestVar = str_replace('bx_products_', '', $this->bxFacets->getFacetParameterName($this->fieldName)); if (!$this->bxDataHelper->isHierarchical($this->fieldName)) { $attributeModel = $this->_config->getAttribute('catalog_product', substr($this->fieldName, 9))->getSource(); $order = $this->bxDataHelper->getFieldSortOrder($this->fieldName); if ($order == 2) { $values = $attributeModel->getAllOptions(); $responseValues = $this->bxDataHelper->useValuesAsKeys($this->bxFacets->getFacetValues($this->fieldName)); $selectedValues = $this->bxDataHelper->useValuesAsKeys($this->bxFacets->getSelectedValues($this->fieldName)); foreach ($values as $value) { $label = is_array($value) ? $value['label'] : $value; if (isset($responseValues[$label])) { $facetValue = $responseValues[$label]; $selected = isset($selectedValues[$facetValue]) ? true : false; $paramValue = $this->is_bx_attribute ? $this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue) : $attributeModel->getOptionId($this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue)); $this->itemDataBuilder->addItemData($this->tagFilter->filter($this->bxFacets->getFacetValueLabel($this->fieldName, $facetValue)), $selected ? 0 : $paramValue, $this->bxFacets->getFacetValueCount($this->fieldName, $facetValue), $selected, 'flat'); } } } else { $selectedValues = $this->bxDataHelper->useValuesAsKeys($this->bxFacets->getSelectedValues($this->fieldName)); $responseValues = $this->bxFacets->getFacetValues($this->fieldName); foreach ($responseValues as $facetValue) { $selected = isset($selectedValues[$facetValue]) ? true : false; $paramValue = $this->is_bx_attribute ? $this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue) : $attributeModel->getOptionId($this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue)); $this->itemDataBuilder->addItemData($this->tagFilter->filter($this->bxFacets->getFacetValueLabel($this->fieldName, $facetValue)), $selected ? 0 : $paramValue, $this->bxFacets->getFacetValueCount($this->fieldName, $facetValue), $selected, 'flat'); } } } else { $count = 1; $facetValues = array(); $parentCategories = $this->bxFacets->getParentCategories(); $parentCount = count($parentCategories); $value = false; foreach ($parentCategories as $key => $parentCategory) { if ($count == 1) { $count++; $homeLabel = __("All Categories"); $this->itemDataBuilder->addItemData($this->tagFilter->filter($homeLabel), 2, $this->bxFacets->getParentCategoriesHitCount($key), $value, 'home parent'); continue; } if ($parentCount == $count++) { $value = true; } $this->itemDataBuilder->addItemData($this->tagFilter->filter($parentCategory), $key, $this->bxFacets->getParentCategoriesHitCount($key), $value, 'parent'); } $sortOrder = $this->bxDataHelper->getFieldSortOrder($this->fieldName); if ($sortOrder == 2) { $facetLabels = $this->bxFacets->getCategoriesKeyLabels(); $childId = explode('/', end($facetLabels))[0]; $childParentId = $this->categoryFactory->create()->load($childId)->getParentId(); end($parentCategories); $parentId = key($parentCategories); $id = $parentId == null ? 2 : ($parentId == $childParentId ? $parentId : $childParentId); $cat = $this->categoryFactory->create()->load($id); foreach ($cat->getChildrenCategories() as $category) { if (isset($facetLabels[$category->getName()])) { $facetValues[] = $facetLabels[$category->getName()]; } } } if ($facetValues == null) { $facetValues = $this->bxFacets->getCategories(); } foreach ($facetValues as $facetValue) { $id = $this->bxFacets->getFacetValueParameterValue($this->fieldName, $facetValue); if ($sortOrder == 2 || $this->categoryHelper->canShow($this->categoryFactory->create()->load($id))) { $this->itemDataBuilder->addItemData($this->tagFilter->filter($this->bxFacets->getFacetValueLabel($this->fieldName, $facetValue)), $id, $this->bxFacets->getFacetValueCount($this->fieldName, $facetValue), false, $value ? 'children' : 'home'); } } } return $this->itemDataBuilder->build(); }
/** * Retrieve Visitor/Customer Last Viewed URL * * @return string */ public function getLastViewedUrl() { $productId = $this->_catalogSession->getLastViewedProductId(); if ($productId) { $product = $this->_productFactory->create()->load($productId); /* @var $product \Magento\Catalog\Model\Product */ if ($this->_catalogProduct->canShow($product, 'catalog')) { return $product->getProductUrl(); } } $categoryId = $this->_catalogSession->getLastViewedCategoryId(); if ($categoryId) { $category = $this->_categoryFactory->create()->load($categoryId); /* @var $category \Magento\Catalog\Model\Category */ if (!$this->_catalogCategory->canShow($category)) { return ''; } return $category->getCategoryUrl(); } return ''; }