AbstractFactFinderToElasticaMapper   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 96
c 1
b 0
f 0
dl 0
loc 147
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mapElasticaImages() 0 22 4
A mapElasticaPrices() 0 25 3
A __construct() 0 4 1
1
<?php
2
3
/**
4
 * MIT License
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
namespace SprykerEco\Client\FactFinderNg\Mapper\Elastica;
9
10
use Generated\Shared\Transfer\ProductAbstractImageStorageTransfer;
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfe...actImageStorageTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use SprykerEco\Client\FactFinderNg\Dependency\Client\FactFinderNgToPriceProductStorageClientInterface;
12
13
abstract class AbstractFactFinderToElasticaMapper
14
{
15
    public const SKU_MAPPING_TYPE = 'sku';
16
    public const GROSS_MODE = 'GROSS_MODE';
17
    public const NET_MODE = 'NET_MODE';
18
19
    public const KEY_TOTAL = 'total';
20
    public const KEY_MAX_SCORE = 'max_score';
21
    public const KEY_HITS = 'hits';
22
    public const KEY_TOP_HITS = 'top-hits';
23
    public const KEY_INDEX = '_index';
24
    public const KEY_SEARCH = '_search';
25
    public const KEY_TYPE = '_type';
26
    public const KEY_PAGE = 'page';
27
    public const KEY_ID = '_id';
28
    public const KEY_OPTION_ID = 'id';
29
    public const KEY_OPTION_SCORE = '_score';
30
    public const KEY_SCORE = 'score';
31
    public const KEY_SOURCE = '_source';
32
    public const KEY_SEARCH_RESULT_DATA = 'search-result-data';
33
    public const KEY_IMAGES = 'images';
34
    public const KEY_ID_PRODUCT_LABELS = 'id_product_labels';
35
    public const KEY_PRICE = 'price';
36
    public const KEY_ABSTRACT_NAME = 'abstract_name';
37
    public const KEY_ID_PRODUCT_ABSTRACT = 'id_product_abstract';
38
    public const KEY_OPTION_TYPE = 'type';
39
    public const KEY_PRODUCT_ABSTRACT = 'product_abstract';
40
    public const KEY_PRICES = 'prices';
41
    public const KEY_ABSTRACT_SKU = 'abstract_sku';
42
    public const KEY_URL = 'url';
43
    public const KEY_AGGREGATIONS = 'aggregations';
44
    public const KEY_KEY = 'key';
45
    public const KEY_DOC_COUNT = 'doc_count';
46
    public const KEY_VARIANT_VALUES = 'variantValues';
47
    public const KEY_TOTAL_HITS = 'totalHits';
48
    public const KEY_SCORE_FIRST_HIT = 'scoreFirstHit';
49
    public const KEY_SCORE_LAST_HIT = 'scoreLastHit';
50
    public const KEY_NAME = 'name';
51
    public const KEY_SKU = 'sku';
52
    public const KEY_FK_PRODUCT_IMAGE_SET = 'fk_product_image_set';
53
    public const KEY_FK_PRODUCT_IMAGE = 'fk_product_image';
54
    public const KEY_ID_PRODUCT_IMAGE = 'id_product_image';
55
    public const KEY_SORT_ORDER = 'sort_order';
56
    public const KEY_SORT_ITEMS = 'sortItems';
57
    public const KEY_FILTERS = 'filters';
58
    public const KEY_FACETS = 'facets';
59
    public const KEY_ID_PRODUCT_IMAGE_SET_TO_PRODUCT_IMAGE = 'id_product_image_set_to_product_image';
60
    public const KEY_CREATED_AT = 'created_at';
61
    public const KEY_EXTERNAL_URL_LARGE = 'external_url_large';
62
    public const KEY_EXTERNAL_URL_SMALL = 'external_url_small';
63
    public const KEY_UPDATED_AT = 'updated_at';
64
    public const KEY_HIT_COUNT = 'hitCount';
65
    public const KEY_BUCKETS = 'buckets';
66
    public const KEY_SUM_OTHER_DOC_COUNT = 'sum_other_doc_count';
67
    public const KEY_DOC_COUNT_ERROR_UPPER_BOUND = 'doc_count_error_upper_bound';
68
    public const KEY_CATEGORY = 'category';
69
    public const KEY_BRAND = 'brand';
70
    public const KEY_PRODUCT_NAME = 'productName';
71
    public const KEY_ATTRIBUTES = 'attributes';
72
    public const KEY_MASTER_ID = 'masterId';
73
    public const KEY_STORE = 'store';
74
    public const KEY_LOCALE = 'locale';
75
    public const KEY_IS_ACTIVE = 'is-active';
76
77
    /**
78
     * @var \SprykerEco\Client\FactFinderNg\Dependency\Client\FactFinderNgToPriceProductStorageClientInterface
79
     */
80
    protected $priceProductStorageClient;
81
82
    /**
83
     * @var string
84
     */
85
    protected $currentLocale;
86
87
    /**
88
     * @var \Generated\Shared\Transfer\StoreTransfer
0 ignored issues
show
Bug introduced by
The type Generated\Shared\Transfer\StoreTransfer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
89
     */
90
    protected $currentStore;
91
92
    /**
93
     * @param \SprykerEco\Client\FactFinderNg\Dependency\Client\FactFinderNgToPriceProductStorageClientInterface $priceProductStorageClient
94
     */
95
    public function __construct(
96
        FactFinderNgToPriceProductStorageClientInterface $priceProductStorageClient
97
    ) {
98
        $this->priceProductStorageClient = $priceProductStorageClient;
99
    }
100
101
    /**
102
     * @param array $productAbstract
103
     *
104
     * @return array
105
     */
106
    protected function mapElasticaPrices(array $productAbstract): array
107
    {
108
        $elasticaPrices = [];
109
        $priceProductAbstractTransfers = $this->priceProductStorageClient
110
            ->getPriceProductAbstractTransfers($productAbstract['id_product_abstract']);
111
112
        foreach ($priceProductAbstractTransfers as $priceProductAbstractTransfer) {
113
            $currencyCode = $priceProductAbstractTransfer->getMoneyValue()
114
                ->getCurrency()
115
                ->getCode();
116
            if (!isset($elasticaPrices[$currencyCode])) {
117
                $elasticaPrices[$currencyCode] = [
118
                    static::GROSS_MODE => [],
119
                    static::NET_MODE => [],
120
                ];
121
            }
122
123
            $elasticaPrices[$currencyCode][static::GROSS_MODE][$priceProductAbstractTransfer->getPriceTypeName()] =
124
                $priceProductAbstractTransfer->getMoneyValue()->getGrossAmount();
125
126
            $elasticaPrices[$currencyCode][static::NET_MODE][$priceProductAbstractTransfer->getPriceTypeName()] =
127
                $priceProductAbstractTransfer->getMoneyValue()->getNetAmount();
128
        }
129
130
        return $elasticaPrices;
131
    }
132
133
    /**
134
     * @param \Generated\Shared\Transfer\ProductAbstractImageStorageTransfer $productAbstractImageStorageTransfer
135
     *
136
     * @return array
137
     */
138
    protected function mapElasticaImages(ProductAbstractImageStorageTransfer $productAbstractImageStorageTransfer): array
139
    {
140
        $elasticaImages = [];
141
        if ($productAbstractImageStorageTransfer !== null) {
142
            foreach ($productAbstractImageStorageTransfer->getImageSets() as $productImageSetStorageTransfer) {
143
                foreach ($productImageSetStorageTransfer->getImages() as $productImageStorageTransfer) {
144
                    $elasticaImages[] = [
145
                        static::KEY_FK_PRODUCT_IMAGE_SET => '',
146
                        static::KEY_ID_PRODUCT_IMAGE => $productImageStorageTransfer->getIdProductImage(),
147
                        static::KEY_UPDATED_AT => '',
148
                        static::KEY_EXTERNAL_URL_SMALL => $productImageStorageTransfer->getExternalUrlSmall(),
149
                        static::KEY_EXTERNAL_URL_LARGE => $productImageStorageTransfer->getExternalUrlLarge(),
150
                        static::KEY_CREATED_AT => '',
151
                        static::KEY_ID_PRODUCT_IMAGE_SET_TO_PRODUCT_IMAGE => '',
152
                        static::KEY_SORT_ORDER => 0,
153
                        static::KEY_FK_PRODUCT_IMAGE => $productImageStorageTransfer->getIdProductImage(),
154
                    ];
155
                }
156
            }
157
        }
158
159
        return $elasticaImages;
160
    }
161
}
162