Skip to content

Commit

Permalink
Merge pull request Lakion#26 from mbabker/FOSElasticaBundle-4-Support
Browse files Browse the repository at this point in the history
Bump to ElasticSearch 2.0
  • Loading branch information
michalmarcinkowski authored May 4, 2017
2 parents 75dfd06 + ff40eba commit cdd4d12
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ php:
addons:
apt:
sources:
- elasticsearch-1.7
- elasticsearch-2.x
packages:
- elasticsearch

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Elastic search for Sylius.
2. Install elastic search server:

```bash
$ brew install elasticsearch@1.7
$ brew install elasticsearch@2.4
```

3. Run elastic search server:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

"sylius/sylius": "dev-master",

"friendsofsymfony/elastica-bundle": "^3.2",
"ongr/elasticsearch-dsl": "^1.0"
"friendsofsymfony/elastica-bundle": "^4.0",
"ongr/elasticsearch-dsl": "^2.0"
},
"require-dev": {
"behat/behat": "^3.2",
Expand Down
14 changes: 10 additions & 4 deletions src/Form/Type/OptionCodeFilterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Lakion\SyliusElasticSearchBundle\Search\Elastic\Factory\Search\SearchFactoryInterface;
use ONGR\ElasticsearchDSL\Aggregation\FiltersAggregation;
use ONGR\ElasticsearchDSL\Search;
use Sylius\Component\Core\Model\Product;
use Sylius\Component\Product\Model\ProductOptionValue;
use Sylius\Component\Product\Model\ProductOptionValueInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
Expand All @@ -44,6 +43,11 @@ final class OptionCodeFilterType extends AbstractType implements DataTransformer
*/
private $productHasOptionCodeQueryFactory;

/**
* @var string
*/
private $productModelClass;

/**
* @var SearchFactoryInterface
*/
Expand All @@ -57,11 +61,13 @@ final class OptionCodeFilterType extends AbstractType implements DataTransformer
public function __construct(
RepositoryManagerInterface $repositoryManager,
QueryFactoryInterface $productHasOptionCodeQueryFactory,
SearchFactoryInterface $searchFactory
SearchFactoryInterface $searchFactory,
$productModelClass
) {
$this->repositoryManager = $repositoryManager;
$this->productHasOptionCodeQueryFactory = $productHasOptionCodeQueryFactory;
$this->searchFactory = $searchFactory;
$this->productModelClass = $productModelClass;
}

/**
Expand All @@ -85,11 +91,11 @@ public function buildForm(FormBuilderInterface $builder, array $options)
'choice_label' => function (ProductOptionValue $productOptionValue) use ($options) {

/** @var Repository $repository */
$repository = $this->repositoryManager->getRepository(Product::class);
$repository = $this->repositoryManager->getRepository($this->productModelClass);
$query = $this->buildAggregation($productOptionValue->getCode())->toArray();
$result = $repository->createPaginatorAdapter($query);
$aggregation = $result->getAggregations();
$count = $aggregation['agg_'.$productOptionValue->getCode()]['buckets'][$productOptionValue->getCode()]['doc_count'];
$count = $aggregation[$productOptionValue->getCode()]['buckets'][$productOptionValue->getCode()]['doc_count'];

return sprintf('%s (%s)', $productOptionValue->getValue(), $count);
},
Expand Down
7 changes: 1 addition & 6 deletions src/Resources/config/app/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,14 @@ fos_elastica:
type: "nested"
properties:
code: { type: string }
availableOn: { type: date }
availableUntil: { type: date }
name: { type: string }
onHand: { type: integer }
onHold: { type: integer }
channelPricings:
type: "nested"
properties:
price: { type: integer }
channel:
type: "object"
properties:
code: { type: string }
channelCode: { type: string }
optionValues:
type: "nested"
properties:
Expand Down
6 changes: 3 additions & 3 deletions src/Resources/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ lakion_elastic_search_shop_product_index:
_controller: lakion_sylius_elastic_search.controller.search:filterAction
_sylius:
template: "@LakionSyliusElasticSearch/Product/index.html.twig"
resource_class: Sylius\Component\Core\Model\Product
resource_class: "%sylius.model.product.class%"
filter_set: mug_type_and_stickers_set
requirements:
slug: .+
Expand All @@ -17,7 +17,7 @@ lakion_elastic_search_shop_global_search:
_controller: lakion_sylius_elastic_search.controller.search:renderFilterSetAction
_sylius:
template: "@LakionSyliusElasticSearch/Product/_globalSearch.html.twig"
resource_class: Sylius\Component\Core\Model\Product
resource_class: "%sylius.model.product.class%"
requirements:
slug: .+

Expand All @@ -28,7 +28,7 @@ sylius_shop_product_index:
_controller: lakion_sylius_elastic_search.controller.search:filterByTaxonAction
_sylius:
template: "@LakionSyliusElasticSearch/Product/indexByTaxon.html.twig"
resource_class: Sylius\Component\Core\Model\Product
resource_class: "%sylius.model.product.class%"
filter_set: mug_type_and_stickers_set
requirements:
slug: .+
1 change: 1 addition & 0 deletions src/Resources/config/services/form.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<argument type="service" id="fos_elastica.manager.orm" />
<argument type="service" id="lakion_sylius_elastic_search.query_factory.product_has_option_code" />
<argument type="service" id="lakion_sylius_elastic_search.factory.search" />
<argument>%sylius.model.product.class%</argument>
<tag name="form.type" />
<tag name="filter.type" type="option" />
</service>
Expand Down
4 changes: 2 additions & 2 deletions tests/Application/app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public function registerBundles()
new \Sylius\Bundle\AdminBundle\SyliusAdminBundle(),
new \Sylius\Bundle\ShopBundle\SyliusShopBundle(),

new \FOS\OAuthServerBundle\FOSOAuthServerBundle(), // Required by SyliusApiBundle
new \Sylius\Bundle\ApiBundle\SyliusApiBundle(),
new \FOS\OAuthServerBundle\FOSOAuthServerBundle(), // Required by SyliusAdminApiBundle
new \Sylius\Bundle\AdminApiBundle\SyliusAdminApiBundle(),
new \FOS\ElasticaBundle\FOSElasticaBundle(),
]);
}
Expand Down
14 changes: 13 additions & 1 deletion tests/Application/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ imports:
- { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" }
- { resource: "@SyliusAdminBundle/Resources/config/app/config.yml" }
- { resource: "@SyliusShopBundle/Resources/config/app/config.yml" }
- { resource: "@SyliusApiBundle/Resources/config/app/config.yml" }
- { resource: "@SyliusAdminApiBundle/Resources/config/app/config.yml" }
- { resource: "@LakionSyliusElasticSearchBundle/Resources/config/app/config.yml" }

- { resource: "security.yml" }
Expand All @@ -33,6 +33,18 @@ doctrine:
path: "%kernel.cache_dir%/db.sql"
charset: UTF8

fos_rest:
exception: ~
view:
formats:
json: true
xml: true
empty_content: 204
format_listener:
rules:
- { path: '^/api', priorities: ['json', 'xml'], fallback_format: json, prefer_extension: true }
- { path: '^/', stop: true }

sylius_resource:
drivers:
- doctrine/orm
Expand Down
2 changes: 1 addition & 1 deletion tests/Application/app/config/routing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sylius_admin:
prefix: /admin

sylius_api:
resource: "@SyliusApiBundle/Resources/config/routing/main.yml"
resource: "@SyliusAdminApiBundle/Resources/config/routing/main.yml"
prefix: /api

sylius_search:
Expand Down

0 comments on commit cdd4d12

Please sign in to comment.