getPriceField example

/** * {@inheritdoc} */
    public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $aggregation = new StatsAggregation('price');
        $field = $this->priceFieldMapper->getPriceField($criteria$context);
        $aggregation->setField($field);
        $search->addAggregation($aggregation);
    }

    /** * {@inheritdoc} */
    public function hydrate(
        array $elasticResult,
        ProductNumberSearchResult $result,
        Criteria $criteria,
        
private function getQuery(PriceCondition $criteriaPart, Criteria $criteria, ShopContextInterface $context): RangeQuery
    {
        $range = [];
        if ($criteriaPart->getMinPrice()) {
            $range['gte'] = $criteriaPart->getMinPrice();
        }
        if ($criteriaPart->getMaxPrice()) {
            $range['lte'] = $criteriaPart->getMaxPrice();
        }

        return new RangeQuery($this->mapper->getPriceField($criteria$context)$range);
    }
}
public function handle(
        CriteriaPartInterface $criteriaPart,
        Criteria $criteria,
        Search $search,
        ShopContextInterface $context
    ) {
        $search->addSort($this->getSorting($criteriaPart$criteria$context));
    }

    private function getSorting(PriceSorting $criteriaPart, Criteria $criteria, ShopContextInterface $context): FieldSort
    {
        $field = $this->mapper->getPriceField($criteria$context);

        return new FieldSort($fieldstrtolower($criteriaPart->getDirection())['unmapped_type' => 'double']);
    }
}
Home | Imprint | This part of the site doesn't use cookies.