Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get latest develop changes #93

Merged
merged 4 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/RegistryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Request/CategoryRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions src/Response/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +33,9 @@ class Category extends Entity
/** @var CategoryDetails[] */
private array $details = [];

/** @var Tag[] */
private array $tags = [];

/**
* @throws Exception
*/
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -116,4 +146,12 @@ public function getDetails(): array
{
return $this->details;
}

/**
* @return Tag[]
*/
public function getTags(): array
{
return $this->tags;
}
}
2 changes: 1 addition & 1 deletion tests/Request/CategoryRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading