This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #268 from DivanteLtd/hotfix/export-category-attrib…
…utes Fix excluding attributes from category.
- Loading branch information
Showing
6 changed files
with
159 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/module-vsbridge-indexer-catalog/Model/Attributes/CategoryAttributes.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Divante\VsbridgeIndexerCatalog\Model\Attributes; | ||
|
||
use Divante\VsbridgeIndexerCatalog\Model\SystemConfig\CategoryConfigInterface; | ||
|
||
/** | ||
* Class CategoryAttributes | ||
*/ | ||
class CategoryAttributes | ||
{ | ||
/** | ||
* @const | ||
*/ | ||
const MINIMAL_ATTRIBUTE_SET = [ | ||
'name', | ||
'is_active', | ||
'url_path', | ||
'url_key', | ||
]; | ||
|
||
/** | ||
* @var CategoryConfigInterface | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* CategoryChildAttributes constructor. | ||
* | ||
* @param CategoryConfigInterface $categoryConfig | ||
*/ | ||
public function __construct(CategoryConfigInterface $categoryConfig) | ||
{ | ||
$this->config = $categoryConfig; | ||
} | ||
|
||
/** | ||
* Retrieve required attributes for category | ||
* | ||
* @param int $storeId | ||
* | ||
* @return array | ||
*/ | ||
public function getRequiredAttributes(int $storeId) | ||
{ | ||
$attributes = $this->config->getAllowedAttributesToIndex($storeId); | ||
|
||
if (!empty($attributes)) { | ||
$attributes = array_merge($attributes, self::MINIMAL_ATTRIBUTE_SET); | ||
|
||
return array_unique($attributes); | ||
} | ||
|
||
return $attributes; | ||
} | ||
|
||
/** | ||
* @param int $storeId | ||
* | ||
* @return bool | ||
*/ | ||
public function canAddAvailableSortBy(int $storeId): bool | ||
{ | ||
return $this->isAttributeAllowed('available_sort_by', $storeId); | ||
} | ||
|
||
/** | ||
* @param int $storeId | ||
* | ||
* @return bool | ||
*/ | ||
public function canAddDefaultSortBy(int $storeId): bool | ||
{ | ||
return $this->isAttributeAllowed('default_sort_by', $storeId); | ||
} | ||
|
||
/** | ||
* @param string $attributeCode | ||
* @param int $storeId | ||
* | ||
* @return bool | ||
*/ | ||
private function isAttributeAllowed(string $attributeCode, int $storeId): bool | ||
{ | ||
$allowedAttributes = $this->getRequiredAttributes($storeId); | ||
|
||
return empty($allowedAttributes) || in_array($attributeCode, $allowedAttributes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters