Skip to content

Commit

Permalink
Add position mapping for all taxons
Browse files Browse the repository at this point in the history
  • Loading branch information
bitbager committed Sep 21, 2019
1 parent 154e988 commit 8e1d784
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ function it_retrieves_data(
{
$taxonContext->getTaxon()->willReturn($taxon);
$taxon->getCode()->willReturn('t_shirt');
$taxonPositionNameResolver->resolvePropertyName('t_shirt')->willReturn('t_shirt_position');
$taxonPositionNameResolver->resolvePropertyName('t_shirt')->willReturn('taxon_position_t_shirts');

$this->retrieveData([])->shouldBeEqualTo([
'sort' => [
't_shirt_position' => [
'taxon_position_t_shirts' => [
'order' => SortDataHandlerInterface::SORT_DESC_INDEX,
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use FOS\ElasticaBundle\Event\TransformEvent;
use Sylius\Component\Core\Model\ProductInterface;

final class ProductMainTaxonPositionPropertyBuilder extends AbstractBuilder
final class ProductTaxonPositionPropertyBuilder extends AbstractBuilder
{
/** @var ConcatedNameResolverInterface */
private $taxonPositionNameResolver;
Expand All @@ -21,16 +21,12 @@ public function consumeEvent(TransformEvent $event): void
{
$this->buildProperty($event, ProductInterface::class,
function (ProductInterface $product, Document $document): void {
$mainTaxon = $product->getMainTaxon();

if (null === $mainTaxon) {
return;
foreach ($product->getTaxons() as $taxon) {
$document->set(
$this->taxonPositionNameResolver->resolvePropertyName($taxon->getCode()),
$taxon->getPosition()
);
}

$document->set(
$this->taxonPositionNameResolver->resolvePropertyName($mainTaxon->getCode()),
$mainTaxon->getPosition()
);
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/config/services/property_builder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<tag name="kernel.event_subscriber" />
</service>

<service id="bitbag_sylius_elasticsearch_plugin.property_builder.main_taxon_position" class="BitBag\SyliusElasticsearchPlugin\PropertyBuilder\ProductMainTaxonPositionPropertyBuilder">
<service id="bitbag_sylius_elasticsearch_plugin.property_builder.main_taxon_position" class="BitBag\SyliusElasticsearchPlugin\PropertyBuilder\ProductTaxonPositionPropertyBuilder">
<argument type="service" id="bitbag_sylius_elasticsearch_plugin.property_name_resolver.taxon_position" />
<tag name="kernel.event_subscriber" />
</service>
Expand Down

0 comments on commit 8e1d784

Please sign in to comment.