diff --git a/src/RegistryService.php b/src/RegistryService.php index 80d949f..1891afa 100644 --- a/src/RegistryService.php +++ b/src/RegistryService.php @@ -375,7 +375,9 @@ protected function fetchCategories(): void ]); foreach ($categoriesMatchingCriteria as $category) { - $this->set('category_' . $category->getId(), $category); + if (!$category->hasExportExclusionTag($this->config->getLanguage())) { + $this->set('category_' . $category->getId(), $category); + } } } } diff --git a/src/Request/CategoryRequest.php b/src/Request/CategoryRequest.php index 4367659..98c58ba 100644 --- a/src/Request/CategoryRequest.php +++ b/src/Request/CategoryRequest.php @@ -15,7 +15,7 @@ public function __construct(int $storeIdentifier) 'categories', [ 'type' => 'item', - 'with' => ['details'], + 'with' => ['details', 'tags'], 'plentyId' => $storeIdentifier, 'page' => $this->page, 'itemsPerPage' => $this->itemsPerPage diff --git a/src/Response/Entity/Category.php b/src/Response/Entity/Category.php index 03fc0e1..d04ab99 100644 --- a/src/Response/Entity/Category.php +++ b/src/Response/Entity/Category.php @@ -6,9 +6,14 @@ use Exception; use FINDOLOGIC\PlentyMarketsRestExporter\Response\Entity\Category\CategoryDetails; +use FINDOLOGIC\PlentyMarketsRestExporter\Response\Entity\Pim\Property\Tag; +use FINDOLOGIC\PlentyMarketsRestExporter\Response\Entity\Pim\Property\TagName; +use FINDOLOGIC\PlentyMarketsRestExporter\Translator; class Category extends Entity { + public const EXCLUSION_TAG_NAME = 'findologic-exclude'; + private int $id; private ?int $parentCategoryId; @@ -28,6 +33,9 @@ class Category extends Entity /** @var CategoryDetails[] */ private array $details = []; + /** @var Tag[] */ + private array $tags = []; + /** * @throws Exception */ @@ -47,6 +55,12 @@ public function __construct(array $data) $this->details[] = new CategoryDetails($categoryDetails); } } + + if (!empty($data['tagRelationship'])) { + foreach ($data['tagRelationship'] as $tag) { + $this->tags[] = new Tag($tag); + } + } } public function getData(): array @@ -69,6 +83,22 @@ public function getData(): array ]; } + public function hasExportExclusionTag(string $lang): bool + { + foreach ($this->getTags() as $tag) { + /** @var TagName[] $names */ + $names = Translator::translateMultiple($tag->getTagData()->getNames(), $lang); + + foreach ($names as $name) { + if (strtolower($name->getName()) === self::EXCLUSION_TAG_NAME) { + return true; + } + } + } + + return false; + } + public function getId(): int { return $this->id; @@ -116,4 +146,12 @@ public function getDetails(): array { return $this->details; } + + /** + * @return Tag[] + */ + public function getTags(): array + { + return $this->tags; + } } diff --git a/tests/Request/CategoryRequestTest.php b/tests/Request/CategoryRequestTest.php index 5ef2f61..f164fcf 100644 --- a/tests/Request/CategoryRequestTest.php +++ b/tests/Request/CategoryRequestTest.php @@ -21,7 +21,7 @@ public function testIterableRequestParamsAreSetProperly(): void $this->assertSame([ 'type' => 'item', // Set by default. - 'with' => ['details'], // Set by default. + 'with' => ['details', 'tags'], // Set by default. 'plentyId' => $expectedStoreIdentifier, 'page' => $expectedPage, 'itemsPerPage' => $expectedItemsPerPage,