ExampleProductSalePageDependencyProvider   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 9
eloc 47
dl 0
loc 114
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A provideServiceLayerDependencies() 0 11 1
A addSaleSearchResultFormatterPlugins() 0 7 1
A addSaleSearchQueryPlugin() 0 7 1
A addSearchClient() 0 7 1
A addSaleSearchQueryExpanderPlugins() 0 7 1
A addClientStore() 0 7 1
A addProductLabelClient() 0 7 1
A getSaleSearchResultFormatterPlugins() 0 8 1
A getSaleSearchQueryExpanderPlugins() 0 14 1
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace Pyz\Client\ExampleProductSalePage;
11
12
use Pyz\Client\ExampleProductSalePage\Plugin\Elasticsearch\Query\SaleSearchQueryPlugin;
13
use Spryker\Client\Catalog\Plugin\Elasticsearch\ResultFormatter\RawCatalogSearchResultFormatterPlugin;
14
use Spryker\Client\CatalogPriceProductConnector\Plugin\CurrencyAwareCatalogSearchResultFormatterPlugin;
15
use Spryker\Client\CatalogPriceProductConnector\Plugin\ProductPriceQueryExpanderPlugin;
16
use Spryker\Client\CustomerCatalog\Plugin\Search\ProductListQueryExpanderPlugin;
17
use Spryker\Client\Kernel\AbstractDependencyProvider;
18
use Spryker\Client\Kernel\Container;
19
use Spryker\Client\Search\SearchClient;
20
use Spryker\Client\SearchElasticsearch\Plugin\QueryExpander\FacetQueryExpanderPlugin;
21
use Spryker\Client\SearchElasticsearch\Plugin\QueryExpander\LocalizedQueryExpanderPlugin;
22
use Spryker\Client\SearchElasticsearch\Plugin\QueryExpander\PaginatedQueryExpanderPlugin;
23
use Spryker\Client\SearchElasticsearch\Plugin\QueryExpander\SortedQueryExpanderPlugin;
24
use Spryker\Client\SearchElasticsearch\Plugin\QueryExpander\StoreQueryExpanderPlugin;
25
use Spryker\Client\SearchElasticsearch\Plugin\ResultFormatter\FacetResultFormatterPlugin;
26
use Spryker\Client\SearchElasticsearch\Plugin\ResultFormatter\PaginatedResultFormatterPlugin;
27
use Spryker\Client\SearchElasticsearch\Plugin\ResultFormatter\SortedResultFormatterPlugin;
28
29
class ExampleProductSalePageDependencyProvider extends AbstractDependencyProvider
30
{
31
    public const CLIENT_SEARCH = 'CLIENT_SEARCH';
32
33
    public const CLIENT_PRODUCT_LABEL_STORAGE = 'CLIENT_PRODUCT_LABEL_STORAGE';
34
35
    public const SALE_SEARCH_QUERY_PLUGIN = 'SALE_SEARCH_QUERY_PLUGIN';
36
37
    public const SALE_SEARCH_QUERY_EXPANDER_PLUGINS = 'SALE_SEARCH_QUERY_EXPANDER_PLUGINS';
38
39
    public const SALE_SEARCH_RESULT_FORMATTER_PLUGINS = 'SALE_SEARCH_RESULT_FORMATTER_PLUGINS';
40
41
    public const CLIENT_STORE = 'CLIENT_STORE';
42
43
    public function provideServiceLayerDependencies(Container $container): Container
44
    {
45
        $container = parent::provideServiceLayerDependencies($container);
46
        $container = $this->addSearchClient($container);
47
        $container = $this->addProductLabelClient($container);
48
        $container = $this->addSaleSearchQueryPlugin($container);
49
        $container = $this->addSaleSearchQueryExpanderPlugins($container);
50
        $container = $this->addSaleSearchResultFormatterPlugins($container);
51
        $container = $this->addClientStore($container);
52
53
        return $container;
54
    }
55
56
    protected function addSearchClient(Container $container): Container
57
    {
58
        $container->set(static::CLIENT_SEARCH, function () {
59
            return new SearchClient();
60
        });
61
62
        return $container;
63
    }
64
65
    protected function addProductLabelClient(Container $container): Container
66
    {
67
        $container->set(static::CLIENT_PRODUCT_LABEL_STORAGE, function (Container $container) {
68
            return $container->getLocator()->productLabelStorage()->client();
69
        });
70
71
        return $container;
72
    }
73
74
    protected function addSaleSearchQueryPlugin(Container $container): Container
75
    {
76
        $container->set(static::SALE_SEARCH_QUERY_PLUGIN, function () {
77
            return new SaleSearchQueryPlugin();
78
        });
79
80
        return $container;
81
    }
82
83
    protected function addSaleSearchQueryExpanderPlugins(Container $container): Container
84
    {
85
        $container->set(static::SALE_SEARCH_QUERY_EXPANDER_PLUGINS, function () {
86
            return $this->getSaleSearchQueryExpanderPlugins();
87
        });
88
89
        return $container;
90
    }
91
92
    /**
93
     * @return array<\Spryker\Client\SearchExtension\Dependency\Plugin\QueryExpanderPluginInterface>
94
     */
95
    protected function getSaleSearchQueryExpanderPlugins(): array
96
    {
97
        return [
98
            new StoreQueryExpanderPlugin(),
99
            new LocalizedQueryExpanderPlugin(),
100
            new ProductPriceQueryExpanderPlugin(),
101
            new SortedQueryExpanderPlugin(),
102
            new PaginatedQueryExpanderPlugin(),
103
            new ProductListQueryExpanderPlugin(),
104
105
            /*
106
             * FacetQueryExpanderPlugin needs to be after other query expanders which filters down the results.
107
             */
108
            new FacetQueryExpanderPlugin(),
109
        ];
110
    }
111
112
    protected function addSaleSearchResultFormatterPlugins(Container $container): Container
113
    {
114
        $container->set(static::SALE_SEARCH_RESULT_FORMATTER_PLUGINS, function () {
115
            return $this->getSaleSearchResultFormatterPlugins();
116
        });
117
118
        return $container;
119
    }
120
121
    /**
122
     * @return array<\Spryker\Client\SearchExtension\Dependency\Plugin\ResultFormatterPluginInterface|\Spryker\Client\Search\Dependency\Plugin\ResultFormatterPluginInterface>
123
     */
124
    protected function getSaleSearchResultFormatterPlugins(): array
125
    {
126
        return [
127
            new FacetResultFormatterPlugin(),
128
            new SortedResultFormatterPlugin(),
129
            new PaginatedResultFormatterPlugin(),
130
            new CurrencyAwareCatalogSearchResultFormatterPlugin(
131
                new RawCatalogSearchResultFormatterPlugin(),
132
            ),
133
        ];
134
    }
135
136
    protected function addClientStore(Container $container): Container
137
    {
138
        $container->set(static::CLIENT_STORE, function (Container $container) {
139
            return $container->getLocator()->store()->client();
140
        });
141
142
        return $container;
143
    }
144
}
145