Skip to content

Commit

Permalink
NEXT-33271 - fix: adjust text type custom field handling
Browse files Browse the repository at this point in the history
  • Loading branch information
m-waes authored and tamvt committed Jul 30, 2024
1 parent 986938d commit a50ca46
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Exclude custom fields of type `text` from possible float casting
issue: NEXT-33271
---
# Core
* Changed `src/Elasticsearch/Framework/ElasticsearchFieldMapper.php::formatCustomField()` to not format custom fields of type `text`
8 changes: 8 additions & 0 deletions src/Elasticsearch/Framework/ElasticsearchFieldMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,14 @@ private function formatCustomField(string $entity, array $customFields, Context
continue;
}

/**
* Do not convert/cast fields defined as text.
* See https://issues.shopware.com/issues/NEXT-33271
*/
if ($type === CustomFieldTypes::TEXT) {
continue;
}

if ($type === CustomFieldTypes::BOOL) {
$customFields[$name] = (bool) $customField;
} elseif ($this->isNumberType($type) && \is_numeric($customField)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function testMapCustomFields(): void
$parameterBag = new ParameterBag(['elasticsearch.product.custom_fields_mapping' => [
'cf_foo' => 'text',
'cf_baz' => 'int',
'cf_bar' => 'text',
]]);

$connection = $this->createMock(Connection::class);
Expand All @@ -93,28 +94,38 @@ public function testMapCustomFields(): void
'cf_baz' => '234',
'cf_bool' => 0,
'cf_text' => 'text',
'cf_bar' => '123E321',
],
$enLanguageId => [
'cf_foo' => 'thankyou',
'cf_baz' => '123',
'cf_bool' => 'true',
'cf_text' => '10.0',
'cf_bar' => '123E321',
],
], new Context(new SystemSource()));

static::assertSame([
/**
* Specifically check, that this case does not happen anymore:
* https://issues.shopware.com/issues/NEXT-33271 (comments)
**/
static::assertNotEquals($formatted[$deLanguageId]['cf_bar'], \INF);
static::assertNotEquals($formatted[$enLanguageId]['cf_bar'], \INF);

static::assertEquals([
$deLanguageId => [
'cf_foo' => 'danke',
'cf_baz' => 234.0,
'cf_bool' => false,
'cf_text' => 'text',

'cf_bar' => '123E321',
],
$enLanguageId => [
'cf_foo' => 'thankyou',
'cf_baz' => 123.0,
'cf_bool' => true,
'cf_text' => '10.0',
'cf_bar' => '123E321',
],
], $formatted);
}
Expand Down

0 comments on commit a50ca46

Please sign in to comment.