Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
feat(Filter): add method to create a subtree filter with an array of IDs
Browse files Browse the repository at this point in the history
Closes #257
  • Loading branch information
Jens Schulze committed Sep 30, 2016
1 parent 2d1c557 commit ac487a3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Model/Product/Search/FilterSubtreeCollection.php
Expand Up @@ -6,6 +6,7 @@
namespace Commercetools\Core\Model\Product\Search;

use Commercetools\Core\Model\Common\Collection;
use Commercetools\Core\Model\Common\Context;

/**
* @package Commercetools\Core\Model\Product\Search
Expand All @@ -26,4 +27,20 @@ public function __toString()
}
return implode(',', $values);
}

/**
* @param array $ids
* @param Context|null $context
* @return FilterSubtreeCollection
*/
public static function ofIds(array $ids, Context $context = null)
{
$collection = static::of($context);

foreach ($ids as $id) {
$collection->add(FilterSubtree::ofId($id));
}

return $collection;
}
}
6 changes: 6 additions & 0 deletions tests/unit/Model/Product/Search/FilterSubtreeTest.php
Expand Up @@ -23,6 +23,12 @@ public function testDefaultType()
$this->assertSame('subtree("12345"),subtree("abcde")', (string)$subtrees);
}

public function testCollectionIds()
{
$subtrees = FilterSubtreeCollection::ofIds(['12345', 'abcde']);
$this->assertSame('subtree("12345"),subtree("abcde")', (string)$subtrees);
}

public function testIntValue()
{
$subtree = FilterSubtree::ofId(12345);
Expand Down

0 comments on commit ac487a3

Please sign in to comment.