diff --git a/src/Parser/ElasticsearchProductDocumentParser.php b/src/Parser/ElasticsearchProductDocumentParser.php index 7729e93..ceddb88 100644 --- a/src/Parser/ElasticsearchProductDocumentParser.php +++ b/src/Parser/ElasticsearchProductDocumentParser.php @@ -158,7 +158,15 @@ public function parse(array $document): ProductResponseInterface $productAttributeValue->setAttribute($productAttribute); $productAttributeValue->setLocaleCode($localeCode); $productAttributeValue->setSubject($productResponse); - $productAttributeValue->setValue(reset($esProductAttributeValue['values'])); + $firstValue = reset($esProductAttributeValue['values']); + if ($productAttribute->getStorageType() === AttributeValueInterface::STORAGE_DATETIME || + $productAttribute->getStorageType() === AttributeValueInterface::STORAGE_DATE + ) { + $firstValue = new DateTime((string) $firstValue); + } elseif ($productAttribute->getStorageType() === AttributeValueInterface::STORAGE_JSON) { + $firstValue = [$firstValue]; + } + $productAttributeValue->setValue($firstValue); $productResponse->addAttribute($productAttributeValue); } } diff --git a/tests/Application/config/fixtures/dress.yaml b/tests/Application/config/fixtures/dress.yaml index eb0ce39..8d04796 100644 --- a/tests/Application/config/fixtures/dress.yaml +++ b/tests/Application/config/fixtures/dress.yaml @@ -42,12 +42,112 @@ sylius_fixtures: code: 'dress_material' type: 'text' + - + name: 'Dress text not translatable' + code: 'dress_text_not_translatable' + translatable: false + type: 'text' + + - + name: 'Dress textarea not translatable' + code: 'dress_textarea_not_translatable' + translatable: false + type: 'textarea' + + - + name: 'Dress textarea translatable' + code: 'dress_textarea_translatable' + translatable: true + type: 'textarea' + + - + name: 'Checkbox not translatable' + code: 'dress_checkbox_not_translatable' + translatable: false + type: 'checkbox' + + - + name: 'Checkbox translatable' + code: 'dress_checkbox_translatable' + translatable: true + type: 'checkbox' + + - + name: 'Integer translatable' + code: 'dress_integer_translatable' + type: 'integer' + translatable: true + - name: 'Length' code: 'length' type: 'integer' translatable: false + - + name: 'Percent not translatable' + code: 'dress_percent_not_translatable' + translatable: false + type: 'percent' + + - + name: 'Percent translatable' + code: 'dress_percent_translatable' + translatable: true + type: 'percent' + + - + name: 'Datetime not translatable' + code: 'dress_datetime_not_translatable' + translatable: false + type: 'datetime' + + - + name: 'Datetime translatable' + code: 'dress_datetime_translatable' + translatable: true + type: 'datetime' + + - + name: 'Date not translatable' + code: 'dress_date_not_translatable' + translatable: false + type: 'date' + + - + name: 'Date translatable' + code: 'dress_date_translatable' + translatable: true + type: 'date' + + - + name: 'Select not translatable' + code: 'dress_select_not_translatable' + translatable: false + type: 'select' + configuration: + multiple: false + min: null + max: null + choices: + dress_select_not_translatable_1: + en_US: 'Dress select not translatable value 1' + it_IT: 'Vestito selezione non traducibile valore 1' + + - + name: 'Select translatable' + code: 'dress_select_translatable' + translatable: true + type: 'select' + configuration: + multiple: false + min: null + max: null + choices: + dress_select_translatable_1: + en_US: 'Dress select translatable value 1' + it_IT: 'Vestito selezione traducibile valore 1' + dress_option: name: product_option options: @@ -87,6 +187,20 @@ sylius_fixtures: dress_brand: 'You are breathtaking' dress_collection: 'Sylius Summer 2019' dress_material: '100% polyester' + dress_text_not_translatable: 'Abacaba' + dress_textarea_not_translatable: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla nec purus feugiat, vestibulum nunc sit amet' + dress_textarea_translatable: 'Qui minus atque ut odio commodi qui aperiam temporibus qui consectetur atque non molestiae sapiente in vero incidunt. Est incidunt rerum est quibusdam ipsa et quae labore a voluptas autem vel tenetur quisquam eos dignissimos quam.' + dress_checkbox_translatable: true + dress_checkbox_not_translatable: false + dress_integer_translatable: 10 + dress_percent_translatable: 0.10 + dress_percent_not_translatable: 0.12 + dress_datetime_not_translatable: '2019-01-01T12:50:00+00:00' + dress_datetime_translatable: '2019-01-01T12:50:00+00:00' + dress_date_not_translatable: '2019-01-01' + dress_date_translatable: '2019-01-01' + dress_select_not_translatable: ['dress_select_not_translatable_1'] + dress_select_translatable: ['dress_select_translatable_1'] product_options: - 'dress_size' - 'dress_height' @@ -106,6 +220,12 @@ sylius_fixtures: dress_brand: 'You are breathtaking' dress_collection: 'Sylius Summer 2019' dress_material: '100% wool' + dress_text_not_translatable: 'Terasdf' + dress_textarea_not_translatable: 'Sed vero accusamus sit ipsa consequatur ad sint ipsam cum veniam cupiditate est quia neque ab autem tenetur. Et expedita velit est quia quaerat ut quas aliquam et animi illum. Nam quisquam odit aut adipisci internos et dolor consectetur est sapiente illo est nobis reprehenderit hic mollitia beatae ad excepturi aliquid.' + dress_textarea_translatable: 'Eos repellat facilis hic dolores dolorum ut sint harum eos quos optio ut totam impedit sit autem repudiandae. Qui distinctio quasi rem vero laborum et officiis ipsum eum reiciendis nihil.' + dress_checkbox_translatable: true + dress_checkbox_not_translatable: true + dress_integer_translatable: 20 product_options: - 'dress_size' - 'dress_height' @@ -126,6 +246,12 @@ sylius_fixtures: dress_collection: 'Sylius Summer 2019' dress_material: '100% polyester' length: 100 + dress_text_not_translatable: 'Rienac' + dress_textarea_not_translatable: 'Ea voluptas voluptate rem architecto laboriosam est aperiam galisum et iste natus est quos dolorum ex culpa repudiandae qui suscipit quia. Ut rerum expedita et omnis rerum eos dolores quia ab sint cumque.' + dress_textarea_translatable: 'Cum beatae illum quo velit quis non culpa sunt est provident tenetur et corporis sunt nam ipsum dolor. Et animi enim ad dolorum ipsum ut laborum nobis sit neque rerum sed illo error non quod quaerat? Sed culpa blanditiis ut quod assumenda et veritatis officiis est suscipit facilis.' + dress_checkbox_translatable: false + dress_checkbox_not_translatable: false + dress_integer_translatable: 18 product_options: - 'dress_size' - 'dress_height'