From dc65b1dd0b65621f60c88f315485b712facbe636 Mon Sep 17 00:00:00 2001 From: Arminek Date: Mon, 5 Jun 2017 15:18:24 +0200 Subject: [PATCH] [ElasticSearch] Tweaks for attribute responses --- composer.json | 2 +- src/Controller/ProductAttributeView.php | 21 ++++++++++ src/Controller/TaxonItemView.php | 38 ------------------- src/Factory/ProductListViewFactory.php | 22 ++++++++++- tests/Responses/Expected/mugs_list_page.json | 24 ++++-------- .../Responses/Expected/product_list_page.json | 24 ++++-------- .../product_list_page_by_en_gb_channel.json | 24 ++++-------- 7 files changed, 67 insertions(+), 88 deletions(-) create mode 100644 src/Controller/ProductAttributeView.php delete mode 100644 src/Controller/TaxonItemView.php diff --git a/composer.json b/composer.json index 446e4a5..1c44e1d 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^5.6|^7.0", - "sylius/sylius": "dev-master", + "sylius/sylius": "^1.0@beta", "ongr/elasticsearch-dsl": "^5.0", "ongr/elasticsearch-bundle": "^5.0", "simple-bus/symfony-bridge": "^4.1", diff --git a/src/Controller/ProductAttributeView.php b/src/Controller/ProductAttributeView.php new file mode 100644 index 0000000..95a46a6 --- /dev/null +++ b/src/Controller/ProductAttributeView.php @@ -0,0 +1,21 @@ +channelCode = $this->provideAttribute('channel_code', $item, null); $productListItemView->mainTaxon = $this->provideAttribute('main_taxon', $item, null); - $productListItemView->attributes = $this->provideAttribute('attribute_values', $item, []); + $productAttributeValues = $this->provideAttribute('attribute_values', $item, []); + + $productListItemView->attributes = array_map(function ($attributeValue) { + $productAttributeView = new ProductAttributeView(); + $productAttributeView->value = $this->provideAttribute('value', $attributeValue, null); + $productAttributeView->code = $this->provideAttribute( + 'code', + $this->provideAttribute('attribute', $attributeValue, []), + null + ); + $productAttributeView->name = $this->provideAttribute( + 'name', + $this->provideAttribute('attribute', $attributeValue, []), + null + ); + + return $productAttributeView; + }, $productAttributeValues); $priceView = new PriceView(); $priceView->current = $this->provideAttribute( diff --git a/tests/Responses/Expected/mugs_list_page.json b/tests/Responses/Expected/mugs_list_page.json index 39e9fa6..a744123 100644 --- a/tests/Responses/Expected/mugs_list_page.json +++ b/tests/Responses/Expected/mugs_list_page.json @@ -31,17 +31,13 @@ "attributes": [ { "value": "FEIERTAGSKOLLEKTION", - "attribute": { - "code": "MUG_COLLECTION_CODE", - "name": "Mug collection" - } + "code": "MUG_COLLECTION_CODE", + "name": "Mug collection" }, { "value": "Holz", - "attribute": { - "code": "MUG_MATERIAL_CODE", - "name": "Mug material" - } + "code": "MUG_MATERIAL_CODE", + "name": "Mug material" } ], "images": [], @@ -81,17 +77,13 @@ "attributes": [ { "value": "HOLIDAY COLLECTION", - "attribute": { - "code": "MUG_COLLECTION_CODE", - "name": "Mug collection" - } + "code": "MUG_COLLECTION_CODE", + "name": "Mug collection" }, { "value": "Wood", - "attribute": { - "code": "MUG_MATERIAL_CODE", - "name": "Mug material" - } + "code": "MUG_MATERIAL_CODE", + "name": "Mug material" } ], "images": [], diff --git a/tests/Responses/Expected/product_list_page.json b/tests/Responses/Expected/product_list_page.json index dbf80fd..d5bf088 100644 --- a/tests/Responses/Expected/product_list_page.json +++ b/tests/Responses/Expected/product_list_page.json @@ -31,17 +31,13 @@ "attributes": [ { "value": "FEIERTAGSKOLLEKTION", - "attribute": { - "code": "MUG_COLLECTION_CODE", - "name": "Mug collection" - } + "code": "MUG_COLLECTION_CODE", + "name": "Mug collection" }, { "value": "Holz", - "attribute": { - "code": "MUG_MATERIAL_CODE", - "name": "Mug material" - } + "code": "MUG_MATERIAL_CODE", + "name": "Mug material" } ], "images": [], @@ -81,17 +77,13 @@ "attributes": [ { "value": "HOLIDAY COLLECTION", - "attribute": { - "code": "MUG_COLLECTION_CODE", - "name": "Mug collection" - } + "code": "MUG_COLLECTION_CODE", + "name": "Mug collection" }, { "value": "Wood", - "attribute": { - "code": "MUG_MATERIAL_CODE", - "name": "Mug material" - } + "code": "MUG_MATERIAL_CODE", + "name": "Mug material" } ], "images": [], diff --git a/tests/Responses/Expected/product_list_page_by_en_gb_channel.json b/tests/Responses/Expected/product_list_page_by_en_gb_channel.json index dbf80fd..d5bf088 100644 --- a/tests/Responses/Expected/product_list_page_by_en_gb_channel.json +++ b/tests/Responses/Expected/product_list_page_by_en_gb_channel.json @@ -31,17 +31,13 @@ "attributes": [ { "value": "FEIERTAGSKOLLEKTION", - "attribute": { - "code": "MUG_COLLECTION_CODE", - "name": "Mug collection" - } + "code": "MUG_COLLECTION_CODE", + "name": "Mug collection" }, { "value": "Holz", - "attribute": { - "code": "MUG_MATERIAL_CODE", - "name": "Mug material" - } + "code": "MUG_MATERIAL_CODE", + "name": "Mug material" } ], "images": [], @@ -81,17 +77,13 @@ "attributes": [ { "value": "HOLIDAY COLLECTION", - "attribute": { - "code": "MUG_COLLECTION_CODE", - "name": "Mug collection" - } + "code": "MUG_COLLECTION_CODE", + "name": "Mug collection" }, { "value": "Wood", - "attribute": { - "code": "MUG_MATERIAL_CODE", - "name": "Mug material" - } + "code": "MUG_MATERIAL_CODE", + "name": "Mug material" } ], "images": [],