Skip to content

Commit c554a0f

Browse files
authored
Merge pull request #6817 from magento-tsg/2.4-develop-pr144
[Arrows] Fixes for 2.4 (pr144) (2.4-develop)
2 parents 28bedc7 + 4086a1b commit c554a0f

File tree

18 files changed

+403
-86
lines changed

18 files changed

+403
-86
lines changed

app/code/Magento/Catalog/Model/Product/Type/Price.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ public function getTierPrice($qty, $product)
298298

299299
$custGroup = $this->_getCustomerGroupId($product);
300300
if ($qty) {
301-
$prevQty = 1;
301+
$prevQty = 0;
302302
$prevPrice = $product->getPrice();
303303
$prevGroup = $allGroupsId;
304304

app/code/Magento/ConfigurableProduct/view/frontend/web/js/configurable.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ define([
578578
_.each(elements, function (element) {
579579
var selected = element.options[element.selectedIndex],
580580
config = selected && selected.config,
581-
priceValue = {};
581+
priceValue = this._calculatePrice({});
582582

583583
if (config && config.allowedProducts.length === 1) {
584584
priceValue = this._calculatePrice(config);
@@ -632,12 +632,10 @@ define([
632632
*/
633633
_calculatePrice: function (config) {
634634
var displayPrices = $(this.options.priceHolderSelector).priceBox('option').prices,
635-
newPrices = this.options.spConfig.optionPrices[_.first(config.allowedProducts)];
635+
newPrices = this.options.spConfig.optionPrices[_.first(config.allowedProducts)] || {};
636636

637637
_.each(displayPrices, function (price, code) {
638-
if (newPrices[code]) {
639-
displayPrices[code].amount = newPrices[code].amount - displayPrices[code].amount;
640-
}
638+
displayPrices[code].amount = newPrices[code] ? newPrices[code].amount - displayPrices[code].amount : 0;
641639
});
642640

643641
return displayPrices;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Elasticsearch7\Model\Adapter\DynamicTemplates;
9+
10+
/**
11+
* @inheridoc
12+
*/
13+
class IntegerMapper implements MapperInterface
14+
{
15+
/**
16+
* @inheridoc
17+
*/
18+
public function processTemplates(array $templates): array
19+
{
20+
$templates[] = [
21+
'integer_mapping' => [
22+
'match_mapping_type' => 'long',
23+
'mapping' => [
24+
'type' => 'integer',
25+
],
26+
],
27+
];
28+
29+
return $templates;
30+
}
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Elasticsearch7\Model\Adapter\DynamicTemplates;
9+
10+
/**
11+
* Elasticsearch dynamic templates mapper.
12+
*/
13+
interface MapperInterface
14+
{
15+
/**
16+
* Add/remove/edit dynamic template mapping.
17+
*
18+
* @param array $templates
19+
* @return array
20+
*/
21+
public function processTemplates(array $templates): array;
22+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Elasticsearch7\Model\Adapter\DynamicTemplates;
9+
10+
/**
11+
* @inheridoc
12+
*/
13+
class PositionMapper implements MapperInterface
14+
{
15+
/**
16+
* @inheridoc
17+
*/
18+
public function processTemplates(array $templates): array
19+
{
20+
$templates[] = [
21+
'position_mapping' => [
22+
'match' => 'position_*',
23+
'match_mapping_type' => 'string',
24+
'mapping' => [
25+
'type' => 'integer',
26+
'index' => true,
27+
],
28+
],
29+
];
30+
31+
return $templates;
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Elasticsearch7\Model\Adapter\DynamicTemplates;
9+
10+
/**
11+
* @inheridoc
12+
*/
13+
class PriceMapper implements MapperInterface
14+
{
15+
/**
16+
* @inheridoc
17+
*/
18+
public function processTemplates(array $templates): array
19+
{
20+
$templates[] = [
21+
'price_mapping' => [
22+
'match' => 'price_*',
23+
'match_mapping_type' => 'string',
24+
'mapping' => [
25+
'type' => 'double',
26+
'store' => true,
27+
],
28+
],
29+
];
30+
31+
return $templates;
32+
}
33+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Elasticsearch7\Model\Adapter\DynamicTemplates;
9+
10+
/**
11+
* @inheridoc
12+
*/
13+
class StringMapper implements MapperInterface
14+
{
15+
/**
16+
* @inheridoc
17+
*/
18+
public function processTemplates(array $templates): array
19+
{
20+
$templates[] = [
21+
'string_mapping' => [
22+
'match' => '*',
23+
'match_mapping_type' => 'string',
24+
'mapping' => [
25+
'type' => 'text',
26+
'index' => true,
27+
'copy_to' => '_search',
28+
],
29+
],
30+
];
31+
32+
return $templates;
33+
}
34+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Elasticsearch7\Model\Adapter;
9+
10+
use Magento\Elasticsearch7\Model\Adapter\DynamicTemplates\MapperInterface;
11+
use Magento\Framework\Exception\InvalidArgumentException;
12+
13+
/**
14+
* Elasticsearch dynamic templates provider.
15+
*/
16+
class DynamicTemplatesProvider
17+
{
18+
/**
19+
* @var array
20+
*/
21+
private $mappers;
22+
23+
/**
24+
* @param MapperInterface[] $mappers
25+
*/
26+
public function __construct(array $mappers)
27+
{
28+
$this->mappers = $mappers;
29+
}
30+
31+
/**
32+
* Get elasticsearch dynamic templates.
33+
*
34+
* @return array
35+
* @throws InvalidArgumentException
36+
*/
37+
public function getTemplates(): array
38+
{
39+
$templates = [];
40+
foreach ($this->mappers as $mapper) {
41+
if (!$mapper instanceof MapperInterface) {
42+
throw new InvalidArgumentException(
43+
__('Mapper %1 should implement %2', get_class($mapper), MapperInterface::class)
44+
);
45+
}
46+
$templates = $mapper->processTemplates($templates);
47+
}
48+
49+
return $templates;
50+
}
51+
}

app/code/Magento/Elasticsearch7/Model/Client/Elasticsearch.php

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77

88
namespace Magento\Elasticsearch7\Model\Client;
99

10+
use Magento\AdvancedSearch\Model\Client\ClientInterface;
1011
use Magento\Elasticsearch\Model\Adapter\FieldsMappingPreprocessorInterface;
12+
use Magento\Elasticsearch7\Model\Adapter\DynamicTemplatesProvider;
13+
use Magento\Framework\App\ObjectManager;
1114
use Magento\Framework\Exception\LocalizedException;
12-
use Magento\AdvancedSearch\Model\Client\ClientInterface;
1315

1416
/**
1517
* Elasticsearch client
@@ -38,18 +40,25 @@ class Elasticsearch implements ClientInterface
3840
*/
3941
private $fieldsMappingPreprocessors;
4042

43+
/**
44+
* @var DynamicTemplatesProvider|null
45+
*/
46+
private $dynamicTemplatesProvider;
47+
4148
/**
4249
* Initialize Elasticsearch 7 Client
4350
*
4451
* @param array $options
4552
* @param \Elasticsearch\Client|null $elasticsearchClient
4653
* @param array $fieldsMappingPreprocessors
54+
* @param DynamicTemplatesProvider|null $dynamicTemplatesProvider
4755
* @throws LocalizedException
4856
*/
4957
public function __construct(
5058
$options = [],
5159
$elasticsearchClient = null,
52-
$fieldsMappingPreprocessors = []
60+
$fieldsMappingPreprocessors = [],
61+
?DynamicTemplatesProvider $dynamicTemplatesProvider = null
5362
) {
5463
if (empty($options['hostname'])
5564
|| ((!empty($options['enableAuth']) && ($options['enableAuth'] == 1))
@@ -65,6 +74,8 @@ public function __construct(
6574
}
6675
$this->clientOptions = $options;
6776
$this->fieldsMappingPreprocessors = $fieldsMappingPreprocessors;
77+
$this->dynamicTemplatesProvider = $dynamicTemplatesProvider ?: ObjectManager::getInstance()
78+
->get(DynamicTemplatesProvider::class);
6879
}
6980

7081
/**
@@ -235,8 +246,8 @@ public function updateAlias(string $alias, string $newIndex, string $oldIndex =
235246
{
236247
$params = [
237248
'body' => [
238-
'actions' => []
239-
]
249+
'actions' => [],
250+
],
240251
];
241252
if ($oldIndex) {
242253
$params['body']['actions'][] = ['remove' => ['alias' => $alias, 'index' => $oldIndex]];
@@ -304,47 +315,7 @@ public function addFieldsMapping(array $fields, string $index, string $entityTyp
304315
'body' => [
305316
$entityType => [
306317
'properties' => [],
307-
'dynamic_templates' => [
308-
[
309-
'price_mapping' => [
310-
'match' => 'price_*',
311-
'match_mapping_type' => 'string',
312-
'mapping' => [
313-
'type' => 'double',
314-
'store' => true,
315-
],
316-
],
317-
],
318-
[
319-
'position_mapping' => [
320-
'match' => 'position_*',
321-
'match_mapping_type' => 'string',
322-
'mapping' => [
323-
'type' => 'integer',
324-
'index' => true,
325-
],
326-
],
327-
],
328-
[
329-
'string_mapping' => [
330-
'match' => '*',
331-
'match_mapping_type' => 'string',
332-
'mapping' => [
333-
'type' => 'text',
334-
'index' => true,
335-
'copy_to' => '_search',
336-
],
337-
],
338-
],
339-
[
340-
'integer_mapping' => [
341-
'match_mapping_type' => 'long',
342-
'mapping' => [
343-
'type' => 'integer',
344-
],
345-
],
346-
],
347-
],
318+
'dynamic_templates' => $this->dynamicTemplatesProvider->getTemplates(),
348319
],
349320
],
350321
];

0 commit comments

Comments
 (0)