repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 7 values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/PropertyBuilder/ProductCodeBuilder.php | src/PropertyBuilder/ProductCodeBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\PropertyBuilder;
use Elastica\Document;
use FOS\ElasticaBundle\Event\PostTransformEvent;
use Sylius\Component\Core\Model\ProductInterface;
final class ProductCodeBuilder extends AbstractBuilder
{
public const PROPERTY_NAME = 'code';
public function consumeEvent(PostTransformEvent $event): void
{
$this->buildProperty(
$event,
ProductInterface::class,
function (ProductInterface $product, Document $document): void {
$document->set(self::PROPERTY_NAME, $product->getCode());
}
);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/PropertyBuilder/Mapper/ProductTaxonsMapper.php | src/PropertyBuilder/Mapper/ProductTaxonsMapper.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\PropertyBuilder\Mapper;
use Sylius\Component\Core\Model\ProductInterface;
final class ProductTaxonsMapper implements ProductTaxonsMapperInterface
{
public function __construct(
private bool $includeAllDescendants
) {
}
public function mapToUniqueCodes(ProductInterface $product): array
{
$taxons = [];
foreach ($product->getTaxons() as $taxon) {
$taxons[] = $taxon->getCode();
if (true === $this->includeAllDescendants) {
foreach ($taxon->getAncestors() as $ancestor) {
$taxons[] = $ancestor->getCode();
}
}
}
return array_values(array_unique($taxons));
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/PropertyBuilder/Mapper/ProductTaxonsMapperInterface.php | src/PropertyBuilder/Mapper/ProductTaxonsMapperInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\PropertyBuilder\Mapper;
use Sylius\Component\Core\Model\ProductInterface;
interface ProductTaxonsMapperInterface
{
public function mapToUniqueCodes(ProductInterface $product): array;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Exception/TaxonNotFoundException.php | src/Exception/TaxonNotFoundException.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Exception;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
final class TaxonNotFoundException extends NotFoundHttpException
{
public function __construct()
{
parent::__construct('Taxon has not been found!');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/IsEnabledQueryBuilder.php | src/QueryBuilder/IsEnabledQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
use Elastica\Query\Term;
final class IsEnabledQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private string $enabledProperty
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
$enabledQuery = new Term();
$enabledQuery->setTerm($this->enabledProperty, true);
return $enabledQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/ProductsByPartialNameQueryBuilder.php | src/QueryBuilder/ProductsByPartialNameQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
use Elastica\Query\BoolQuery;
final class ProductsByPartialNameQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private QueryBuilderInterface $containsNameQueryBuilder
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
$boolQuery = new BoolQuery();
$nameQuery = $this->containsNameQueryBuilder->buildQuery($data);
if (null !== $nameQuery) {
$boolQuery->addFilter($nameQuery);
}
return $boolQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/HasPriceBetweenQueryBuilder.php | src/QueryBuilder/HasPriceBetweenQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\PriceNameResolverInterface;
use Elastica\Query\AbstractQuery;
use Elastica\Query\Range;
use NumberFormatter;
use Sylius\Bundle\MoneyBundle\Form\DataTransformer\SyliusMoneyTransformer;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Currency\Context\CurrencyContextInterface;
use Sylius\Component\Currency\Converter\CurrencyConverterInterface;
use Webmozart\Assert\Assert;
final class HasPriceBetweenQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private PriceNameResolverInterface $priceNameResolver,
private ConcatedNameResolverInterface $channelPricingNameResolver,
private ChannelContextInterface $channelContext,
private CurrencyContextInterface $currencyContext,
private CurrencyConverterInterface $currencyConverter
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
$dataMinPrice = $this->getDataByKey($data, $this->priceNameResolver->resolveMinPriceName());
$dataMaxPrice = $this->getDataByKey($data, $this->priceNameResolver->resolveMaxPriceName());
// PHPStan is not right here: Only booleans are allowed in a ternary operator condition, string|null given
// When we change the functionality, it breaks search filtering on empty price fields value
/** @phpstan-ignore-next-line */
$minPrice = $dataMinPrice ? $this->resolveBasePrice($dataMinPrice) : null;
/** @phpstan-ignore-next-line */
$maxPrice = $dataMaxPrice ? $this->resolveBasePrice($dataMaxPrice) : null;
/** @var string $channelCode */
$channelCode = $this->channelContext->getChannel()->getCode();
$propertyName = $this->channelPricingNameResolver->resolvePropertyName($channelCode);
$rangeQuery = new Range();
$paramValue = $this->getQueryParamValue($minPrice, $maxPrice);
if (null === $paramValue) {
return null;
}
$rangeQuery->setParam($propertyName, $paramValue);
return $rangeQuery;
}
private function resolveBasePrice(string $price): int
{
$price = $this->convertFromString($price);
/** @var ChannelInterface $channel */
$channel = $this->channelContext->getChannel();
$channelBaseCurrency = $channel->getBaseCurrency();
Assert::notNull($channelBaseCurrency);
$currentCurrencyCode = $this->currencyContext->getCurrencyCode();
/** @var string $channelBaseCurrencyCode */
$channelBaseCurrencyCode = $channelBaseCurrency->getCode();
if ($currentCurrencyCode !== $channelBaseCurrencyCode) {
$price = $this->currencyConverter->convert($price, $currentCurrencyCode, $channelBaseCurrencyCode);
}
return $price;
}
private function convertFromString(string $price): int
{
if (!is_numeric(str_replace(',', '.', $price))) {
return 0;
}
$transformer = new SyliusMoneyTransformer(2, false, NumberFormatter::ROUND_HALFUP, 100);
/** @var int $convertedPrice */
$convertedPrice = $transformer->reverseTransform($price);
return $convertedPrice;
}
private function getDataByKey(array $data, ?string $key = null): ?string
{
return $data[$key] ?? null;
}
private function getQueryParamValue(?int $min, ?int $max): ?array
{
$paramValue = null;
foreach (['gte' => $min, 'lte' => $max] as $key => $value) {
if (null !== $value) {
$paramValue[$key] = $value;
}
}
return $paramValue ?? null;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/SiteWideProductsQueryBuilder.php | src/QueryBuilder/SiteWideProductsQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
use Elastica\Query\BoolQuery;
use Webmozart\Assert\Assert;
final class SiteWideProductsQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private QueryBuilderInterface $isEnabledQueryBuilder,
private QueryBuilderInterface $hasChannelQueryBuilder,
private QueryBuilderInterface $containsNameQueryBuilder
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
$boolQuery = new BoolQuery();
$isEnabledQuery = $this->isEnabledQueryBuilder->buildQuery([]);
$hasChannelQuery = $this->hasChannelQueryBuilder->buildQuery([]);
Assert::notNull($isEnabledQuery);
Assert::notNull($hasChannelQuery);
$boolQuery->addMust($isEnabledQuery);
$boolQuery->addMust($hasChannelQuery);
$nameQuery = $this->containsNameQueryBuilder->buildQuery($data);
$this->addMustIfNotNull($nameQuery, $boolQuery);
return $boolQuery;
}
private function addMustIfNotNull(?AbstractQuery $query, BoolQuery $boolQuery): void
{
if (null !== $query) {
$boolQuery->addMust($query);
}
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/QueryBuilderInterface.php | src/QueryBuilder/QueryBuilderInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
interface QueryBuilderInterface
{
public function buildQuery(array $data): ?AbstractQuery;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/HasAttributesQueryBuilder.php | src/QueryBuilder/HasAttributesQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\AttributesQueryBuilder\AttributesQueryBuilderCollectorInterface;
use BitBag\SyliusElasticsearchPlugin\Repository\ProductAttributeRepositoryInterface;
use Elastica\Query\AbstractQuery;
use Sylius\Component\Locale\Context\LocaleContextInterface;
final class HasAttributesQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private LocaleContextInterface $localeContext,
private ProductAttributeRepositoryInterface $productAttributeRepository,
/** @var AttributesQueryBuilderCollectorInterface[] */
private iterable $attributeDriver
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
$attributeName = str_replace('attribute_', '', $data['attribute']);
$type = $this->productAttributeRepository->getAttributeTypeByName($attributeName);
foreach ($this->attributeDriver as $driver) {
if ($driver->supports($type)) {
return $driver->buildQuery($data, $this->localeContext->getLocaleCode());
}
}
return null;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/HasChannelQueryBuilder.php | src/QueryBuilder/HasChannelQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
use Elastica\Query\Terms;
use Sylius\Component\Channel\Context\ChannelContextInterface;
final class HasChannelQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private ChannelContextInterface $channelContext,
private string $channelsProperty
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
$channelQuery = new Terms(sprintf('%s.keyword', $this->channelsProperty));
/** @var string $channelCode */
$channelCode = $this->channelContext->getChannel()->getCode();
$channelQuery->setTerms([$channelCode]);
return $channelQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/HasTaxonQueryBuilder.php | src/QueryBuilder/HasTaxonQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
use Elastica\Query\Terms;
final class HasTaxonQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private string $taxonsProperty
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
if (!$taxonCode = $data[$this->taxonsProperty]) {
return null;
}
$taxonQuery = new Terms($this->taxonsProperty);
$taxonQuery->setTerms([$taxonCode]);
return $taxonQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/TaxonProductsQueryBuilder.php | src/QueryBuilder/TaxonProductsQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
use Elastica\Query\BoolQuery;
use Webmozart\Assert\Assert;
final class TaxonProductsQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private QueryBuilderInterface $isEnabledQueryBuilder,
private QueryBuilderInterface $hasChannelQueryBuilder,
private QueryBuilderInterface $containsNameQueryBuilder,
private QueryBuilderInterface $hasTaxonQueryBuilder,
private QueryBuilderInterface $hasOptionsQueryBuilder,
private QueryBuilderInterface $hasAttributesQueryBuilder,
private QueryBuilderInterface $hasPriceBetweenQueryBuilder,
private string $optionPropertyPrefix,
private string $attributePropertyPrefix
) {
}
public function buildQuery(array $data): AbstractQuery
{
$boolQuery = new BoolQuery();
$isEnabledQuery = $this->isEnabledQueryBuilder->buildQuery($data);
$hasChannelQuery = $this->hasChannelQueryBuilder->buildQuery($data);
Assert::notNull($isEnabledQuery);
Assert::notNull($hasChannelQuery);
$boolQuery->addMust($isEnabledQuery);
$boolQuery->addMust($hasChannelQuery);
$nameQuery = $this->containsNameQueryBuilder->buildQuery($data);
$this->addMustIfNotNull($nameQuery, $boolQuery);
$taxonQuery = $this->hasTaxonQueryBuilder->buildQuery($data);
$this->addMustIfNotNull($taxonQuery, $boolQuery);
$priceQuery = $this->hasPriceBetweenQueryBuilder->buildQuery($data);
$this->addMustIfNotNull($priceQuery, $boolQuery);
$this->resolveOptionQuery($boolQuery, $data);
$this->resolveAttributeQuery($boolQuery, $data);
return $boolQuery;
}
private function resolveOptionQuery(BoolQuery $boolQuery, array $data): void
{
foreach ($data as $key => $value) {
if (0 === strpos($key, $this->optionPropertyPrefix) && 0 < count($value)) {
$optionQuery = $this->hasOptionsQueryBuilder->buildQuery(['option' => $key, 'option_values' => $value]);
if (null !== $optionQuery) {
$boolQuery->addMust($optionQuery);
}
}
}
}
private function resolveAttributeQuery(BoolQuery $boolQuery, array $data): void
{
foreach ($data as $key => $value) {
if (0 === strpos($key, $this->attributePropertyPrefix) && 0 < count($value)) {
$optionQuery = $this->hasAttributesQueryBuilder->buildQuery(['attribute' => $key, 'attribute_values' => $value]);
if (null !== $optionQuery) {
$boolQuery->addMust($optionQuery);
}
}
}
}
private function addMustIfNotNull(?AbstractQuery $query, BoolQuery $boolQuery): void
{
if (null !== $query) {
$boolQuery->addMust($query);
}
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/ContainsNameQueryBuilder.php | src/QueryBuilder/ContainsNameQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\SearchPropertyNameResolverRegistryInterface;
use Elastica\Query\AbstractQuery;
use Elastica\Query\MultiMatch;
use Sylius\Component\Locale\Context\LocaleContextInterface;
final class ContainsNameQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private LocaleContextInterface $localeContext,
private SearchPropertyNameResolverRegistryInterface $searchProperyNameResolverRegistry,
private string $fuzziness = 'AUTO'
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
$localeCode = $this->localeContext->getLocaleCode();
$query = $data['name'] ?? $data['query'] ?? null;
if (null === $query || '' === $query) {
return null;
}
$fields = [];
foreach ($this->searchProperyNameResolverRegistry->getPropertyNameResolvers() as $propertyNameResolver) {
$fields[] = $propertyNameResolver->resolvePropertyName($localeCode);
}
$multiMatch = new MultiMatch();
$multiMatch->setQuery($query);
$multiMatch->setFuzziness($this->fuzziness);
$multiMatch->setFields($fields);
return $multiMatch;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/ProductOptionsByTaxonQueryBuilder.php | src/QueryBuilder/ProductOptionsByTaxonQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
use Elastica\Query\BoolQuery;
use Webmozart\Assert\Assert;
final class ProductOptionsByTaxonQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private QueryBuilderInterface $hasTaxonQueryBuilder
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
$boolQuery = new BoolQuery();
$taxonQuery = $this->hasTaxonQueryBuilder->buildQuery($data);
Assert::notNull($taxonQuery);
$boolQuery->addMust($taxonQuery);
return $boolQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/ProductAttributesByTaxonQueryBuilder.php | src/QueryBuilder/ProductAttributesByTaxonQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
use Elastica\Query\BoolQuery;
use Webmozart\Assert\Assert;
final class ProductAttributesByTaxonQueryBuilder implements QueryBuilderInterface
{
public function __construct(
private QueryBuilderInterface $hasTaxonQueryBuilder
) {
}
public function buildQuery(array $data): ?AbstractQuery
{
$boolQuery = new BoolQuery();
$taxonQuery = $this->hasTaxonQueryBuilder->buildQuery($data);
Assert::notNull($taxonQuery);
$boolQuery->addMust($taxonQuery);
return $boolQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/HasOptionsQueryBuilder.php | src/QueryBuilder/HasOptionsQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder;
use Elastica\Query\AbstractQuery;
use Elastica\Query\BoolQuery;
use Elastica\Query\Term;
final class HasOptionsQueryBuilder implements QueryBuilderInterface
{
public function buildQuery(array $data): ?AbstractQuery
{
$optionQuery = new BoolQuery();
foreach ((array) $data['option_values'] as $optionValue) {
$termQuery = new Term();
$termQuery->setTerm($data['option'], $optionValue);
$optionQuery->addShould($termQuery);
}
return $optionQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/FormQueryBuilder/TaxonFacetsQueryBuilderInterface.php | src/QueryBuilder/FormQueryBuilder/TaxonFacetsQueryBuilderInterface.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder\FormQueryBuilder;
use Elastica\Query;
use Symfony\Component\Form\FormEvent;
interface TaxonFacetsQueryBuilderInterface
{
public function getQuery(FormEvent $event, string $namePropertyPrefix): Query;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/FormQueryBuilder/SiteWideFacetsQueryBuilderInterface.php | src/QueryBuilder/FormQueryBuilder/SiteWideFacetsQueryBuilderInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder\FormQueryBuilder;
use Elastica\Query;
use Symfony\Component\Form\FormEvent;
interface SiteWideFacetsQueryBuilderInterface
{
public function getQuery(FormEvent $event): Query;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/FormQueryBuilder/SiteWideFacetsQueryBuilder.php | src/QueryBuilder/FormQueryBuilder/SiteWideFacetsQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder\FormQueryBuilder;
use BitBag\SyliusElasticsearchPlugin\Facet\RegistryInterface;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
use Elastica\Query;
use Symfony\Component\Form\FormEvent;
final class SiteWideFacetsQueryBuilder implements SiteWideFacetsQueryBuilderInterface
{
public function __construct(
private QueryBuilderInterface $queryBuilder,
private RegistryInterface $facetRegistry,
) {
}
public function getQuery(FormEvent $event): Query
{
/** @var array $data */
$data = $event->getData();
/** @var Query\BoolQuery $boolQuery */
$boolQuery = $this->queryBuilder->buildQuery([
'query' => $data['query'] ?? '',
]);
foreach ($data['facets'] ?? [] as $facetId => $selectedBuckets) {
if (!$selectedBuckets) {
continue;
}
$facet = $this->facetRegistry->getFacetById((string) $facetId);
$boolQuery->addFilter($facet->getQuery($selectedBuckets));
}
return new Query($boolQuery);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/FormQueryBuilder/TaxonFacetsQueryBuilder.php | src/QueryBuilder/FormQueryBuilder/TaxonFacetsQueryBuilder.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder\FormQueryBuilder;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\DataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\Facet\RegistryInterface;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
use Elastica\Query;
use Symfony\Component\Form\FormEvent;
final class TaxonFacetsQueryBuilder implements TaxonFacetsQueryBuilderInterface
{
public function __construct(
private DataHandlerInterface $shopProductListDataHandler,
private QueryBuilderInterface $searchProductsQueryBuilder,
private RegistryInterface $facetRegistry
) {
}
public function getQuery(FormEvent $event, string $namePropertyPrefix): Query
{
$eventData = $event->getData();
if (!isset($eventData[$namePropertyPrefix])) {
$eventData[$namePropertyPrefix] = '';
}
$data = $this->shopProductListDataHandler->retrieveData($eventData);
/** @var Query\BoolQuery $boolQuery */
$boolQuery = $this->searchProductsQueryBuilder->buildQuery($data);
foreach ($data['facets'] ?? [] as $facetId => $selectedBuckets) {
if (!$selectedBuckets) {
continue;
}
$facet = $this->facetRegistry->getFacetById((string) $facetId);
$boolQuery->addFilter($facet->getQuery($selectedBuckets));
}
return new Query($boolQuery);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/AttributesQueryBuilder/AttributesTypeNumberQueryBuilder.php | src/QueryBuilder/AttributesQueryBuilder/AttributesTypeNumberQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder\AttributesQueryBuilder;
use Elastica\Query\BoolQuery;
use Elastica\Query\Term;
use function sprintf;
class AttributesTypeNumberQueryBuilder implements AttributesQueryBuilderCollectorInterface
{
private const AVAILABLE_ATTRIBUTES_TYPE = [
'percent',
'integer',
'checkbox',
];
public function supports(string $type): bool
{
return in_array($type, self::AVAILABLE_ATTRIBUTES_TYPE, true);
}
public function buildQuery(array $data, string $localCode): BoolQuery
{
$attributeQuery = new BoolQuery();
foreach ((array) $data['attribute_values'] as $attributeValue) {
$termQuery = new Term();
$attribute = sprintf('%s_%s', $data['attribute'], $localCode);
$termQuery->setTerm($attribute, $attributeValue);
$attributeQuery->addShould($termQuery);
}
return $attributeQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/AttributesQueryBuilder/AttributesTypeDateQueryBuilder.php | src/QueryBuilder/AttributesQueryBuilder/AttributesTypeDateQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder\AttributesQueryBuilder;
use Elastica\Query\BoolQuery;
use Elastica\Query\Term;
use function sprintf;
class AttributesTypeDateQueryBuilder implements AttributesQueryBuilderCollectorInterface
{
private const AVAILABLE_ATTRIBUTES_TYPE = [
'date',
'datetime',
];
public function supports(string $type): bool
{
return in_array($type, self::AVAILABLE_ATTRIBUTES_TYPE, true);
}
public function buildQuery(array $data, string $localCode): BoolQuery
{
$attributeQuery = new BoolQuery();
foreach ((array) $data['attribute_values'] as $attributeValue) {
$termQuery = new Term();
$attribute = sprintf('%s_%s.date.keyword', $data['attribute'], $localCode);
$termQuery->setTerm($attribute, $attributeValue);
$attributeQuery->addShould($termQuery);
}
return $attributeQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/AttributesQueryBuilder/AttributesTypeTextQueryBuilder.php | src/QueryBuilder/AttributesQueryBuilder/AttributesTypeTextQueryBuilder.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder\AttributesQueryBuilder;
use Elastica\Query\BoolQuery;
use Elastica\Query\Term;
use function sprintf;
class AttributesTypeTextQueryBuilder implements AttributesQueryBuilderCollectorInterface
{
private const AVAILABLE_ATTRIBUTES_TYPE = [
'select',
'textarea',
'text',
];
public function supports(string $type): bool
{
return in_array($type, self::AVAILABLE_ATTRIBUTES_TYPE, true);
}
public function buildQuery(array $data, string $localCode): BoolQuery
{
$attributeQuery = new BoolQuery();
foreach ((array) $data['attribute_values'] as $attributeValue) {
$termQuery = new Term();
$attribute = sprintf('%s_%s.keyword', $data['attribute'], $localCode);
$termQuery->setTerm($attribute, $attributeValue);
$attributeQuery->addShould($termQuery);
}
return $attributeQuery;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/QueryBuilder/AttributesQueryBuilder/AttributesQueryBuilderCollectorInterface.php | src/QueryBuilder/AttributesQueryBuilder/AttributesQueryBuilderCollectorInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\QueryBuilder\AttributesQueryBuilder;
use Elastica\Query\BoolQuery;
interface AttributesQueryBuilderCollectorInterface
{
public function supports(string $type): bool;
public function buildQuery(array $data, string $localCode): BoolQuery;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Api/RequestDataHandler/RequestDataHandler.php | src/Api/RequestDataHandler/RequestDataHandler.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Api\RequestDataHandler;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\DataHandlerInterface;
final class RequestDataHandler implements RequestDataHandlerInterface
{
public function __construct(
private DataHandlerInterface $sortDataHandler,
private DataHandlerInterface $paginationDataHandler,
) {
}
public function retrieveData(array $context): array
{
$requestData = $context['filters'] ?? [];
return array_merge(
$this->sortDataHandler->retrieveData($requestData),
$this->paginationDataHandler->retrieveData($requestData),
['query' => $requestData['query'] ?? ''],
['facets' => $requestData['facets'] ?? []],
);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Api/RequestDataHandler/RequestDataHandlerInterface.php | src/Api/RequestDataHandler/RequestDataHandlerInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Api\RequestDataHandler;
interface RequestDataHandlerInterface
{
public function retrieveData(array $context): array;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Api/OpenApi/Documentation/ProductSearchDocumentationModifier.php | src/Api/OpenApi/Documentation/ProductSearchDocumentationModifier.php | <?php
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Api\OpenApi\Documentation;
use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
use ApiPlatform\OpenApi\Model\Parameter;
use ApiPlatform\OpenApi\OpenApi;
final class ProductSearchDocumentationModifier implements OpenApiFactoryInterface
{
private OpenApiFactoryInterface $decorated;
public function __construct(OpenApiFactoryInterface $decorated)
{
$this->decorated = $decorated;
}
public function __invoke(array $context = []): OpenApi
{
$openApi = $this->decorated->__invoke($context);
$paths = $openApi->getPaths();
$pathItem = $paths->getPath('/api/v2/shop/products/search');
if (null === $pathItem) {
return $openApi;
}
$operation = $pathItem->getGet();
if (null === $operation) {
return $openApi;
}
$parameters = [
new Parameter(
'query',
'query',
'Search query string',
required: false,
deprecated: false,
allowEmptyValue: false,
schema: ['type' => 'string'],
),
new Parameter(
'limit',
'query',
'Number of items per page',
required: false,
deprecated: false,
allowEmptyValue: false,
schema: ['type' => 'integer', 'default' => 10],
),
new Parameter(
'page',
'query',
'Page number',
required: false,
deprecated: false,
allowEmptyValue: false,
schema: ['type' => 'integer', 'default' => 1],
),
new Parameter(
'order_by',
'query',
'Sort field',
required: false,
deprecated: false,
allowEmptyValue: false,
schema: ['type' => 'string', 'enum' => ['sold_units', 'product_created_at', 'price']],
),
new Parameter(
'sort',
'query',
'Sort direction',
required: false,
deprecated: false,
allowEmptyValue: false,
schema: ['type' => 'string', 'enum' => ['asc', 'desc']],
),
new Parameter(
'facets',
'query',
'Filter facets with dynamic keys',
required: false,
deprecated: false,
allowEmptyValue: true,
explode: true,
example: '[jeans_collection][]=sylius_summer_2024',
),
];
$newOperation = $operation->withParameters($parameters);
$paths->addPath('/api/v2/shop/products/search', $pathItem->withGet($newOperation));
return $openApi->withPaths($paths);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Api/DataProvider/ProductCollectionDataProvider.php | src/Api/DataProvider/ProductCollectionDataProvider.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Api\DataProvider;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use BitBag\SyliusElasticsearchPlugin\Api\RequestDataHandler\RequestDataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\Api\Resolver\FacetsResolverInterface;
use BitBag\SyliusElasticsearchPlugin\Finder\ShopProductsFinderInterface;
use Webmozart\Assert\Assert;
final class ProductCollectionDataProvider implements ProviderInterface
{
public function __construct(
private RequestDataHandlerInterface $dataHandler,
private ShopProductsFinderInterface $shopProductsFinder,
private FacetsResolverInterface $facetsResolver
) {
}
public function provide(
Operation $operation,
array $uriVariables = [],
array $context = []
): object|array|null {
Assert::isInstanceOf($operation, GetCollection::class);
$data = $this->dataHandler->retrieveData($context);
$facets = $this->facetsResolver->resolve($data);
$products = $this->shopProductsFinder->find($data);
/** @var array $result */
$result = [
'items' => iterator_to_array($products->getCurrentPageResults()),
'facets' => $facets,
'pagination' => [
'current_page' => $products->getCurrentPage(),
'has_previous_page' => $products->hasPreviousPage(),
'has_next_page' => $products->hasNextPage(),
'per_page' => $products->getMaxPerPage(),
'total_items' => $products->getNbResults(),
'total_pages' => $products->getNbPages(),
],
];
return $result;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Api/Resolver/FacetsResolverInterface.php | src/Api/Resolver/FacetsResolverInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Api\Resolver;
interface FacetsResolverInterface
{
public function resolve(array $data): array;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Api/Resolver/FacetsResolver.php | src/Api/Resolver/FacetsResolver.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Api\Resolver;
use BitBag\SyliusElasticsearchPlugin\Facet\AutoDiscoverRegistryInterface;
use BitBag\SyliusElasticsearchPlugin\Facet\RegistryInterface;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
use Elastica\Query;
use FOS\ElasticaBundle\Finder\PaginatedFinderInterface;
use FOS\ElasticaBundle\Paginator\FantaPaginatorAdapter;
final class FacetsResolver implements FacetsResolverInterface
{
public function __construct(
private AutoDiscoverRegistryInterface $autoDiscoverRegistry,
private QueryBuilderInterface $queryBuilder,
private RegistryInterface $facetRegistry,
private PaginatedFinderInterface $finder,
) {
}
public function resolve(array $data): array
{
$this->autoDiscoverRegistry->autoRegister();
/** @var Query\BoolQuery $boolQuery */
$boolQuery = $this->queryBuilder->buildQuery($data);
$query = new Query($boolQuery);
$query->setSize(0);
foreach ($this->facetRegistry->getFacets() as $facetId => $facet) {
$query->addAggregation($facet->getAggregation()->setName((string) $facetId));
}
foreach ($data['facets'] ?? [] as $facetId => $selectedBuckets) {
if (!$selectedBuckets) {
continue;
}
$facet = $this->facetRegistry->getFacetById((string) $facetId);
$boolQuery->addFilter($facet->getQuery($selectedBuckets));
}
$facets = $this->finder->findPaginated($query);
$adapter = $facets->getAdapter();
if (!$adapter instanceof FantaPaginatorAdapter) {
return [];
}
return array_filter($adapter->getAggregations(), function ($facet) {
return [] !== ($facet['buckets'] ?? []);
});
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Refresher/ResourceRefresher.php | src/Refresher/ResourceRefresher.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Refresher;
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
final class ResourceRefresher implements ResourceRefresherInterface
{
public function refresh(ResourceInterface $resource, ObjectPersisterInterface $objectPersister): void
{
if ($resource->getId()) {
$objectPersister->deleteById($resource->getId());
$objectPersister->replaceOne($resource);
}
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Refresher/ResourceRefresherInterface.php | src/Refresher/ResourceRefresherInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Refresher;
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
interface ResourceRefresherInterface
{
public function refresh(ResourceInterface $resource, ObjectPersisterInterface $objectPersisterId): void;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/ProductAttributeValueRepository.php | src/Repository/ProductAttributeValueRepository.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Doctrine\ORM\EntityRepository;
use Sylius\Component\Attribute\Model\AttributeInterface;
use Sylius\Component\Product\Repository\ProductAttributeValueRepositoryInterface as BaseAttributeValueRepositoryInterface;
use Sylius\Component\Taxonomy\Model\Taxon;
class ProductAttributeValueRepository implements ProductAttributeValueRepositoryInterface
{
public function __construct(
private BaseAttributeValueRepositoryInterface $baseAttributeValueRepository,
private bool $includeAllDescendants
) {
}
public function getUniqueAttributeValues(AttributeInterface $productAttribute, Taxon $taxon): array
{
/** @var EntityRepository $baseAttributeValueRepository */
$baseAttributeValueRepository = $this->baseAttributeValueRepository;
$queryBuilder = $baseAttributeValueRepository->createQueryBuilder('o');
/** @var string|null $storageType */
$storageType = $productAttribute->getStorageType();
$queryBuilder
->join('o.subject', 'p', 'WITH', 'p.enabled = 1')
->join('p.productTaxons', 't', 'WITH', 't.product = p.id')
->select('o.localeCode, o.' . $storageType . ' as value')
->andWhere('t.taxon = :taxon');
if (true === $this->includeAllDescendants) {
$queryBuilder->innerJoin('t.taxon', 'taxon')
->orWhere('taxon.left >= :taxonLeft and taxon.right <= :taxonRight and taxon.root = :taxonRoot')
->setParameter('taxonLeft', $taxon->getLeft())
->setParameter('taxonRight', $taxon->getRight())
->setParameter('taxonRoot', $taxon->getRoot());
}
return $queryBuilder
->andWhere('o.attribute = :attribute')
->groupBy('o.' . $storageType)
->addGroupBy('o.localeCode')
->setParameter('attribute', $productAttribute)
->setParameter('taxon', $taxon->getId())
->getQuery()
->getResult()
;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/ProductAttributeRepositoryInterface.php | src/Repository/ProductAttributeRepositoryInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
interface ProductAttributeRepositoryInterface
{
public function getAttributeTypeByName(string $attributeName): string;
public function findAllWithTranslations(?string $locale): array;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/ProductOptionRepositoryInterface.php | src/Repository/ProductOptionRepositoryInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
interface ProductOptionRepositoryInterface
{
public function findAllWithTranslations(?string $locale): array;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/OrderItemRepository.php | src/Repository/OrderItemRepository.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Doctrine\ORM\EntityRepository;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
class OrderItemRepository implements OrderItemRepositoryInterface
{
public function __construct(
private OrderItemRepositoryInterface|EntityRepository $baseOrderItemRepository
) {
}
public function countByVariant(ProductVariantInterface $variant, array $orderStates = []): int
{
if ([] === $orderStates) {
$orderStates = [OrderInterface::STATE_CANCELLED, OrderInterface::STATE_CART];
}
/** @var EntityRepository $baseOrderItemRepository */
$baseOrderItemRepository = $this->baseOrderItemRepository;
return (int) ($baseOrderItemRepository
->createQueryBuilder('oi')
->select('SUM(oi.quantity)')
->join('oi.order', 'o')
->where('oi.variant = :variant')
->andWhere('o.state NOT IN (:states)')
->setParameter('variant', $variant)
->setParameter('states', $orderStates)
->getQuery()
->getSingleScalarResult());
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/ProductVariantRepositoryInterface.php | src/Repository/ProductVariantRepositoryInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Product\Model\ProductOptionValueInterface;
interface ProductVariantRepositoryInterface
{
public function findOneByOptionValue(ProductOptionValueInterface $productOptionValue): ?ProductVariantInterface;
public function findByOptionValue(ProductOptionValueInterface $productOptionValue): array;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/ProductOptionRepository.php | src/Repository/ProductOptionRepository.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Doctrine\ORM\EntityRepository;
use Sylius\Component\Resource\Repository\RepositoryInterface;
class ProductOptionRepository implements ProductOptionRepositoryInterface
{
public function __construct(
private RepositoryInterface $productOptionRepository
) {
}
public function findAllWithTranslations(?string $locale): array
{
/** @var EntityRepository $queryBuilder */
$queryBuilder = $this->productOptionRepository;
if (null !== $locale) {
$queryBuilder
->createQueryBuilder('o')
->addSelect('translation')
/** @phpstan-ignore-next-line phpstan can't read relationship correctly */
->leftJoin('o.translations', 'translation', 'ot')
->andWhere('translation.locale = :locale')
->setParameter('locale', $locale)
;
}
return $queryBuilder
->createQueryBuilder('o')
->getQuery()
->getResult()
;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/ProductAttributeRepository.php | src/Repository/ProductAttributeRepository.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Doctrine\ORM\EntityRepository;
use Sylius\Component\Resource\Repository\RepositoryInterface;
class ProductAttributeRepository implements ProductAttributeRepositoryInterface
{
public function __construct(
private RepositoryInterface $productAttributeRepository
) {
}
public function getAttributeTypeByName(string $attributeName): string
{
/** @var EntityRepository $queryBuilder */
$queryBuilder = $this->productAttributeRepository;
$result = $queryBuilder
->createQueryBuilder('p')
->select('p.type')
->where('p.code = :code')
->setParameter(':code', $attributeName)
->getQuery()
->getOneOrNullResult();
return $result['type'];
}
public function findAllWithTranslations(?string $locale): array
{
/** @var EntityRepository $productAttributeRepository */
$productAttributeRepository = $this->productAttributeRepository;
$queryBuilder = $productAttributeRepository->createQueryBuilder('o');
if (null !== $locale) {
$queryBuilder
->addSelect('translation')
/** @phpstan-ignore-next-line phpstan can't read relationship correctly */
->leftJoin('o.translations', 'translation', 'ot')
->andWhere('translation.locale = :locale')
->setParameter('locale', $locale)
;
}
return $queryBuilder
->getQuery()
->getResult()
;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/TaxonRepositoryInterface.php | src/Repository/TaxonRepositoryInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Sylius\Component\Attribute\Model\AttributeInterface;
interface TaxonRepositoryInterface
{
public function getTaxonsByAttributeViaProduct(AttributeInterface $attribute): array;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/TaxonRepository.php | src/Repository/TaxonRepository.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr\Join;
use Sylius\Component\Attribute\Model\AttributeInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface as BaseTaxonRepositoryInterface;
class TaxonRepository implements TaxonRepositoryInterface
{
public function __construct(
private BaseTaxonRepositoryInterface|EntityRepository $baseTaxonRepository,
private ProductRepositoryInterface|EntityRepository $productRepository,
private string $productTaxonEntityClass,
private string $productAttributeEntityClass
) {
}
public function getTaxonsByAttributeViaProduct(AttributeInterface $attribute): array
{
/** @var EntityRepository $taxonRepository */
$taxonRepository = $this->baseTaxonRepository;
/** @var EntityRepository $productRepository */
$productRepository = $this->productRepository;
return $taxonRepository
->createQueryBuilder('t')
->distinct(true)
->select('t')
->leftJoin($this->productTaxonEntityClass, 'pt', Join::WITH, 'pt.taxon = t.id')
->where(
'pt.product IN(' .
$productRepository
->createQueryBuilder('p')
->leftJoin($this->productAttributeEntityClass, 'pav', Join::WITH, 'pav.subject = p.id')
->where('pav.attribute = :attribute')
->getQuery()
->getDQL()
. ')'
)
->setParameter(':attribute', $attribute)
->getQuery()
->getResult()
;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/OrderItemRepositoryInterface.php | src/Repository/OrderItemRepositoryInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Sylius\Component\Core\Model\ProductVariantInterface;
interface OrderItemRepositoryInterface
{
public function countByVariant(ProductVariantInterface $variant): int;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/ProductVariantRepository.php | src/Repository/ProductVariantRepository.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Doctrine\ORM\EntityRepository;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface as BaseProductVariantRepositoryInterface;
use Sylius\Component\Product\Model\ProductOptionValueInterface;
class ProductVariantRepository implements ProductVariantRepositoryInterface
{
public function __construct(
private BaseProductVariantRepositoryInterface|EntityRepository $baseProductVariantRepository
) {
}
public function findOneByOptionValue(ProductOptionValueInterface $productOptionValue): ?ProductVariantInterface
{
/** @var EntityRepository $baseProductVariantRepository */
$baseProductVariantRepository = $this->baseProductVariantRepository;
return $baseProductVariantRepository
->createQueryBuilder('o')
->where(':optionValue MEMBER OF o.optionValues')
->setParameter('optionValue', $productOptionValue)
->getQuery()
->setMaxResults(1)
->getOneOrNullResult()
;
}
public function findByOptionValue(ProductOptionValueInterface $productOptionValue): array
{
/** @var EntityRepository $baseProductVariantRepository */
$baseProductVariantRepository = $this->baseProductVariantRepository;
return $baseProductVariantRepository
->createQueryBuilder('o')
->where(':optionValue MEMBER OF o.optionValues')
->setParameter('optionValue', $productOptionValue)
->getQuery()
->getResult()
;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/Repository/ProductAttributeValueRepositoryInterface.php | src/Repository/ProductAttributeValueRepositoryInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\Repository;
use Sylius\Component\Attribute\Model\AttributeInterface;
use Sylius\Component\Core\Model\Taxon;
interface ProductAttributeValueRepositoryInterface
{
public function getUniqueAttributeValues(AttributeInterface $productAttribute, Taxon $taxon): array;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/EventListener/ResourceIndexListener.php | src/EventListener/ResourceIndexListener.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\EventListener;
use BitBag\SyliusElasticsearchPlugin\Refresher\ResourceRefresherInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Product\Model\ProductAttribute;
use Sylius\Component\Product\Model\ProductOption;
use Sylius\Component\Resource\Model\ResourceInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Webmozart\Assert\Assert;
final class ResourceIndexListener implements ResourceIndexListenerInterface
{
public function __construct(
private ResourceRefresherInterface $resourceRefresher,
private array $persistersMap,
private RepositoryInterface $attributeRepository,
private RepositoryInterface $optionRepository
) {
}
public function updateIndex(GenericEvent $event): void
{
/** @var ResourceInterface|null $resource */
$resource = $event->getSubject();
Assert::isInstanceOf($resource, ResourceInterface::class);
foreach ($this->persistersMap as $config) {
$method = $config[self::GET_PARENT_METHOD_KEY] ?? null;
if (null !== $method && method_exists($resource, $method)) {
/** @phpstan-ignore-next-line Variable method call on mixed or other bugs */
$resource = $resource->$method();
}
if ($resource instanceof $config[self::MODEL_KEY]) {
/** @phpstan-ignore-next-line refresh method needs ResourceInterface but ECS doesn't see $resource variable in method. */
$this->resourceRefresher->refresh($resource, $config[self::SERVICE_ID_KEY]);
}
if ($resource instanceof ProductInterface || $resource instanceof ProductVariantInterface) {
if (ProductAttribute::class === $config[self::MODEL_KEY]) {
foreach ($this->attributeRepository->findAll() as $attribute) {
/** @var ResourceInterface $attribute */
$this->resourceRefresher->refresh($attribute, $config[self::SERVICE_ID_KEY]);
}
}
if (ProductOption::class === $config[self::MODEL_KEY]) {
foreach ($this->optionRepository->findAll() as $option) {
/** @var ResourceInterface $option */
$this->resourceRefresher->refresh($option, $config[self::SERVICE_ID_KEY]);
}
}
}
}
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/EventListener/ResourceIndexListenerInterface.php | src/EventListener/ResourceIndexListenerInterface.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\EventListener;
use Symfony\Component\EventDispatcher\GenericEvent;
interface ResourceIndexListenerInterface
{
public const GET_PARENT_METHOD_KEY = 'getParentMethod';
public const MODEL_KEY = 'model';
public const SERVICE_ID_KEY = 'serviceId';
public function updateIndex(GenericEvent $event): void;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/EventListener/OrderProductsListener.php | src/EventListener/OrderProductsListener.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\EventListener;
use BitBag\SyliusElasticsearchPlugin\Refresher\ResourceRefresherInterface;
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
use Webmozart\Assert\Assert;
final class OrderProductsListener
{
public function __construct(
private ResourceRefresherInterface $resourceRefresher,
private ObjectPersisterInterface $productPersister
) {
}
public function updateOrderProducts(GenericEvent $event): void
{
$order = $event->getSubject();
Assert::isInstanceOf($order, OrderInterface::class);
/** @var OrderItemInterface $orderItem */
foreach ($order->getItems() as $orderItem) {
/** @var ResourceInterface $product */
$product = $orderItem->getProduct();
$this->resourceRefresher->refresh($product, $this->productPersister);
}
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/src/EventListener/ProductTaxonIndexListener.php | src/EventListener/ProductTaxonIndexListener.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace BitBag\SyliusElasticsearchPlugin\EventListener;
use BitBag\SyliusElasticsearchPlugin\Refresher\ResourceRefresherInterface;
use FOS\ElasticaBundle\Persister\ObjectPersisterInterface;
use Sylius\Component\Core\Model\ProductTaxonInterface;
use Sylius\Component\Resource\Model\ResourceInterface;
final class ProductTaxonIndexListener
{
public function __construct(
private ResourceRefresherInterface $resourceRefresher,
private ObjectPersisterInterface $objectPersister
) {
}
public function updateIndex(ProductTaxonInterface $productTaxon): void
{
/** @var ResourceInterface $product */
$product = $productTaxon->getProduct();
$this->resourceRefresher->refresh($product, $this->objectPersister);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Application/Kernel.php | tests/Application/Kernel.php | <?php
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Application;
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
final class Kernel extends BaseKernel
{
use MicroKernelTrait;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Application/public/index.php | tests/Application/public/index.php | <?php
declare(strict_types=1);
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
use Tests\BitBag\SyliusElasticsearchPlugin\Application\Kernel;
require dirname(__DIR__) . '/config/bootstrap.php';
if ($_SERVER['APP_DEBUG']) {
umask(0000);
Debug::enable();
}
if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? $_ENV['TRUSTED_PROXIES'] ?? false) {
Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}
if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? $_ENV['TRUSTED_HOSTS'] ?? false) {
Request::setTrustedHosts([$trustedHosts]);
}
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Application/config/bundles.php | tests/Application/config/bundles.php | <?php
declare(strict_types=1);
$bundles = [
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Symfony\Bundle\MonologBundle\MonologBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Sylius\Bundle\OrderBundle\SyliusOrderBundle::class => ['all' => true],
Sylius\Bundle\MoneyBundle\SyliusMoneyBundle::class => ['all' => true],
Sylius\Bundle\CurrencyBundle\SyliusCurrencyBundle::class => ['all' => true],
Sylius\Bundle\LocaleBundle\SyliusLocaleBundle::class => ['all' => true],
Sylius\Bundle\ProductBundle\SyliusProductBundle::class => ['all' => true],
Sylius\Bundle\ChannelBundle\SyliusChannelBundle::class => ['all' => true],
Sylius\Bundle\AttributeBundle\SyliusAttributeBundle::class => ['all' => true],
Sylius\Bundle\TaxationBundle\SyliusTaxationBundle::class => ['all' => true],
Sylius\Bundle\ShippingBundle\SyliusShippingBundle::class => ['all' => true],
Sylius\Bundle\PaymentBundle\SyliusPaymentBundle::class => ['all' => true],
Sylius\Bundle\MailerBundle\SyliusMailerBundle::class => ['all' => true],
Sylius\Bundle\PromotionBundle\SyliusPromotionBundle::class => ['all' => true],
Sylius\Bundle\AddressingBundle\SyliusAddressingBundle::class => ['all' => true],
Sylius\Bundle\InventoryBundle\SyliusInventoryBundle::class => ['all' => true],
Sylius\Bundle\TaxonomyBundle\SyliusTaxonomyBundle::class => ['all' => true],
Sylius\Bundle\UserBundle\SyliusUserBundle::class => ['all' => true],
Sylius\Bundle\CustomerBundle\SyliusCustomerBundle::class => ['all' => true],
Sylius\Bundle\UiBundle\SyliusUiBundle::class => ['all' => true],
Sylius\Bundle\ReviewBundle\SyliusReviewBundle::class => ['all' => true],
Sylius\Bundle\CoreBundle\SyliusCoreBundle::class => ['all' => true],
Sylius\Bundle\ResourceBundle\SyliusResourceBundle::class => ['all' => true],
Sylius\Bundle\GridBundle\SyliusGridBundle::class => ['all' => true],
Knp\Bundle\GaufretteBundle\KnpGaufretteBundle::class => ['all' => true],
Knp\Bundle\MenuBundle\KnpMenuBundle::class => ['all' => true],
Liip\ImagineBundle\LiipImagineBundle::class => ['all' => true],
Payum\Bundle\PayumBundle\PayumBundle::class => ['all' => true],
Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Sylius\Bundle\FixturesBundle\SyliusFixturesBundle::class => ['all' => true],
Sylius\Bundle\PayumBundle\SyliusPayumBundle::class => ['all' => true],
Sylius\Bundle\ThemeBundle\SyliusThemeBundle::class => ['all' => true],
Sylius\Bundle\AdminBundle\SyliusAdminBundle::class => ['all' => true],
Sylius\Bundle\ShopBundle\SyliusShopBundle::class => ['all' => true],
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
FriendsOfBehat\SymfonyExtension\Bundle\FriendsOfBehatSymfonyExtensionBundle::class => ['test' => true, 'test_cached' => true],
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
Sylius\Bundle\ApiBundle\SyliusApiBundle::class => ['all' => true],
Lexik\Bundle\JWTAuthenticationBundle\LexikJWTAuthenticationBundle::class => ['all' => true],
SyliusLabs\DoctrineMigrationsExtraBundle\SyliusLabsDoctrineMigrationsExtraBundle::class => ['all' => true],
BabDev\PagerfantaBundle\BabDevPagerfantaBundle::class => ['all' => true],
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
League\FlysystemBundle\FlysystemBundle::class => ['all' => true],
Sylius\TwigExtra\Symfony\SyliusTwigExtraBundle::class => ['all' => true],
Sylius\TwigHooks\SyliusTwigHooksBundle::class => ['all' => true],
Symfony\UX\Icons\UXIconsBundle::class => ['all' => true],
Symfony\UX\TwigComponent\TwigComponentBundle::class => ['all' => true],
Symfony\UX\LiveComponent\LiveComponentBundle::class => ['all' => true],
Symfony\UX\Autocomplete\AutocompleteBundle::class => ['all' => true],
Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
Sylius\Abstraction\StateMachine\SyliusStateMachineAbstractionBundle::class => ['all' => true],
FOS\ElasticaBundle\FOSElasticaBundle::class => ['all' => true],
BitBag\SyliusElasticsearchPlugin\BitBagSyliusElasticsearchPlugin::class => ['all' => true],
Nelmio\Alice\Bridge\Symfony\NelmioAliceBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle::class => ['dev' => true, 'test' => true, 'test_cached' => true],
];
return $bundles;
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Application/config/bootstrap.php | tests/Application/config/bootstrap.php | <?php
declare(strict_types=1);
use Symfony\Component\Dotenv\Dotenv;
require dirname(__DIR__) . '../../../vendor/autoload.php';
// Load cached env vars if the .env.local.php file exists
// Run "composer dump-env prod" to create it (requires symfony/flex >=1.2)
if (is_array($env = @include dirname(__DIR__) . '/.env.local.php')) {
$_SERVER += $env;
$_ENV += $env;
} elseif (!class_exists(Dotenv::class)) {
throw new RuntimeException('Please run "composer require symfony/dotenv" to load the ".env" files configuring the application.');
} else {
// load all the .env files
(new Dotenv())->loadEnv(dirname(__DIR__) . '/.env');
}
$_SERVER['APP_ENV'] = $_ENV['APP_ENV'] = ($_SERVER['APP_ENV'] ?? $_ENV['APP_ENV'] ?? null) ?: 'dev';
$_SERVER['APP_DEBUG'] = $_SERVER['APP_DEBUG'] ?? $_ENV['APP_DEBUG'] ?? 'prod' !== $_SERVER['APP_ENV'];
$_SERVER['APP_DEBUG'] = $_ENV['APP_DEBUG'] = (int) $_SERVER['APP_DEBUG'] || filter_var($_SERVER['APP_DEBUG'], \FILTER_VALIDATE_BOOLEAN) ? '1' : '0';
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/PHPUnit/Integration/IntegrationTestCase.php | tests/PHPUnit/Integration/IntegrationTestCase.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Integration;
use ApiTestCase\JsonApiTestCase;
abstract class IntegrationTestCase extends JsonApiTestCase
{
public function __construct(
?string $name = null,
array $data = [],
string $dataName = ''
) {
parent::__construct($name, $data, $dataName);
$this->dataFixturesPath = __DIR__ . \DIRECTORY_SEPARATOR . 'DataFixtures' . \DIRECTORY_SEPARATOR . 'ORM';
$this->expectedResponsesPath = __DIR__ . \DIRECTORY_SEPARATOR . 'Responses' . \DIRECTORY_SEPARATOR . 'Expected';
}
protected function setUp(): void
{
self::bootKernel();
}
protected function tearDown(): void
{
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/PHPUnit/Integration/Form/Type/ChoiceMapper/AttributesMapper/AttributesTypePercentMapperTest.php | tests/PHPUnit/Integration/Form/Type/ChoiceMapper/AttributesMapper/AttributesTypePercentMapperTest.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace PHPUnit\Integration\Form\Type\ChoiceMapper\AttributesMapper;
use BitBag\SyliusElasticsearchPlugin\Form\Type\ChoiceMapper\AttributesMapper\AttributesTypePercentMapper;
use BitBag\SyliusElasticsearchPlugin\Repository\ProductAttributeValueRepository;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Bundle\TaxonomyBundle\Doctrine\ORM\TaxonRepository;
use Tests\BitBag\SyliusElasticsearchPlugin\Integration\IntegrationTestCase;
class AttributesTypePercentMapperTest extends IntegrationTestCase
{
private ProductAttributeValueRepository $productAttributeValueRepository;
private EntityRepository $attributeRepository;
private TaxonRepository $taxonRepository;
private AttributesTypePercentMapper $attributesType;
public function SetUp(): void
{
parent::SetUp();
$container = self::getContainer();
$this->productAttributeValueRepository = $container->get('bitbag.sylius_elasticsearch_plugin.repository.product_attribute_value_repository');
$this->attributeRepository = $container->get('sylius.repository.product_attribute');
$this->taxonRepository = $container->get('sylius.repository.taxon');
$this->attributesType = $container->get('bitbag_sylius_elasticsearch_plugin.form.mapper.type.percent');
}
public function tearDown(): void
{
parent::tearDown();
self::ensureKernelShutdown();
}
public function test_percent_mapper(): void
{
$this->loadFixturesFromFiles(['Type/ChoiceMapper/AttributesMapper/test_attributes_type_percent_mapper.yaml']);
$attribute = $this->attributeRepository->findAll()[0];
$taxon = $this->taxonRepository->findAll()[0];
$uniqueAttributeValues = $this->productAttributeValueRepository->getUniqueAttributeValues($attribute, $taxon);
$result = $this->attributesType->map($uniqueAttributeValues);
$this->assertNotEmpty($result);
$this->assertCount(1, $result);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/PHPUnit/Integration/Form/Type/ChoiceMapper/AttributesMapper/AttributesTypeDateMapperTest.php | tests/PHPUnit/Integration/Form/Type/ChoiceMapper/AttributesMapper/AttributesTypeDateMapperTest.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace PHPUnit\Integration\Form\Type\ChoiceMapper\AttributesMapper;
use BitBag\SyliusElasticsearchPlugin\Form\Type\ChoiceMapper\AttributesMapper\AttributesTypeDateMapper;
use BitBag\SyliusElasticsearchPlugin\Repository\ProductAttributeValueRepository;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Bundle\TaxonomyBundle\Doctrine\ORM\TaxonRepository;
use Tests\BitBag\SyliusElasticsearchPlugin\Integration\IntegrationTestCase;
class AttributesTypeDateMapperTest extends IntegrationTestCase
{
private ProductAttributeValueRepository $productAttributeValueRepository;
private EntityRepository $attributeRepository;
private TaxonRepository $taxonRepository;
private AttributesTypeDateMapper $attributesTypeDateMapper;
public function SetUp(): void
{
parent::SetUp();
$container = self::getContainer();
$this->productAttributeValueRepository = $container->get('bitbag.sylius_elasticsearch_plugin.repository.product_attribute_value_repository');
$this->attributeRepository = $container->get('sylius.repository.product_attribute');
$this->taxonRepository = $container->get('sylius.repository.taxon');
$this->attributesTypeDateMapper = $container->get('bitbag_sylius_elasticsearch_plugin.form.mapper.type.date');
}
public function tearDown(): void
{
parent::tearDown();
self::ensureKernelShutdown();
}
public function test_date_mapper(): void
{
$this->loadFixturesFromFiles(['Type/ChoiceMapper/AttributesMapper/test_attributes_type_date_mapper.yaml']);
$attribute = $this->attributeRepository->findAll()[0];
$taxon = $this->taxonRepository->findAll()[0];
$uniqueAttributeValues = $this->productAttributeValueRepository->getUniqueAttributeValues($attribute, $taxon);
$result = $this->attributesTypeDateMapper->map($uniqueAttributeValues);
$this->assertNotEmpty($result);
$this->assertCount(1, $result);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/PHPUnit/Integration/Form/Type/ChoiceMapper/AttributesMapper/AttributesTypeDateTimeMapperTest.php | tests/PHPUnit/Integration/Form/Type/ChoiceMapper/AttributesMapper/AttributesTypeDateTimeMapperTest.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace PHPUnit\Integration\Form\Type\ChoiceMapper\AttributesMapper;
use BitBag\SyliusElasticsearchPlugin\Form\Type\ChoiceMapper\AttributesMapper\AttributesTypeDateTimeMapper;
use BitBag\SyliusElasticsearchPlugin\Repository\ProductAttributeValueRepository;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Bundle\TaxonomyBundle\Doctrine\ORM\TaxonRepository;
use Tests\BitBag\SyliusElasticsearchPlugin\Integration\IntegrationTestCase;
class AttributesTypeDateTimeMapperTest extends IntegrationTestCase
{
private ProductAttributeValueRepository $productAttributeValueRepository;
private EntityRepository $attributeRepository;
private TaxonRepository $taxonRepository;
private AttributesTypeDateTimeMapper $attributesType;
public function SetUp(): void
{
parent::SetUp();
$container = self::getContainer();
$this->productAttributeValueRepository = $container->get('bitbag.sylius_elasticsearch_plugin.repository.product_attribute_value_repository');
$this->attributeRepository = $container->get('sylius.repository.product_attribute');
$this->taxonRepository = $container->get('sylius.repository.taxon');
$this->attributesType = $container->get('bitbag_sylius_elasticsearch_plugin.form.mapper.type.date_time');
}
public function tearDown(): void
{
parent::tearDown();
self::ensureKernelShutdown();
}
public function test_date_time_mapper(): void
{
$this->loadFixturesFromFiles(['Type/ChoiceMapper/AttributesMapper/test_attributes_type_date_time_mapper.yaml']);
$attribute = $this->attributeRepository->findAll()[0];
$taxon = $this->taxonRepository->findAll()[0];
$uniqueAttributeValues = $this->productAttributeValueRepository->getUniqueAttributeValues($attribute, $taxon);
$result = $this->attributesType->map($uniqueAttributeValues);
$this->assertNotEmpty($result);
$this->assertCount(1, $result);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/PHPUnit/Integration/Api/ProductListingTest.php | tests/PHPUnit/Integration/Api/ProductListingTest.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace PHPUnit\Integration\Api;
use ApiTestCase\JsonApiTestCase;
use Sylius\Bundle\CoreBundle\SyliusCoreBundle;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Process\Process;
final class ProductListingTest extends JsonApiTestCase
{
public function __construct(
?string $name = null,
array $data = [],
string $dataName = ''
) {
parent::__construct($name, $data, $dataName);
$this->dataFixturesPath = __DIR__ . \DIRECTORY_SEPARATOR . 'DataFixtures' . \DIRECTORY_SEPARATOR . 'ORM';
$this->expectedResponsesPath = __DIR__ . \DIRECTORY_SEPARATOR . 'Responses' . \DIRECTORY_SEPARATOR . 'Expected';
}
public function test_it_finds_products_by_name(): void
{
$this->loadFixturesFromFiles(['test_it_finds_products_by_name.yaml']);
$this->populateElasticsearch();
$this->client->request(
'GET',
'/api/v2/shop/products/search?query=mug'
);
$response = $this->client->getResponse();
if (SyliusCoreBundle::VERSION_ID >= 20100) {
$this->assertResponse($response, '2.1_test_it_finds_products_by_name', Response::HTTP_OK);
return;
}
$this->assertResponse($response, 'test_it_finds_products_by_name', Response::HTTP_OK);
}
public function test_it_finds_products_by_name_and_facets(): void
{
$this->loadFixturesFromFiles(['test_it_finds_products_by_name_and_facets.yaml']);
$this->populateElasticsearch();
$this->client->request(
'GET',
'/api/v2/shop/products/search?query=mug&facets[color][]=red'
);
$response = $this->client->getResponse();
if (SyliusCoreBundle::VERSION_ID >= 20100) {
$this->assertResponse($response, '2.1_test_it_finds_products_by_name_and_facets', Response::HTTP_OK);
return;
}
$this->assertResponse($response, 'test_it_finds_products_by_name_and_facets', Response::HTTP_OK);
}
public function test_it_finds_products_by_name_and_multiple_facets(): void
{
$this->loadFixturesFromFiles(['test_it_finds_products_by_name_and_multiple_facets.yaml']);
$this->populateElasticsearch();
$this->client->request(
'GET',
'/api/v2/shop/products/search?query=mug&facets[color][]=red&facets[material][]=ceramic'
);
$response = $this->client->getResponse();
if (SyliusCoreBundle::VERSION_ID >= 20100) {
$this->assertResponse($response, '2.1_test_it_finds_products_by_name_and_multiple_facets', Response::HTTP_OK);
return;
}
$this->assertResponse($response, 'test_it_finds_products_by_name_and_multiple_facets', Response::HTTP_OK);
}
public function test_it_updates_facets(): void
{
$this->loadFixturesFromFiles(['test_it_updates_facets.yaml']);
$this->populateElasticsearch();
$this->client->request(
'GET',
'/api/v2/shop/products/search?query=mug&facets[color][]=red&facets[material][]=ceramic'
);
$response = $this->client->getResponse();
if (SyliusCoreBundle::VERSION_ID >= 20100) {
$this->assertResponse($response, '2.1_test_it_updates_facets', Response::HTTP_OK);
return;
}
$this->assertResponse($response, 'test_it_updates_facets', Response::HTTP_OK);
}
private function populateElasticsearch(): void
{
$process = new Process(['tests/Application/bin/console', 'fos:elastica:populate']);
$process->run();
if (!$process->isSuccessful()) {
throw new \Exception('Failed to populate Elasticsearch: ' . $process->getErrorOutput());
}
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/PHPUnit/Integration/Repository/ProductAttributeValueRepositoryTest.php | tests/PHPUnit/Integration/Repository/ProductAttributeValueRepositoryTest.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Integration\Repository;
use BitBag\SyliusElasticsearchPlugin\Repository\ProductAttributeValueRepository;
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
use Sylius\Bundle\TaxonomyBundle\Doctrine\ORM\TaxonRepository;
use Tests\BitBag\SyliusElasticsearchPlugin\Integration\IntegrationTestCase;
class ProductAttributeValueRepositoryTest extends IntegrationTestCase
{
private ProductAttributeValueRepository $productAttributeValueRepository;
private EntityRepository $attributeRepository;
private TaxonRepository $taxonRepository;
public function SetUp(): void
{
parent::SetUp();
$container = self::getContainer();
$this->productAttributeValueRepository = $container->get('bitbag.sylius_elasticsearch_plugin.repository.product_attribute_value_repository');
$this->attributeRepository = $container->get('sylius.repository.product_attribute');
$this->taxonRepository = $container->get('sylius.repository.taxon');
}
public function tearDown(): void
{
parent::tearDown();
self::ensureKernelShutdown();
}
public function test_get_unique_attribute_values(): void
{
$this->loadFixturesFromFiles(['Repository/ProductAttributeValueRepositoryTest/test_product_attribute_value_repository.yaml']);
$attribute = $this->attributeRepository->findAll()[0];
$taxon = $this->taxonRepository->findAll()[0];
$result = $this->productAttributeValueRepository->getUniqueAttributeValues($attribute, $taxon);
$this->assertNotEmpty($result);
$this->assertCount(1, $result);
}
public function test_get_unique_attribute_values_for_ancestor_taxon(): void
{
$this->loadFixturesFromFiles(['Repository/ProductAttributeValueRepositoryTest/test_product_attribute_value_repository_for_ancestor_taxon.yaml']);
$attribute = $this->attributeRepository->findAll()[0];
$taxon = $this->taxonRepository->findAll()[0];
$result = $this->productAttributeValueRepository->getUniqueAttributeValues($attribute, $taxon);
$this->assertNotEmpty($result);
$this->assertCount(1, $result);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/PHPUnit/Integration/Repository/ProductAttributeRepositoryTest.php | tests/PHPUnit/Integration/Repository/ProductAttributeRepositoryTest.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* You can find more information about us on https://bitbag.io and write us
* an email on hello@bitbag.io.
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Integration\Repository;
use BitBag\SyliusElasticsearchPlugin\Repository\ProductAttributeRepository;
use Tests\BitBag\SyliusElasticsearchPlugin\Integration\IntegrationTestCase;
class ProductAttributeRepositoryTest extends IntegrationTestCase
{
private ProductAttributeRepository $attributeRepository;
public function SetUp(): void
{
parent::SetUp();
$container = self::getContainer();
$this->attributeRepository = $container->get('bitbag.sylius_elasticsearch_plugin.repository.product_attribute_repository');
}
public function tearDown(): void
{
parent::tearDown();
self::ensureKernelShutdown();
}
public function test_get_attribute_type_by_name(): void
{
$this->loadFixturesFromFiles(['Repository/ProductAttributeValueRepositoryTest/test_product_attribute_repository.yaml']);
$result = $this->attributeRepository->getAttributeTypeByName('t_shirt_brand');
$this->assertNotEmpty($result);
$this->assertIsString($result);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Context/Api/Shop/ProductContext.php | tests/Behat/Context/Api/Shop/ProductContext.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Context\Api\Shop;
use Behat\Behat\Context\Context;
use Symfony\Component\BrowserKit\AbstractBrowser;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\RouterInterface;
use Webmozart\Assert\Assert;
final class ProductContext implements Context
{
public function __construct(
private AbstractBrowser $client,
private RouterInterface $router
) {
}
/**
* @When I search the products by :phrase phrase
*/
public function iSearchTheProductsByPhrase(string $phrase): void
{
$this->client->request(
'GET',
$this->router->generate('bitbag_sylius_elasticsearch_plugin_shop_auto_complete_product_name', ['_locale' => 'en_US', 'query' => $phrase]),
[],
[],
['ACCEPT' => 'application/json']
);
}
/**
* @Then I should see :productsCount products
*/
public function iShouldSeeProducts(int $productsCount): void
{
/** @var Response $response */
$response = $this->client->getResponse();
$content = \json_decode($response->getContent());
Assert::count($content->items, $productsCount);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Context/Ui/Shop/ProductContext.php | tests/Behat/Context/Ui/Shop/ProductContext.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Context\Ui\Shop;
use Behat\Behat\Context\Context;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Tests\BitBag\SyliusElasticsearchPlugin\Behat\Page\Shop\Product\IndexPageInterface;
use Webmozart\Assert\Assert;
final class ProductContext implements Context
{
public function __construct(
private IndexPageInterface $productIndexPage,
private SharedStorageInterface $sharedStorage
) {
}
/**
* @When /^I go to the shop products page for ("([^"]+)" taxon)$/
*/
public function iGoToTheShopProductsPageForTaxon(TaxonInterface $taxon): void
{
$this->productIndexPage->open(['slug' => $taxon->getSlug()]);
$this->sharedStorage->set('current_taxon_page', $taxon);
}
/**
* @When I search the products by :name phase
*/
public function iSearchTheProductsByPhase(string $phase): void
{
$this->productIndexPage->searchByPhase($phase);
$this->productIndexPage->filter();
}
/**
* @When I filter products by :attributeValue :attributeName attribute
*/
public function iFilterProductsByAttribute(string $attributeValue, string $attributeName): void
{
$this->productIndexPage->checkAttribute($attributeName, $attributeValue);
$this->productIndexPage->filter();
}
/**
* @Then /^I should see (\d+) products on (\d+) page$/
* @Then /^I should see (\d+) products on the page$/
*/
public function iShouldSeeProductsOnTheSecondPage(int $count, int $page = 1): void
{
if (1 < $page) {
$this->productIndexPage->paginate($page);
}
Assert::same($this->productIndexPage->countProductsItems(), $count);
}
/**
* @When I filter product price between :min and :max
*/
public function iFilterProductPriceBetweenAnd(int $min, int $max): void
{
$this->productIndexPage->filterPrice($min, $max);
$this->productIndexPage->filter();
}
/**
* @When I filter products by :arg1 :arg2 option
*/
public function iFilterProductsByOption(string $optionValue, string $optionName): void
{
$this->productIndexPage->checkOption($optionName, $optionValue);
$this->productIndexPage->filter();
}
/**
* @When I change the limit to :limit
*/
public function iChangeTheLimitTo(int $limit): void
{
$this->productIndexPage->changeLimit($limit);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Context/Ui/Shop/SearchContext.php | tests/Behat/Context/Ui/Shop/SearchContext.php | <?php
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Context\Ui\Shop;
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Sylius\Component\Core\Model\ProductInterface;
use Tests\BitBag\SyliusElasticsearchPlugin\Behat\Page\Shop\SearchPageInterface;
final class SearchContext implements Context
{
public function __construct(
private SearchPageInterface $searchPage
) {
}
/**
* @When /^I browse the search page$/
*/
public function iBrowseTheSearchPage()
{
$this->searchPage->open();
}
/**
* @When /^I search the products by "([^"]*)" phrase in the site\-wide search box$/
*/
public function iSearchTheProductsByPhraseInTheSiteWideSearchBox(string $phrase)
{
$this->searchPage->searchPhrase($phrase);
}
/**
* @Then /^I should see the (product "([^"]*)") in the search results$/
*/
public function iShouldSeeTheProductNamedInTheSearchResults(ProductInterface $product)
{
$this->searchPage->assertProductInSearchResults($product);
}
/**
* @Then /^I should see the following intervals in the price filter:$/
*/
public function iShouldSeeTheFollowingIntervalsInThePriceFilter(PyStringNode $intervals)
{
$this->searchPage->assertPriceIntervals($intervals->getStrings());
}
/**
* @Given /^I should see (\d+) products in search results$/
*/
public function iShouldSeeProductsInSearchResults(int $expectedCount)
{
$this->searchPage->assertProductsCountInSearchResults($expectedCount);
}
/**
* @Then /^I should see the following options in the taxon filter:$/
*/
public function iShouldSeeTheFollowingOptionsInTheTaxonFilter(PyStringNode $options)
{
$this->searchPage->assertTaxonFacetOptions($options->getStrings());
}
/**
* @Given /^I filter by price interval "([^"]*)"$/
*/
public function iFilterByPriceInterval(string $intervalLabel)
{
$this->searchPage->filterByPriceInterval($intervalLabel);
}
/**
* @Given /^I filter by taxon "([^"]*)"$/
*/
public function iFilterByTaxon(string $taxon)
{
$this->searchPage->filterByTaxon($taxon);
}
/**
* @Then /^I should see the following options in the "([^"]*)" attribute filter:$/
*/
public function iShouldSeeTheFollowingOptionsInTheAttributeFilter(
string $attributeFilterLabel,
PyStringNode $options
) {
$this->searchPage->assertAttributeFacetOptions($attributeFilterLabel, $options->getStrings());
}
/**
* @Then /^I should see the following options in the "([^"]*)" option filter:$/
*/
public function iShouldSeeTheFollowingOptionsInTheOptionFilter($optionFilterLabel, PyStringNode $options)
{
$this->searchPage->assertOptionFacetOptions($optionFilterLabel, $options->getStrings());
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Context/Ui/Shop/HomepageContext.php | tests/Behat/Context/Ui/Shop/HomepageContext.php | <?php
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Context\Ui\Shop;
use Behat\Behat\Context\Context;
use Tests\BitBag\SyliusElasticsearchPlugin\Behat\Page\Shop\HomePageInterface;
class HomepageContext implements Context
{
public function __construct(
private HomePageInterface $homePage
) {
}
/**
* @When /^I open the home page$/
*/
public function iOpenTheHomePage()
{
$this->homePage->open();
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Context/Setup/ProductTaxonContext.php | tests/Behat/Context/Setup/ProductTaxonContext.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Context\Setup;
use Behat\Behat\Context\Context;
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductTaxonInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
final class ProductTaxonContext implements Context
{
public function __construct(
private SharedStorageInterface $sharedStorage,
private FactoryInterface $productTaxonFactory,
private EntityManagerInterface $objectManager
) {
}
/**
* @Given /^these products belongs to ("[^"]+" taxon)$/
*/
public function theseProductsBelongsToTaxon(TaxonInterface $taxon): void
{
/** @var ProductInterface $product */
foreach ($this->sharedStorage->get('products') as $product) {
$productTaxon = $this->createProductTaxon($taxon, $product);
$product->addProductTaxon($productTaxon);
$this->objectManager->persist($product);
}
$this->objectManager->flush();
}
/**
* @Given /^these products belongs primarily to ("[^"]+" taxon)$/
*/
public function theseProductsBelongsPrimarilyToTaxon(TaxonInterface $taxon): void
{
/** @var ProductInterface $product */
foreach ($this->sharedStorage->get('products') as $product) {
$productTaxon = $this->createProductTaxon($taxon, $product);
$product->setMainTaxon($productTaxon->getTaxon());
$this->objectManager->persist($product);
}
$this->objectManager->flush();
}
private function createProductTaxon(
TaxonInterface $taxon,
ProductInterface $product,
int $position = null
): ProductTaxonInterface {
/** @var ProductTaxonInterface $productTaxon */
$productTaxon = $this->productTaxonFactory->createNew();
$productTaxon->setProduct($product);
$productTaxon->setTaxon($taxon);
if (null !== $position) {
$productTaxon->setPosition($position);
}
return $productTaxon;
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Context/Setup/ProductAttributeContext.php | tests/Behat/Context/Setup/ProductAttributeContext.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Context\Setup;
use Behat\Behat\Context\Context;
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Attribute\Factory\AttributeFactoryInterface;
use Sylius\Component\Core\Formatter\StringInflector;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Product\Model\ProductAttributeInterface;
use Sylius\Component\Product\Model\ProductAttributeValueInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Sylius\Component\Resource\Repository\RepositoryInterface;
final class ProductAttributeContext implements Context
{
public function __construct(
private SharedStorageInterface $sharedStorage,
private RepositoryInterface $productAttributeRepository,
private AttributeFactoryInterface $productAttributeFactory,
private FactoryInterface $productAttributeValueFactory,
private EntityManagerInterface $objectManager
) {
}
/**
* @Given /^these products have ([^"]+) attribute "([^"]+)"$/
*/
public function theseProductsHaveTextAttribute(string $productAttributeType, string $productAttributeName): void
{
$this->provideProductAttribute($productAttributeType, $productAttributeName);
$this->objectManager->flush();
}
/**
* @Given /^(\d+) of these products have text attribute "([^"]+)" with "([^"]+)" value$/
*/
public function ofTheseProductsHaveAttributeWithValue(
int $quantity,
string $productAttributeName,
string $value
): void {
$attribute = $this->provideProductAttribute('text', $productAttributeName);
$sumQuantity = $this->sharedStorage->has('sum_quantity') ? $this->sharedStorage->get('sum_quantity') : 0;
$products = $this->sharedStorage->get('products');
if (count($products) <= $sumQuantity) {
$sumQuantity = 0;
}
$products = array_slice($products, $sumQuantity, $quantity);
/** @var ProductInterface $product */
foreach ($products as $product) {
$attributeValue = $this->createProductAttributeValue($value, $attribute);
$this->objectManager->persist($attributeValue);
$product->addAttribute($attributeValue);
}
$this->sharedStorage->set('sum_quantity', $sumQuantity + $quantity);
$this->objectManager->flush();
}
private function createProductAttribute(
string $type,
string $name,
?string $code = null
): ProductAttributeInterface {
$productAttribute = $this->productAttributeFactory->createTyped($type);
$code = $code ?: StringInflector::nameToCode($name);
$productAttribute->setCode($code);
$productAttribute->setName($name);
return $productAttribute;
}
private function provideProductAttribute(
string $type,
string $name,
?string $code = null
): ProductAttributeInterface {
$code = $code ?: StringInflector::nameToCode($name);
/** @var ProductAttributeInterface $productAttribute */
$productAttribute = $this->productAttributeRepository->findOneBy(['code' => $code]);
if (null !== $productAttribute) {
return $productAttribute;
}
$productAttribute = $this->createProductAttribute($type, $name, $code);
$this->saveProductAttribute($productAttribute);
return $productAttribute;
}
private function createProductAttributeValue(
$value,
ProductAttributeInterface $attribute,
string $localeCode = 'en_US'
): ProductAttributeValueInterface {
/** @var ProductAttributeValueInterface $attributeValue */
$attributeValue = $this->productAttributeValueFactory->createNew();
$attributeValue->setAttribute($attribute);
$attributeValue->setValue($value);
$attributeValue->setLocaleCode($localeCode);
$this->objectManager->persist($attributeValue);
return $attributeValue;
}
private function saveProductAttribute(ProductAttributeInterface $productAttribute): void
{
$this->productAttributeRepository->add($productAttribute);
$this->sharedStorage->set('product_attribute', $productAttribute);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Context/Setup/ElasticsearchContext.php | tests/Behat/Context/Setup/ElasticsearchContext.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Context\Setup;
use Behat\Behat\Context\Context;
use Tests\BitBag\SyliusElasticsearchPlugin\Behat\Service\Populate;
final class ElasticsearchContext implements Context
{
public function __construct(
private Populate $populate
) {
}
/**
* @Given the data is populated to Elasticsearch
*/
public function theDataIsPopulatedToElasticsearch(): void
{
$this->populate->populateIndex();
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Context/Setup/ProductContext.php | tests/Behat/Context/Setup/ProductContext.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Context\Setup;
use Behat\Behat\Context\Context;
use Behat\Gherkin\Node\PyStringNode;
use Doctrine\ORM\EntityManagerInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Formatter\StringInflector;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ChannelPricingInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Product\Factory\ProductFactoryInterface;
use Sylius\Component\Product\Generator\SlugGeneratorInterface;
use Sylius\Component\Product\Model\ProductOptionInterface;
use Sylius\Component\Product\Model\ProductOptionValueInterface;
use Sylius\Component\Product\Resolver\ProductVariantResolverInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
final class ProductContext implements Context
{
/** @var \Faker\Generator */
private $faker;
public function __construct(
private SharedStorageInterface $sharedStorage,
private ProductRepositoryInterface $productRepository,
private ProductFactoryInterface $productFactory,
private FactoryInterface $channelPricingFactory,
private FactoryInterface $productOptionFactory,
private FactoryInterface $productOptionValueFactory,
private EntityManagerInterface $objectManager,
private ProductVariantResolverInterface $defaultVariantResolver,
private SlugGeneratorInterface $slugGenerator
) {
$this->faker = \Faker\Factory::create();
}
/**
* @Given there are :quantity t-shirts in the store
*/
public function thereAreTShirtsInTheStore(int $quantity): void
{
$products = [];
for ($i = 0; $i < $quantity; ++$i) {
$products[] = $product = $this->createProduct('T-shirt ' . uniqid());
$this->saveProduct($product);
}
$this->sharedStorage->set('products', $products);
}
/**
* @Given there is a product named :productName in the store
*/
public function thereIsProductNamedInTheStore(string $productName): void
{
$product = $this->createProduct($productName);
$this->saveProduct($product);
$products = $this->sharedStorage->has('products') ? $this->sharedStorage->get('products') : [];
\array_push($products, $product);
$this->sharedStorage->set('products', $products);
}
/**
* @Given /^(\d+) of these products are priced between ("[^"]+") and ("[^"]+")$/
*/
public function ofTheseProductsArePricedBetweenAnd(
int $quantity,
int $min,
int $max
): void {
$channel = $this->sharedStorage->get('channel');
$sumQuantity = $this->sharedStorage->has('sum_quantity') ? $this->sharedStorage->get('sum_quantity') : 0;
$products = $this->sharedStorage->get('products');
if (count($products) <= $sumQuantity) {
$sumQuantity = 0;
}
$products = array_slice($products, $sumQuantity, $quantity);
/** @var ProductInterface $product */
foreach ($products as $product) {
/** @var ProductVariantInterface $productVariant */
$productVariant = $product->getVariants()->first();
$channelPricing = $productVariant->getChannelPricingForChannel($channel);
$channelPricing->setPrice($this->faker->numberBetween($min, $max));
}
$this->sharedStorage->set('sum_quantity', $sumQuantity + $quantity);
$this->objectManager->flush();
}
/**
* @Given these products have :optionName option with values :values
*/
public function theseHaveOption(string $optionName, string $values): void
{
/** @var ProductOptionInterface $option */
$option = $this->productOptionFactory->createNew();
$option->setName($optionName);
$option->setCode(StringInflector::nameToUppercaseCode($optionName));
$this->sharedStorage->set(sprintf('%s_option', $optionName), $option);
foreach (explode(',', $values) as $value) {
$optionValue = $this->addProductOption($option, $value, StringInflector::nameToUppercaseCode($value));
$this->sharedStorage->set(sprintf('%s_option_%s_value', $value, strtolower($optionName)), $optionValue);
}
/** @var ProductInterface $product */
foreach ($this->sharedStorage->get('products') as $product) {
$product->addOption($option);
$product->setVariantSelectionMethod(ProductInterface::VARIANT_SELECTION_MATCH);
}
$this->objectManager->persist($option);
$this->objectManager->flush();
}
/**
* @Given :quantity of these products have :optionName option with :value value
*/
public function ofTheseProductsHaveOptionWithValue(
int $quantity,
string $optionName,
string $value
): void {
$sumQuantity = $this->sharedStorage->has('sum_quantity') ? $this->sharedStorage->get('sum_quantity') : 0;
$products = $this->sharedStorage->get('products');
if (count($products) <= $sumQuantity) {
$sumQuantity = 0;
}
$products = array_slice($products, $sumQuantity, $quantity);
$optionValue = $this->sharedStorage->get(sprintf('%s_option_%s_value', $value, strtolower($optionName)));
/** @var ProductInterface $product */
foreach ($products as $product) {
/** @var ProductVariantInterface $productVariant */
$productVariant = $product->getVariants()->first();
$productVariant->addOptionValue($optionValue);
}
$this->sharedStorage->set('sum_quantity', $sumQuantity + $quantity);
$this->objectManager->flush();
}
private function createProduct(
string $productName,
int $price = 100,
ChannelInterface $channel = null
): ProductInterface {
if (null === $channel && $this->sharedStorage->has('channel')) {
$channel = $this->sharedStorage->get('channel');
}
/** @var ProductInterface $product */
$product = $this->productFactory->createWithVariant();
$product->setCode(StringInflector::nameToUppercaseCode($productName));
$product->setName($productName);
$product->setSlug($this->slugGenerator->generate($productName));
if (null !== $channel) {
$product->addChannel($channel);
foreach ($channel->getLocales() as $locale) {
$product->setFallbackLocale($locale->getCode());
$product->setCurrentLocale($locale->getCode());
$product->setName($productName);
$product->setSlug($this->slugGenerator->generate($productName));
}
}
/** @var ProductVariantInterface $productVariant */
$productVariant = $this->defaultVariantResolver->getVariant($product);
if (null !== $channel) {
$productVariant->addChannelPricing($this->createChannelPricingForChannel($price, $channel));
}
$productVariant->setCode($product->getCode());
$productVariant->setName($product->getName());
return $product;
}
private function addProductOption(
ProductOptionInterface $option,
string $value,
string $code
): ProductOptionValueInterface {
/** @var ProductOptionValueInterface $optionValue */
$optionValue = $this->productOptionValueFactory->createNew();
$optionValue->setValue($value);
$optionValue->setCode($code);
$optionValue->setOption($option);
$option->addValue($optionValue);
return $optionValue;
}
private function saveProduct(ProductInterface $product): void
{
$this->productRepository->add($product);
$this->sharedStorage->set('product', $product);
}
private function createChannelPricingForChannel(int $price, ChannelInterface $channel = null): ChannelPricingInterface
{
/** @var ChannelPricingInterface $channelPricing */
$channelPricing = $this->channelPricingFactory->createNew();
$channelPricing->setPrice($price);
$channelPricing->setChannelCode($channel->getCode());
return $channelPricing;
}
/**
* @Given /^(this product)'s description is:$/
*/
public function thisProductSDescriptionIs(ProductInterface $product, PyStringNode $description)
{
$product->setDescription($description->getRaw());
$this->objectManager->flush();
}
/**
* @Given /^(this product)'s short description is:$/
*/
public function thisProductSShortDescriptionIs(ProductInterface $product, PyStringNode $shortDescription)
{
$product->setShortDescription($shortDescription->getRaw());
$this->objectManager->flush();
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Page/Shop/HomePage.php | tests/Behat/Page/Shop/HomePage.php | <?php
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Page\Shop;
use Sylius\Behat\Page\Shop\HomePage as BaseHomePage;
class HomePage extends BaseHomePage implements HomePageInterface
{
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Page/Shop/SearchPage.php | tests/Behat/Page/Shop/SearchPage.php | <?php
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Page\Shop;
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ExpectationException;
use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage;
use Sylius\Component\Core\Model\ProductInterface;
use Webmozart\Assert\Assert;
class SearchPage extends SymfonyPage implements SearchPageInterface
{
public function getRouteName(): string
{
return 'bitbag_sylius_elasticsearch_plugin_shop_search';
}
public function searchPhrase(string $phrase): void
{
$this->getElement('search_box_query')->setValue($phrase);
$this->getElement('search_box_submit')->click();
}
public function getSearchResults(): array
{
$results = [];
foreach ($this->getElement('search_results')->findAll('css', '[data-test-product-name]') as $productElement) {
$results[] = trim($productElement->getText());
}
return $results;
}
protected function getDefinedElements(): array
{
return [
'search_box_query' => '#bitbag_elasticsearch_search_query',
'search_box_submit' => '#bitbag_elasticsearch_search_box_search',
'search_results' => '#search_results',
'search_facets_price' => '#bitbag_elasticsearch_search_facets_price',
'search_facets_taxon' => '#bitbag_elasticsearch_search_facets_taxon',
'search_facets_filter_button' => 'form[name="bitbag_elasticsearch_search"] button[type="submit"]',
'search_facets_attribute_car_type' => '#bitbag_elasticsearch_search_facets_Car_Type',
'search_facets_attribute_motorbike_type' => '#bitbag_elasticsearch_search_facets_Motorbike_Type',
'search_facets_attribute_color' => '#bitbag_elasticsearch_search_facets_Color',
'search_facets_option_supply' => '#bitbag_elasticsearch_search_facets_SUPPLY',
'search_facets_option_SUPPLY' => '#bitbag_elasticsearch_search_facets_SUPPLY',
];
}
public function assertProductInSearchResults(ProductInterface $product): void
{
$results = $this->getSearchResults();
foreach ($results as $result) {
if (false !== strpos($result, $product->getName())) {
return;
}
}
throw new ExpectationException(
sprintf('Cannot find a product named "%s" in the search results', $product->getName()),
$this->getSession()
);
}
public function assertPriceIntervals(array $expectedIntervals): void
{
$priceIntervals = array_map(
static fn (NodeElement $element) => trim($element->getText()),
$this->getElement('search_facets_price')->findAll('css', '.form-check-label')
);
Assert::eq(
$priceIntervals,
$expectedIntervals,
sprintf(
"Expected intervals are:\n%s\nGot:\n%s",
print_r($expectedIntervals, true),
print_r($priceIntervals, true)
)
);
}
public function assertProductsCountInSearchResults(int $expectedCount): void
{
Assert::count($this->getSearchResults(), $expectedCount);
}
public function assertTaxonFacetOptions(array $expectedOptions): void
{
$options = array_map(
static fn (NodeElement $element) => trim($element->getText()),
$this->getElement('search_facets_taxon')->findAll('css', '.form-check-label')
);
Assert::eq(
$options,
$expectedOptions,
sprintf(
"Expected taxon facet options are:\n%s\nGot:\n%s",
print_r($expectedOptions, true),
print_r($options, true)
)
);
}
public function filterByFacet(string $facetName, string $label): void
{
$session = $this->getSession();
$currentUrl = $session->getCurrentUrl();
$parsedUrl = parse_url($currentUrl);
$queryParams = [];
if (!empty($parsedUrl['query'])) {
parse_str($parsedUrl['query'], $queryParams);
}
$facetElement = $this->getElement("search_facets_{$facetName}");
if (!$facetElement) {
throw new \Exception("Facet '{$facetName}' not found.");
}
foreach ($facetElement->findAll('css', '.form-check-input') as $checkbox) {
$labelElement = $checkbox->getParent()->find('css', 'label');
if ($labelElement && preg_replace('/\s*\(\d+\)$/', '', trim($labelElement->getText())) === $label) {
$queryParams['bitbag_elasticsearch_search']['facets'][$facetName][] = $checkbox->getAttribute('value');
$newUrl = sprintf(
'%s://%s%s?%s',
$parsedUrl['scheme'] ?? 'http',
$parsedUrl['host'] ?? 'localhost',
$parsedUrl['path'] ?? '',
http_build_query($queryParams)
);
$session->visit($newUrl);
return;
}
}
throw new \Exception("Filter option '{$label}' not found in facet '{$facetName}'.");
}
public function filterByPriceInterval(string $intervalLabel): void
{
$this->filterByFacet('price', $intervalLabel);
}
public function filterByTaxon(string $taxon): void
{
$this->filterByFacet('taxon', $taxon);
}
public function assertAttributeFacetOptions(string $attributeFilterLabel, array $expectedOptions): void
{
$element = 'search_facets_attribute_' . strtolower(str_replace(' ', '_', $attributeFilterLabel));
if (!$this->hasElement($element)) {
throw new ExpectationException(
sprintf("Element '%s' is not defined in `getDefinedElements()`", $element),
$this->getSession()
);
}
$options = array_map(
static fn (NodeElement $element) => trim($element->getText()),
$this->getElement($element)->findAll('css', '.form-check-label')
);
Assert::eq(
$options,
$expectedOptions,
sprintf(
"Expected \"%s\" attribute facet options are:\n%s\nGot:\n%s",
$attributeFilterLabel,
print_r($expectedOptions, true),
print_r($options, true)
)
);
}
public function assertOptionFacetOptions($optionFilterLabel, array $expectedOptions): void
{
$element = 'search_facets_option_' . strtoupper(str_replace(' ', '_', $optionFilterLabel));
if (!$this->hasElement($element)) {
throw new ExpectationException(
sprintf("Element '%s' is not defined in `getDefinedElements()`", $element),
$this->getSession()
);
}
$options = array_map(
static fn (NodeElement $element) => trim($element->getText()),
$this->getElement($element)->findAll('css', '.form-check-label')
);
Assert::eq(
$options,
$expectedOptions,
sprintf(
"Expected \"%s\" option facet options are:\n%s\nGot:\n%s",
$optionFilterLabel,
print_r($expectedOptions, true),
print_r($options, true)
)
);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Page/Shop/HomePageInterface.php | tests/Behat/Page/Shop/HomePageInterface.php | <?php
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Page\Shop;
use Sylius\Behat\Page\Shop\HomePageInterface as BaseHomePageInterface;
interface HomePageInterface extends BaseHomePageInterface
{
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Page/Shop/SearchPageInterface.php | tests/Behat/Page/Shop/SearchPageInterface.php | <?php
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Page\Shop;
use FriendsOfBehat\PageObjectExtension\Page\PageInterface;
use Sylius\Component\Core\Model\ProductInterface;
interface SearchPageInterface extends PageInterface
{
public function searchPhrase(string $phrase): void;
public function getSearchResults(): array;
public function assertProductInSearchResults(ProductInterface $product);
public function assertPriceIntervals(array $expectedIntervals);
public function assertProductsCountInSearchResults(int $expectedCount);
public function assertTaxonFacetOptions(array $expectedOptions);
public function filterByPriceInterval(string $intervalLabel);
public function filterByTaxon(string $taxon);
public function assertAttributeFacetOptions(string $attributeFilterLabel, array $expectedOptions);
public function assertOptionFacetOptions($optionFilterLabel, array $expectedOptions);
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Page/Shop/Product/IndexPage.php | tests/Behat/Page/Shop/Product/IndexPage.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Page\Shop\Product;
use Sylius\Behat\Page\Shop\Product\IndexPage as BaseIndexPage;
class IndexPage extends BaseIndexPage implements IndexPageInterface
{
public function getRouteName(): string
{
return 'bitbag_sylius_elasticsearch_plugin_shop_list_products';
}
public function searchByPhase(string $name): void
{
$this->getDocument()->fillField('name', $name);
}
public function filter(): void
{
$this->getElement('submit_filter')->press();
}
public function checkAttribute(string $attributeName, string $attributeValueName): void
{
$this->getElement('attributes_filter', ['%attributeName%' => $attributeName])->checkField($attributeValueName);
}
public function paginate(int $page): void
{
$this->getElement('pagination')->clickLink($page);
}
public function filterPrice(int $min, int $max): void
{
$this->getDocument()->fillField('Min price', $min);
$this->getDocument()->fillField('Max price', $max);
}
public function changeLimit(int $limit): void
{
$this->getElement('limit')->clickLink($limit);
}
public function checkOption(string $optionName, string $optionValueName): void
{
$this->getElement('options_filter', ['%optionName%' => $optionName])->checkField($optionValueName);
}
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'attributes_filter' => '#attributes label:contains("%attributeName%") ~ .dropdown',
'options_filter' => '#options label:contains("%optionName%") ~ .dropdown',
'limit' => '.ui.dropdown span:contains("Per page") ~ .menu',
'submit_filter' => '#filters-vertical button[type="submit"]',
'pagination' => '.pagination',
]);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Page/Shop/Product/IndexPageInterface.php | tests/Behat/Page/Shop/Product/IndexPageInterface.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Page\Shop\Product;
use Sylius\Behat\Page\Shop\Product\IndexPageInterface as BaseIndexPageInterface;
interface IndexPageInterface extends BaseIndexPageInterface
{
public function searchByPhase(string $name): void;
public function filter(): void;
public function checkAttribute(string $attributeName, string $attributeValueName): void;
public function checkOption(string $optionName, string $optionValueName): void;
public function paginate(int $page): void;
public function filterPrice(int $min, int $max): void;
public function changeLimit(int $limit): void;
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/tests/Behat/Service/Populate.php | tests/Behat/Service/Populate.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace Tests\BitBag\SyliusElasticsearchPlugin\Behat\Service;
use FOS\ElasticaBundle\Event\PostIndexPopulateEvent;
use FOS\ElasticaBundle\Event\PreIndexPopulateEvent;
use FOS\ElasticaBundle\Index\IndexManager;
use FOS\ElasticaBundle\Index\ResetterInterface;
use FOS\ElasticaBundle\Persister\PagerPersisterRegistry;
use FOS\ElasticaBundle\Provider\PagerProviderRegistry;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
final class Populate
{
public function __construct(
private EventDispatcherInterface $dispatcher,
private IndexManager $indexManager,
private PagerProviderRegistry $pagerProviderRegistry,
private PagerPersisterRegistry $pagerPersisterRegistry,
private ResetterInterface $resetter
) {
}
public function populateIndex(): void
{
$this->pagerPersister = $this->pagerPersisterRegistry->getPagerPersister('in_place');
$indexes = array_keys($this->indexManager->getAllIndexes());
$options = [
'delete' => true,
'reset' => true,
];
foreach ($indexes as $index) {
$event = new PreIndexPopulateEvent($index, true, $options);
$this->dispatcher->dispatch($event);
if ($event->isReset()) {
$this->resetter->resetIndex($index, true);
}
$provider = $this->pagerProviderRegistry->getProvider($index);
$pager = $provider->provide($options);
$options['indexName'] = $index;
$this->pagerPersister->insert($pager, $options);
$event = new PostIndexPopulateEvent($index, true, $options);
$this->dispatcher->dispatch($event);
$this->refreshIndex($index);
}
}
private function refreshIndex(string $index): void
{
$this->indexManager->getIndex($index)->refresh();
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/bin/create_node_symlink.php | bin/create_node_symlink.php | <?php
const NODE_MODULES_FOLDER_NAME = 'node_modules';
const PATH_TO_NODE_MODULES = 'tests' . DIRECTORY_SEPARATOR . 'Application' . DIRECTORY_SEPARATOR . 'node_modules';
/* cannot use `file_exists` or `stat` as gives false on symlinks if target path does not exist yet */
if (@lstat(NODE_MODULES_FOLDER_NAME))
{
if (is_link(NODE_MODULES_FOLDER_NAME) || is_dir(NODE_MODULES_FOLDER_NAME)) {
echo '> `' . NODE_MODULES_FOLDER_NAME . '` already exists as a link or folder, keeping existing as may be intentional.' . PHP_EOL;
exit(0);
} else {
echo '> Invalid symlink `' . NODE_MODULES_FOLDER_NAME . '` detected, recreating...' . PHP_EOL;
if (!@unlink(NODE_MODULES_FOLDER_NAME)) {
echo '> Could not delete file `' . NODE_MODULES_FOLDER_NAME . '`.' . PHP_EOL;
exit(1);
}
}
}
/* try to create the symlink using PHP internals... */
$success = @symlink(PATH_TO_NODE_MODULES, NODE_MODULES_FOLDER_NAME);
/* if case it has failed, but OS is Windows... */
if (!$success && strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
/* ...then try a different approach which does not require elevated permissions and folder to exist */
echo '> This system is running Windows, creation of links requires elevated privileges,' . PHP_EOL;
echo '> and target path to exist. Fallback to NTFS Junction:' . PHP_EOL;
exec(sprintf('mklink /J %s %s 2> NUL', NODE_MODULES_FOLDER_NAME, PATH_TO_NODE_MODULES), $output, $returnCode);
$success = $returnCode === 0;
if (!$success) {
echo '> Failed o create the required symlink' . PHP_EOL;
exit(2);
}
}
$path = @readlink(NODE_MODULES_FOLDER_NAME);
/* check if link points to the intended directory */
if ($path && realpath($path) === realpath(PATH_TO_NODE_MODULES)) {
echo '> Successfully created the symlink.' . PHP_EOL;
exit(0);
}
echo '> Failed to create the symlink to `' . NODE_MODULES_FOLDER_NAME . '`.' . PHP_EOL;
exit(3);
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Formatter/StringFormatterSpec.php | spec/Formatter/StringFormatterSpec.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on mikolaj.krol@bitbag.pl.
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Formatter;
use BitBag\SyliusElasticsearchPlugin\Formatter\StringFormatter;
use BitBag\SyliusElasticsearchPlugin\Formatter\StringFormatterInterface;
use PhpSpec\ObjectBehavior;
final class StringFormatterSpec extends ObjectBehavior
{
function it_is_initializable(): void
{
$this->shouldHaveType(StringFormatter::class);
}
function it_implements_string_formatter_interface(): void
{
$this->shouldHaveType(StringFormatterInterface::class);
}
function it_formats_to_lowercase_without_spaces(): void
{
$this->formatToLowercaseWithoutSpaces('StrIng in-De-x')->shouldBeEqualTo('string_in_de_x');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Facet/TaxonFacetSpec.php | spec/Facet/TaxonFacetSpec.php | <?php
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Facet;
use BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface;
use BitBag\SyliusElasticsearchPlugin\Facet\TaxonFacet;
use Elastica\Aggregation\Terms;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\Taxon;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
final class TaxonFacetSpec extends ObjectBehavior
{
private $taxonsProperty = 'product_taxons';
function let(TaxonRepositoryInterface $taxonRepository): void
{
$this->beConstructedWith($taxonRepository, $this->taxonsProperty);
}
function it_is_initializable(): void
{
$this->shouldHaveType(TaxonFacet::class);
}
function it_implements_facet_interface(): void
{
$this->shouldHaveType(FacetInterface::class);
}
function it_returns_taxon_terms_aggregation(): void
{
$expectedAggregation = new Terms('taxon');
$expectedAggregation->setField('product_taxons.keyword');
$this->getAggregation()->shouldBeLike($expectedAggregation);
}
function it_returns_terms_query_for_selected_buckets(): void
{
$this->getQuery(['taxon_1', 'taxon_2'])->shouldBeLike(
new \Elastica\Query\Terms('product_taxons.keyword', ['taxon_1', 'taxon_2'])
);
}
function it_returns_taxon_name_as_bucket_label(TaxonRepositoryInterface $taxonRepository): void
{
$taxon = new Taxon();
$taxon->setCurrentLocale('en_US');
$taxon->setFallbackLocale('en_US');
$taxon->setName('Taxon 1');
$taxonRepository->findOneBy(['code' => 'taxon_1'])->shouldBeCalled()->willReturn($taxon);
$this->getBucketLabel(['key' => 'taxon_1', 'doc_count' => 3])->shouldBe('Taxon 1 (3)');
}
function it_returns_bucket_key_as_bucket_label_if_taxon_could_not_be_found(
TaxonRepositoryInterface $taxonRepository
): void {
$taxonRepository->findOneBy(['code' => 'taxon_1'])->shouldBeCalled()->willReturn(null);
$this->getBucketLabel(['key' => 'taxon_1', 'doc_count' => 3])->shouldBe('taxon_1 (3)');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Facet/AttributeFacetSpec.php | spec/Facet/AttributeFacetSpec.php | <?php
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Facet;
use BitBag\SyliusElasticsearchPlugin\Facet\AttributeFacet;
use BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
use Elastica\Aggregation\Terms;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Attribute\Model\AttributeInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
final class AttributeFacetSpec extends ObjectBehavior
{
public function let(
ConcatedNameResolverInterface $attributeNameResolver,
AttributeInterface $attribute,
LocaleContextInterface $localeContext
): void {
$attributeNameResolver->resolvePropertyName('attribute_code')->willReturn('attribute_attribute_code');
$attribute->getCode()->willReturn('attribute_code');
$attribute->getType()->willReturn('text');
$this->beConstructedWith($attributeNameResolver, $attribute, $localeContext);
}
public function it_is_initializable(): void
{
$this->shouldHaveType(AttributeFacet::class);
}
public function it_implements_facet_interface(): void
{
$this->shouldHaveType(FacetInterface::class);
}
public function it_returns_terms_aggregation(LocaleContextInterface $localeContext): void
{
$localeContext->getLocaleCode()->willReturn('en');
$expectedAggregation = new Terms('');
$expectedAggregation->setField('attribute_attribute_code_en.keyword');
$this->getAggregation()->shouldBeLike($expectedAggregation);
}
public function it_returns_terms_query(LocaleContextInterface $localeContext): void
{
$localeContext->getLocaleCode()->willReturn('en');
$selectedBuckets = ['selected_value'];
$expectedQuery = new \Elastica\Query\Terms('attribute_attribute_code_en.keyword', $selectedBuckets);
$this->getQuery($selectedBuckets)->shouldBeLike($expectedQuery);
}
public function it_returns_bucket_label_(): void
{
$this->getBucketLabel(['key' => 'value_label', 'doc_count' => 3])->shouldReturn('Value Label (3)');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Facet/PriceFacetSpec.php | spec/Facet/PriceFacetSpec.php | <?php
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Facet;
use BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface;
use BitBag\SyliusElasticsearchPlugin\Facet\PriceFacet;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
use Elastica\Aggregation\Histogram;
use Elastica\Query\BoolQuery;
use Elastica\Query\Range;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface;
use Sylius\Component\Core\Context\ShopperContextInterface;
use Sylius\Component\Core\Model\Channel;
final class PriceFacetSpec extends ObjectBehavior
{
private $interval = 1000000;
function let(
ConcatedNameResolverInterface $channelPricingNameResolver,
MoneyFormatterInterface $moneyFormatter,
ShopperContextInterface $shopperContext
): void {
$channel = new Channel();
$channel->setCode('web_us');
$shopperContext->getChannel()->willReturn($channel);
$this->beConstructedWith(
$channelPricingNameResolver,
$moneyFormatter,
$shopperContext,
$this->interval
);
}
function it_is_initializable(): void
{
$this->shouldHaveType(PriceFacet::class);
}
function it_implements_facet_interface(): void
{
$this->shouldHaveType(FacetInterface::class);
}
function it_returns_histogram_aggregation_for_price_field(
ConcatedNameResolverInterface $channelPricingNameResolver
): void {
$channelPricingNameResolver->resolvePropertyName('web_us')->shouldBeCalled()->willReturn('price_web_us');
$expectedHistogram = new Histogram('price', 'price_web_us', $this->interval);
$expectedHistogram->setMinimumDocumentCount(1);
$this->getAggregation()->shouldBeLike($expectedHistogram);
}
function it_returns_bool_query_made_of_ranges_based_on_selected_histograms(
ConcatedNameResolverInterface $channelPricingNameResolver
): void {
$channelPricingNameResolver->resolvePropertyName('web_us')->shouldBeCalled()->willReturn('price_web_us');
$selectedHistograms = [1000000, 4000000];
$expectedQuery = new BoolQuery();
$expectedQuery->addShould(new Range('price_web_us', ['gte' => 1000000, 'lte' => 2000000]));
$expectedQuery->addShould(new Range('price_web_us', ['gte' => 4000000, 'lte' => 5000000]));
$this->getQuery($selectedHistograms)->shouldBeLike($expectedQuery);
}
function it_returns_money_formatted_bucket_label(
MoneyFormatterInterface $moneyFormatter,
ShopperContextInterface $shopperContext
): void {
$shopperContext->getCurrencyCode()->willReturn('USD');
$shopperContext->getLocaleCode()->willReturn('en_US');
$moneyFormatter->format(1000000, 'USD', 'en_US')->shouldBeCalled()->willReturn('$10,000.00');
$moneyFormatter->format(2000000, 'USD', 'en_US')->shouldBeCalled()->willReturn('$20,000.00');
$this->getBucketLabel(['key' => 1000000, 'doc_count' => 6])->shouldBe('$10,000.00 - $20,000.00 (6)');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Facet/OptionFacetSpec.php | spec/Facet/OptionFacetSpec.php | <?php
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Facet;
use BitBag\SyliusElasticsearchPlugin\Facet\FacetInterface;
use BitBag\SyliusElasticsearchPlugin\Facet\OptionFacet;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
use Elastica\Aggregation\Terms;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Product\Model\ProductOptionInterface;
final class OptionFacetSpec extends ObjectBehavior
{
function let(ConcatedNameResolverInterface $optionNameResolver, ProductOptionInterface $productOption): void
{
$optionCode = 'SUPPLY';
$optionNameResolver->resolvePropertyName('SUPPLY')->willReturn('option_SUPPLY');
$productOption->setCurrentLocale('en_US');
$productOption->getName()->willReturn('Supply');
$productOption->getCode()->willReturn($optionCode);
$this->beConstructedWith($optionNameResolver, $productOption, $optionCode);
}
function it_is_initializable(): void
{
$this->shouldHaveType(OptionFacet::class);
}
function it_implements_facet_interface(): void
{
$this->shouldHaveType(FacetInterface::class);
}
function it_returns_terms_aggregation(): void
{
$expectedAggregation = new Terms('');
$expectedAggregation->setField('option_SUPPLY.keyword');
$this->getAggregation()->shouldBeLike($expectedAggregation);
}
function it_returns_terms_query(): void
{
$expectedQuery = new \Elastica\Query\Terms('option_SUPPLY.keyword', ['selected', 'values']);
$this->getQuery(['selected', 'values'])->shouldBeLike($expectedQuery);
}
function it_returns_bucket_label(): void
{
$this->getBucketLabel(['key' => 'option_value', 'doc_count' => 3])->shouldReturn('Option Value (3)');
}
function it_returns_option_name_as_facet_label(): void
{
$this->getLabel()->shouldReturn('Supply');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Finder/ShopProductsFinderSpec.php | spec/Finder/ShopProductsFinderSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Finder;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\PaginationDataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\SortDataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\Facet\RegistryInterface;
use BitBag\SyliusElasticsearchPlugin\Finder\ShopProductsFinder;
use BitBag\SyliusElasticsearchPlugin\Finder\ShopProductsFinderInterface;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
use Elastica\Query\AbstractQuery;
use FOS\ElasticaBundle\Finder\PaginatedFinderInterface;
use Pagerfanta\Pagerfanta;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
final class ShopProductsFinderSpec extends ObjectBehavior
{
function let(
QueryBuilderInterface $shopProductsQueryBuilder,
PaginatedFinderInterface $productFinder,
RegistryInterface $facetRegistry
): void {
$this->beConstructedWith(
$shopProductsQueryBuilder,
$productFinder,
$facetRegistry
);
}
function it_is_initializable(): void
{
$this->shouldHaveType(ShopProductsFinder::class);
}
function it_implements_shop_products_finder_interface(): void
{
$this->shouldHaveType(ShopProductsFinderInterface::class);
}
function it_finds(
QueryBuilderInterface $shopProductsQueryBuilder,
PaginatedFinderInterface $productFinder,
AbstractQuery $boolQuery,
Pagerfanta $pagerfanta
): void {
$data = [
SortDataHandlerInterface::SORT_INDEX => null,
PaginationDataHandlerInterface::PAGE_INDEX => null,
PaginationDataHandlerInterface::LIMIT_INDEX => null,
'facets' => [],
];
$shopProductsQueryBuilder->buildQuery($data)->willReturn($boolQuery);
$productFinder->findPaginated(Argument::any())->willReturn($pagerfanta);
$this->find($data)->shouldBeEqualTo($pagerfanta);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Finder/NamedProductsFinderSpec.php | spec/Finder/NamedProductsFinderSpec.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on mikolaj.krol@bitbag.pl.
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Finder;
use BitBag\SyliusElasticsearchPlugin\Finder\NamedProductsFinderInterface;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
use Elastica\Query\AbstractQuery;
use FOS\ElasticaBundle\Finder\FinderInterface;
use PhpSpec\ObjectBehavior;
final class NamedProductsFinderSpec extends ObjectBehavior
{
function let(
QueryBuilderInterface $productsByPartialNameQueryBuilder,
FinderInterface $productsFinder
): void {
$this->beConstructedWith($productsByPartialNameQueryBuilder, $productsFinder);
}
function it_is_a_named_products_finder(): void
{
$this->shouldImplement(NamedProductsFinderInterface::class);
}
function it_finds_by_partial_name_of_products(
QueryBuilderInterface $productsByPartialNameQueryBuilder,
FinderInterface $productsFinder,
AbstractQuery $query
): void {
$productsByPartialNameQueryBuilder->buildQuery(['query' => 'part'])->willReturn($query);
$productsFinder->find($query)->willReturn([]);
$this->findByNamePart('part')->shouldBeArray();
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Finder/ProductAttributesFinderSpec.php | spec/Finder/ProductAttributesFinderSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Finder;
use BitBag\SyliusElasticsearchPlugin\Finder\ProductAttributesFinder;
use BitBag\SyliusElasticsearchPlugin\Finder\ProductAttributesFinderInterface;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
use Elastica\Query\AbstractQuery;
use FOS\ElasticaBundle\Finder\FinderInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\TaxonInterface;
final class ProductAttributesFinderSpec extends ObjectBehavior
{
function let(
FinderInterface $attributesFinder,
QueryBuilderInterface $attributesByTaxonQueryBuilder
): void {
$this->beConstructedWith(
$attributesFinder,
$attributesByTaxonQueryBuilder,
'taxons'
);
}
function it_is_initializable(): void
{
$this->shouldHaveType(ProductAttributesFinder::class);
}
function it_implements_product_attributes_finder_interface(): void
{
$this->shouldImplement(ProductAttributesFinderInterface::class);
}
function it_finds_by_taxon(
TaxonInterface $taxon,
QueryBuilderInterface $attributesByTaxonQueryBuilder,
FinderInterface $attributesFinder,
AbstractQuery $query
): void {
$taxon->getCode()->willReturn('book');
$attributesByTaxonQueryBuilder->buildQuery(['taxons' => 'book'])->willReturn($query);
$attributesFinder->find($query, 20)->willReturn([]);
$this->findByTaxon($taxon)->shouldBeEqualTo([]);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Finder/ProductOptionsFinderSpec.php | spec/Finder/ProductOptionsFinderSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Finder;
use BitBag\SyliusElasticsearchPlugin\Finder\ProductOptionsFinder;
use BitBag\SyliusElasticsearchPlugin\Finder\ProductOptionsFinderInterface;
use BitBag\SyliusElasticsearchPlugin\QueryBuilder\QueryBuilderInterface;
use Elastica\Query\AbstractQuery;
use FOS\ElasticaBundle\Finder\FinderInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\TaxonInterface;
final class ProductOptionsFinderSpec extends ObjectBehavior
{
function let(
FinderInterface $optionsFinder,
QueryBuilderInterface $productOptionsByTaxonQueryBuilder
): void {
$this->beConstructedWith(
$optionsFinder,
$productOptionsByTaxonQueryBuilder,
'taxons'
);
}
function it_is_initializable(): void
{
$this->shouldHaveType(ProductOptionsFinder::class);
}
function it_implements_product_options_finder_interface(): void
{
$this->shouldHaveType(ProductOptionsFinderInterface::class);
}
function it_finds_by_taxon(
TaxonInterface $taxon,
QueryBuilderInterface $productOptionsByTaxonQueryBuilder,
FinderInterface $optionsFinder,
AbstractQuery $query
): void {
$taxon->getCode()->willReturn('book');
$productOptionsByTaxonQueryBuilder->buildQuery(['taxons' => 'book'])->willReturn($query);
$optionsFinder->find($query, 20)->willReturn([]);
$this->findByTaxon($taxon)->shouldBeEqualTo([]);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Controller/RequestDataHandler/ShopProductsSortDataHandlerSpec.php | spec/Controller/RequestDataHandler/ShopProductsSortDataHandlerSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler;
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\ShopProductsSortDataHandler;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\SortDataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Core\Model\TaxonInterface;
final class ShopProductsSortDataHandlerSpec extends ObjectBehavior
{
public function let(
ConcatedNameResolverInterface $channelPricingNameResolver,
ChannelContextInterface $channelContext,
): void {
$this->beConstructedWith(
$channelPricingNameResolver,
$channelContext,
'sold_units',
'created_at',
'price'
);
}
function it_is_initializable(): void
{
$this->shouldHaveType(ShopProductsSortDataHandler::class);
}
function it_implements_sort_data_handler_interface(): void
{
$this->shouldHaveType(SortDataHandlerInterface::class);
}
function it_retrieves_data(
TaxonContextInterface $taxonContext,
TaxonInterface $taxon,
): void {
$taxonContext->getTaxon()->willReturn($taxon);
$taxon->getCode()->willReturn('t_shirt');
$this->retrieveData([])->shouldBeEqualTo([
'sort' => [
'created_at' => [
'order' => SortDataHandlerInterface::SORT_ASC_INDEX,
'unmapped_type' => 'keyword',
],
],
]);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Controller/RequestDataHandler/PaginationDataHandlerSpec.php | spec/Controller/RequestDataHandler/PaginationDataHandlerSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\PaginationDataHandler;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\PaginationDataHandlerInterface;
use PhpSpec\ObjectBehavior;
final class PaginationDataHandlerSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith(
9,
);
}
function it_is_initializable(): void
{
$this->shouldHaveType(PaginationDataHandler::class);
}
function it_implements_pagination_data_handler_interface(): void
{
$this->shouldHaveType(PaginationDataHandlerInterface::class);
}
function it_retrieves_data(): void
{
$this->retrieveData([])->shouldBeEqualTo([
PaginationDataHandlerInterface::PAGE_INDEX => 1,
PaginationDataHandlerInterface::LIMIT_INDEX => 9,
]);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Controller/RequestDataHandler/ShopProductListDataHandlerSpec.php | spec/Controller/RequestDataHandler/ShopProductListDataHandlerSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler;
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\DataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\ShopProductListDataHandler;
use BitBag\SyliusElasticsearchPlugin\Finder\ProductAttributesFinderInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\TaxonInterface;
final class ShopProductListDataHandlerSpec extends ObjectBehavior
{
function let(
TaxonContextInterface $taxonContext,
ProductAttributesFinderInterface $attributesFinder
): void {
$this->beConstructedWith(
$taxonContext,
$attributesFinder,
'name',
'taxons',
'option',
'attribute'
);
}
function it_is_initializable(): void
{
$this->shouldHaveType(ShopProductListDataHandler::class);
}
function it_implements_data_handler_interface(): void
{
$this->shouldHaveType(DataHandlerInterface::class);
}
function it_retrieves_data(
TaxonContextInterface $taxonContext,
TaxonInterface $taxon
): void {
$taxonContext->getTaxon()->willReturn($taxon);
$taxon->getCode()->willReturn('book');
$this->retrieveData([
'slug' => 'book',
'name' => 'Book',
'price' => [],
'facets' => [],
])->shouldBeEqualTo([
'name' => 'Book',
'taxons' => 'book',
'taxon' => $taxon,
'facets' => [],
]);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Controller/Response/ItemsResponseSpec.php | spec/Controller/Response/ItemsResponseSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Controller\Response;
use BitBag\SyliusElasticsearchPlugin\Controller\Response\DTO\Item;
use PhpSpec\ObjectBehavior;
final class ItemsResponseSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedThrough('createEmpty');
}
function it_can_add_items(): void
{
$this->addItem(new Item(
'Super cars',
'McLaren F1',
'Very quirky super-car',
'/mc-laren/f1',
'$22,000,000.00',
''
));
$this->all()->shouldHaveCount(1);
}
function it_returns_an_array(): void
{
$this->toArray()->shouldBeArray();
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Controller/Response/DTO/ItemSpec.php | spec/Controller/Response/DTO/ItemSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Controller\Response\DTO;
use PhpSpec\ObjectBehavior;
final class ItemSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith(
'Super cars',
'McLaren F1',
'Very quirky super-car',
'/mc-laren/f1',
'$22,000,000.00',
''
);
}
function it_returns_an_array(): void
{
$this->toArray()->shouldReturn([
'taxon_name' => 'Super cars',
'name' => 'McLaren F1',
'description' => 'Very quirky super-car',
'slug' => '/mc-laren/f1',
'price' => '$22,000,000.00',
'image' => '',
]);
}
function it_returns_values(): void
{
$this->taxonName()->shouldReturn('Super cars');
$this->name()->shouldReturn('McLaren F1');
$this->description()->shouldReturn('Very quirky super-car');
$this->slug()->shouldReturn('/mc-laren/f1');
$this->price()->shouldReturn('$22,000,000.00');
$this->image()->shouldReturn('');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Controller/Action/Shop/TaxonProductsSearchActionSpec.php | spec/Controller/Action/Shop/TaxonProductsSearchActionSpec.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on mikolaj.krol@bitbag.pl.
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Controller\Action\Shop;
use BitBag\SyliusElasticsearchPlugin\Controller\Action\Shop\TaxonProductsSearchAction;
use BitBag\SyliusElasticsearchPlugin\Controller\RequestDataHandler\DataHandlerInterface;
use BitBag\SyliusElasticsearchPlugin\Finder\ShopProductsFinderInterface;
use BitBag\SyliusElasticsearchPlugin\Form\Type\ShopProductsFilterType;
use Pagerfanta\Pagerfanta;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;
final class TaxonProductsSearchActionSpec extends ObjectBehavior
{
function let(
FormFactoryInterface $formFactory,
DataHandlerInterface $dataHandler,
ShopProductsFinderInterface $finder,
Environment $twig
): void {
$this->beConstructedWith(
$formFactory,
$dataHandler,
$finder,
$twig
);
}
function it_is_initializable(): void
{
$this->shouldHaveType(TaxonProductsSearchAction::class);
}
function it_renders_product_list(
FormFactoryInterface $formFactory,
FormInterface $form,
DataHandlerInterface $dataHandler,
Pagerfanta $pagerfanta,
FormView $formView,
Environment $twig,
Response $response,
ShopProductsFinderInterface $finder
): void {
$form->getData()->willReturn([]);
$form->isValid()->willReturn(true);
$form->isSubmitted()->willReturn(true);
$form->handleRequest(Argument::any())->willReturn($form);
$form->createView()->willReturn($formView);
$formFactory->create(ShopProductsFilterType::class)->willReturn($form);
$request = new Request(query: ['slug' => null], attributes: ['template' => '@Template']);
$dataHandler->retrieveData(['slug' => null])->willReturn(['taxon' => null]);
$finder->find(['taxon' => null])->willReturn($pagerfanta);
$twig->render('@Template', Argument::any())->shouldBeCalled();
$this->__invoke($request);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Twig/Extension/UnsetArrayElementsExtensionSpec.php | spec/Twig/Extension/UnsetArrayElementsExtensionSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Twig\Extension;
use BitBag\SyliusElasticsearchPlugin\Twig\Extension\UnsetArrayElementsExtension;
use PhpSpec\ObjectBehavior;
use Twig\Extension\AbstractExtension;
final class UnsetArrayElementsExtensionSpec extends ObjectBehavior
{
function it_is_initializable(): void
{
$this->shouldHaveType(UnsetArrayElementsExtension::class);
}
function it_is_a_twig_extension(): void
{
$this->shouldHaveType(AbstractExtension::class);
}
function it_unset_elments(): void
{
$elements = [
'option_l' => 'L',
'option_xl' => 'XL',
];
$this->unsetElements($elements, ['option_xl'])->shouldBeEqualTo(['option_l' => 'L']);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Transformer/Product/ChannelPricingTransformerSpec.php | spec/Transformer/Product/ChannelPricingTransformerSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Transformer\Product;
use BitBag\SyliusElasticsearchPlugin\Transformer\Product\TransformerInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Bundle\MoneyBundle\Formatter\MoneyFormatterInterface;
use Sylius\Component\Channel\Context\ChannelContextInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ChannelPricingInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Product\Resolver\ProductVariantResolverInterface;
final class ChannelPricingTransformerSpec extends ObjectBehavior
{
function let(
ChannelContextInterface $channelContext,
LocaleContextInterface $localeContext,
ProductVariantResolverInterface $productVariantResolver,
MoneyFormatterInterface $moneyFormatter
): void {
$this->beConstructedWith($channelContext, $localeContext, $productVariantResolver, $moneyFormatter);
}
function it_is_a_transformer(): void
{
$this->shouldImplement(TransformerInterface::class);
}
function it_transforms_product_channel_prices_into_formatted_price(
ChannelContextInterface $channelContext,
LocaleContextInterface $localeContext,
ProductVariantResolverInterface $productVariantResolver,
MoneyFormatterInterface $moneyFormatter,
CurrencyInterface $currency,
ChannelInterface $channel,
ProductVariantInterface $productVariant,
ProductInterface $product,
ChannelPricingInterface $channelPricing
): void {
$currency->getCode()->willReturn('USD');
$channel->getBaseCurrency()->willReturn($currency);
$channelContext->getChannel()->willReturn($channel);
$localeContext->getLocaleCode()->willReturn('en_US');
$productVariantResolver->getVariant($product)->willReturn($productVariant);
$channelPricing->getPrice()->willReturn(10);
$productVariant->getChannelPricingForChannel($channel)->willReturn($channelPricing);
$moneyFormatter->format(10, 'USD', 'en_US');
$this->transform($product);
}
function it_returns_null_when_product_doeas_not_have_any_variant(
ChannelContextInterface $channelContext,
ProductVariantResolverInterface $productVariantResolver,
MoneyFormatterInterface $moneyFormatter,
CurrencyInterface $currency,
ChannelInterface $channel,
ProductVariantInterface $productVariant,
ProductInterface $product,
ChannelPricingInterface $channelPricing
): void {
$currency->getCode()->willReturn('USD');
$channel->getBaseCurrency()->willReturn($currency);
$channelContext->getChannel()->willReturn($channel);
$productVariantResolver->getVariant($product)->willReturn(null);
$this->transform($product)->shouldBeNull();
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Transformer/Product/ImageTransformerSpec.php | spec/Transformer/Product/ImageTransformerSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Transformer\Product;
use BitBag\SyliusElasticsearchPlugin\Transformer\Product\TransformerInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Liip\ImagineBundle\Service\FilterService;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ImageInterface;
use Sylius\Component\Core\Model\ProductInterface;
final class ImageTransformerSpec extends ObjectBehavior
{
function let(FilterService $filterService): void
{
$this->beConstructedWith($filterService);
}
function it_is_a_transformer(): void
{
$this->shouldImplement(TransformerInterface::class);
}
function it_transforms_product_images_into_product_thumbnail(
ProductInterface $product,
ImageInterface $productImage,
FilterService $filterService
): void {
$product->getImagesByType('main')->willReturn(new ArrayCollection([$productImage->getWrappedObject()]));
$productImage->getPath()->willReturn('/path-to-image.png');
$filterService
->getUrlOfFilteredImage('/path-to-image.png', 'sylius_shop_product_thumbnail')
->shouldBeCalled()
;
$this->transform($product);
}
function it_does_not_transforms_svg_product_images_into_product_thumbnail(
ProductInterface $product,
ImageInterface $productImage,
FilterService $filterService
): void {
$product->getImagesByType('main')->willReturn(new ArrayCollection([$productImage->getWrappedObject()]));
$productImage->getPath()->willReturn('/path-to-image.svg');
$filterService
->getUrlOfFilteredImage('/path-to-image.svg', 'sylius_shop_product_thumbnail')
->shouldNotBeCalled()
;
$this->transform($product);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Transformer/Product/SlugTransformerSpec.php | spec/Transformer/Product/SlugTransformerSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Transformer\Product;
use BitBag\SyliusElasticsearchPlugin\Transformer\Product\TransformerInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\ProductInterface;
use Symfony\Component\Routing\RouterInterface;
final class SlugTransformerSpec extends ObjectBehavior
{
function let(RouterInterface $router): void
{
$this->beConstructedWith($router);
}
function it_is_a_transformer(): void
{
$this->shouldImplement(TransformerInterface::class);
}
function it_transforms_product_slug_into_route(RouterInterface $router, ProductInterface $product): void
{
$product->getSlug()->willReturn('/super-quirky-shirt');
$router->generate('sylius_shop_product_show', ['slug' => '/super-quirky-shirt'])->shouldBeCalled();
$this->transform($product);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/PropertyNameResolver/ConcatedNameResolverSpec.php | spec/PropertyNameResolver/ConcatedNameResolverSpec.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on mikolaj.krol@bitbag.pl.
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\PropertyNameResolver;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolver;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\ConcatedNameResolverInterface;
use PhpSpec\ObjectBehavior;
final class ConcatedNameResolverSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith('Book');
}
function it_is_initializable(): void
{
$this->shouldHaveType(ConcatedNameResolver::class);
}
function it_implements_concated_name_resolver_interface(): void
{
$this->shouldHaveType(ConcatedNameResolverInterface::class);
}
function it_resolves_property_name(): void
{
$this->resolvePropertyName('En')->shouldBeEqualTo('book_en');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/PropertyNameResolver/PriceNameResolverSpec.php | spec/PropertyNameResolver/PriceNameResolverSpec.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on mikolaj.krol@bitbag.pl.
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\PropertyNameResolver;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\PriceNameResolver;
use BitBag\SyliusElasticsearchPlugin\PropertyNameResolver\PriceNameResolverInterface;
use PhpSpec\ObjectBehavior;
final class PriceNameResolverSpec extends ObjectBehavior
{
function let(): void
{
$this->beConstructedWith('price');
}
function it_is_initializable(): void
{
$this->shouldHaveType(PriceNameResolver::class);
}
function it_implements_price_name_resolver_interface(): void
{
$this->shouldHaveType(PriceNameResolverInterface::class);
}
function it_resolves_min_price_name(): void
{
$this->resolveMinPriceName()->shouldBeEqualTo('min_price');
}
function it_resolves_max_price_name(): void
{
$this->resolveMaxPriceName()->shouldBeEqualTo('max_price');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Context/TaxonContextSpec.php | spec/Context/TaxonContextSpec.php | <?php
/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Context;
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContext;
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
use BitBag\SyliusElasticsearchPlugin\Exception\TaxonNotFoundException;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
final class TaxonContextSpec extends ObjectBehavior
{
function let(
RequestStack $requestStack,
TaxonRepositoryInterface $taxonRepository,
LocaleContextInterface $localeContext
): void {
$this->beConstructedWith($requestStack, $taxonRepository, $localeContext);
}
function it_is_initializable(): void
{
$this->shouldHaveType(TaxonContext::class);
}
function it_implements_taxon_context_interface(): void
{
$this->shouldHaveType(TaxonContextInterface::class);
}
function it_gets_taxon(
RequestStack $requestStack,
TaxonRepositoryInterface $taxonRepository,
LocaleContextInterface $localeContext,
Request $request,
TaxonInterface $taxon
): void {
$request->get('slug')->willReturn('book');
$requestStack->getCurrentRequest()->willReturn($request);
$localeContext->getLocaleCode()->willReturn('en');
$taxonRepository->findOneBySlug('book', 'en')->willReturn($taxon);
$this->getTaxon()->shouldBeEqualTo($taxon);
}
function it_throws_taxon_not_found_exception_if_taxon_is_null(
RequestStack $requestStack,
TaxonRepositoryInterface $taxonRepository,
LocaleContextInterface $localeContext,
Request $request
): void {
$request->get('slug')->willReturn('book');
$requestStack->getCurrentRequest()->willReturn($request);
$localeContext->getLocaleCode()->willReturn('en');
$taxonRepository->findOneBySlug('book', 'en')->willReturn(null);
$this->shouldThrow(TaxonNotFoundException::class)->during('getTaxon');
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Context/ProductAttributesContextSpec.php | spec/Context/ProductAttributesContextSpec.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on mikolaj.krol@bitbag.pl.
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Context;
use BitBag\SyliusElasticsearchPlugin\Context\ProductAttributesContext;
use BitBag\SyliusElasticsearchPlugin\Context\ProductAttributesContextInterface;
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
use BitBag\SyliusElasticsearchPlugin\Finder\ProductAttributesFinderInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\TaxonInterface;
final class ProductAttributesContextSpec extends ObjectBehavior
{
function let(
TaxonContextInterface $taxonContext,
ProductAttributesFinderInterface $attributesFinder
): void {
$this->beConstructedWith($taxonContext, $attributesFinder);
}
function it_is_initializable(): void
{
$this->shouldHaveType(ProductAttributesContext::class);
}
function it_implements_product_attributes_context_interface(): void
{
$this->shouldHaveType(ProductAttributesContextInterface::class);
}
function it_gets_attributes(
TaxonContextInterface $taxonContext,
ProductAttributesFinderInterface $attributesFinder,
TaxonInterface $taxon
): void {
$taxonContext->getTaxon()->willReturn($taxon);
$attributesFinder->findByTaxon($taxon)->willReturn([]);
$this->getAttributes()->shouldBeEqualTo([]);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
BitBagCommerce/SyliusElasticsearchPlugin | https://github.com/BitBagCommerce/SyliusElasticsearchPlugin/blob/12afd251bd3a3f7cf280cbb43166a94e89eac291/spec/Context/ProductProductAttributesContextSpec.php | spec/Context/ProductProductAttributesContextSpec.php | <?php
/*
* This file has been created by developers from BitBag.
* Feel free to contact us once you face any issues or want to start
* another great project.
* You can find more information about us on https://bitbag.shop and write us
* an email on mikolaj.krol@bitbag.pl.
*/
declare(strict_types=1);
namespace spec\BitBag\SyliusElasticsearchPlugin\Context;
use BitBag\SyliusElasticsearchPlugin\Context\ProductAttributesContextInterface;
use BitBag\SyliusElasticsearchPlugin\Context\ProductProductAttributesContext;
use BitBag\SyliusElasticsearchPlugin\Context\TaxonContextInterface;
use BitBag\SyliusElasticsearchPlugin\Finder\ProductAttributesFinderInterface;
use PhpSpec\ObjectBehavior;
use Sylius\Component\Core\Model\TaxonInterface;
final class ProductProductAttributesContextSpec extends ObjectBehavior
{
function let(
TaxonContextInterface $taxonContext,
ProductAttributesFinderInterface $attributesFinder
): void {
$this->beConstructedWith($taxonContext, $attributesFinder);
}
function it_is_initializable(): void
{
$this->shouldHaveType(ProductProductAttributesContext::class);
}
function it_implements_product_attributes_context_interface(): void
{
$this->shouldHaveType(ProductAttributesContextInterface::class);
}
function it_gets_attributes(
TaxonContextInterface $taxonContext,
ProductAttributesFinderInterface $attributesFinder,
TaxonInterface $taxon
): void {
$taxonContext->getTaxon()->willReturn($taxon);
$attributesFinder->findByTaxon($taxon)->willReturn([]);
$this->getAttributes()->shouldBeEqualTo([]);
}
}
| php | MIT | 12afd251bd3a3f7cf280cbb43166a94e89eac291 | 2026-01-05T05:15:43.159589Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.