public function testGetFacetNames() { $facetGroup = new FacetGroup(123, 'FacetGroup'); $this->assertEquals('', $facetGroup->getFacetNames()); $facetGroup->addFacet(new Facet(456, 'Foo', 'foo', 123, 'FacetGroup')); $this->assertEquals('Foo', $facetGroup->getFacetNames()); $this->assertEquals('Foo', $facetGroup->getFacetNames(',')); $facetGroup->addFacet(new Facet(789, 'Bar', 'bar', 123, 'FacetGroup')); $this->assertEquals('Foo/Bar', $facetGroup->getFacetNames()); $this->assertEquals('Foo,Bar', $facetGroup->getFacetNames(',')); }
public function testFilterByVarientFacets() { $criteria = ProductSearchCriteria::create('12345')->filterByFacetIds(array(0 => array(264))); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"0":[264]}}}', json_encode($criteria->toArray())); $criteria->filterByFacetIds(array(2 => array(123))); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"2":[123]}}}', json_encode($criteria->toArray())); $criteria->filterByFacetIds(array(2 => array(456)), true); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"2":[123,456]}}}', json_encode($criteria->toArray())); $criteria->filterByFacetIds(array(1 => array(123)), true); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"2":[123,456],"1":[123]}}}', json_encode($criteria->toArray())); $criteria->filterByFacetIds(array(2 => array(789, 123)), true); $criteria->filterByFacetIds(array(2 => array(789)), true); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"2":[123,456,789],"1":[123]}}}', json_encode($criteria->toArray())); $criteria = ProductSearchCriteria::create('12345')->filterByFacetGroupSet(new FacetGroupSet(array(0 => array(264)))); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"0":[264]}}}', json_encode($criteria->toArray())); $criteria->filterByFacetGroupSet(new FacetGroupSet(array(0 => array(123))), true); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"0":[264,123]}}}', json_encode($criteria->toArray())); $facetGroup = new FacetGroup(0, 'brand'); $facetGroup->addFacet(new Facet(264, 'TOM', null, 0, 'brand')); $criteria = ProductSearchCriteria::create('12345')->filterByFacetGroup($facetGroup); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"0":[264]}}}', json_encode($criteria->toArray())); $facetGroup2 = new FacetGroup(0, 'brand'); $facetGroup2->addFacet(new Facet(123, 'FOO', null, 0, 'brand')); $criteria->filterByFacetGroup($facetGroup2, true); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"0":[264,123]}}}', json_encode($criteria->toArray())); $criteria->filterByFacetIds(array(2 => array(456)), true); $this->assertEquals('{"session_id":"12345","filter":{"facets":{"0":[264,123],"2":[456]}}}', json_encode($criteria->toArray())); }
protected function fetch() { if (true === empty($this->facets)) { //pre-heat cache $groups = self::$facetManager->getFacetsByGroups($this->getGroupIds()); foreach ($this->ids as $groupId => $facetIds) { $facets = []; foreach ($facetIds as $facetId) { $uniqueKey = $groupId . ':' . $facetId; if (false === empty($groups)) { $facet = isset($groups[$uniqueKey]) ? $groups[$uniqueKey] : null; } else { $facet = self::$facetManager->getFacet($groupId, $facetId); } if ($facet) { $facets[$facetId] = $facet; $this->facets[$uniqueKey] = $facet; } } if (false === empty($facets)) { $facet = reset($facets); $facetGroup = new FacetGroup($groupId, $facet->getGroupName()); $facetGroup->setFacets($facets); $this->groups[$groupId] = $facetGroup; } } } }
/** * @param FacetGroup $facetGroup * @param boolean $append, if true the category ids will added to current filter * * @return ProductSearchCriteria */ public function filterByFacetGroup(FacetGroup $facetGroup, $append = false) { return $this->filterByFacetIds($facetGroup->getIds(), $append); }