Skip to content
This repository has been archived by the owner on Aug 3, 2018. It is now read-only.

Commit

Permalink
Merge pull request #3 from Sylius/change-sylius-version
Browse files Browse the repository at this point in the history
Change sylius version and tweak product attributes response
  • Loading branch information
pamil authored Jun 6, 2017
2 parents 1ca29d2 + dc65b1d commit 461f271
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 88 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 21 additions & 0 deletions src/Controller/ProductAttributeView.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace Sylius\ElasticSearchPlugin\Controller;

final class ProductAttributeView
{
/**
* @var string
*/
public $code;

/**
* @var string
*/
public $name;

/**
* @var mixed
*/
public $value;
}
38 changes: 0 additions & 38 deletions src/Controller/TaxonItemView.php

This file was deleted.

22 changes: 21 additions & 1 deletion src/Factory/ProductListViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
use Porpaginas\Arrays\ArrayResult;
use Porpaginas\Result;
use Sylius\ElasticSearchPlugin\Controller\PriceView;
use Sylius\ElasticSearchPlugin\Controller\ProductAttributeView;
use Sylius\ElasticSearchPlugin\Controller\ProductListItemView;
use Sylius\ElasticSearchPlugin\Controller\ProductListView;
use Sylius\ElasticSearchPlugin\Controller\ProductVariantItemView;
use Sylius\ElasticSearchPlugin\Controller\TaxonItemView;
use Sylius\ElasticSearchPlugin\Document\AttributeValue;
use Sylius\ElasticSearchPlugin\Exception\UnsupportedFactoryMethodException;
use Sylius\ElasticSearchPlugin\Search\Criteria\Paginating;

Expand Down Expand Up @@ -55,7 +58,24 @@ private function fromArrayResult(ArrayResult $result, Paginating $paginating)
$productListItemView->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(
Expand Down
24 changes: 8 additions & 16 deletions tests/Responses/Expected/mugs_list_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -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": [],
Expand Down
24 changes: 8 additions & 16 deletions tests/Responses/Expected/product_list_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -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": [],
Expand Down
24 changes: 8 additions & 16 deletions tests/Responses/Expected/product_list_page_by_en_gb_channel.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
Expand Down Expand Up @@ -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": [],
Expand Down

0 comments on commit 461f271

Please sign in to comment.