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 #23 from lchrusciel/main-taxon-fix
Browse files Browse the repository at this point in the history
[Product] [Api] Prevent main taxon null failure
  • Loading branch information
lchrusciel authored Jun 27, 2017
2 parents 5a0797e + fece475 commit ebb400f
Show file tree
Hide file tree
Showing 5 changed files with 407 additions and 43 deletions.
5 changes: 4 additions & 1 deletion src/Factory/ProductListViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,13 @@ private function getProductView(ProductDocument $product)
$productView->channelCode = $product->getChannelCode();
$productView->images = $this->getImageViews($product->getImages());
$productView->taxons = $this->getTaxonViews($product->getTaxons());
$productView->mainTaxon = $this->getTaxonView($product->getMainTaxon());
$productView->attributes = $this->getAttributeViews($product->getAttributeValues());
$productView->variants = [$this->getVariantView($product)];

if (null !== $product->getMainTaxon()) {
$productView->mainTaxon = $this->getTaxonView($product->getMainTaxon());
}

return $productView;
}
}
71 changes: 69 additions & 2 deletions tests/DataFixtures/ORM/shop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,31 @@ Sylius\Component\Core\Model\Product:
currentTranslation: "@en_gb_mug_product_translation"
translations: ["@en_gb_mug_product_translation", "@de_de_mug_product_translation"]
mainTaxon: "@mug_taxon"
productTaxons: ["@mug_product_taxon"]
productTaxons: ["@mug_product_taxon", "@mug_brand_taxon"]
attributes:
- "@en_gb_mug_holiday_collection_value"
- "@de_de_mug_holiday_collection_value"
- "@en_gb_mug_wood_material_value"
- "@de_de_mug_wood_material_value"
variants: ["@mug_variant"]
hat:
code: "LOGAN_HAT_CODE"
channels: ["@gb_web_channel"]
currentLocale: "en_GB"
currentTranslation: "@en_gb_hat_product_translation"
translations: ["@en_gb_hat_product_translation", "@de_de_hat_product_translation"]
productTaxons: ["@hat_product_taxon", "@hat_brand_taxon"]
attributes:
- "@en_gb_mug_holiday_collection_value"
- "@de_de_mug_holiday_collection_value"
variants: ["@hat_variant"]
t_shirt:
code: "LOGAN_T_SHIRT_CODE"
channels: ["@gb_web_channel"]
currentLocale: "en_GB"
currentTranslation: "@t_shirt_translation"
mainTaxon: "@t_shirt_taxon"
productTaxons: ["@t_shirt_product_taxon"]
productTaxons: ["@t_shirt_product_taxon", "@t_shirt_brand_taxon"]
variants: ["@t_shirt_small"]

Sylius\Component\Core\Model\ProductTranslation:
Expand All @@ -71,6 +82,18 @@ Sylius\Component\Core\Model\ProductTranslation:
name: "Logan Becher"
description: <paragraph(2)>
translatable: "@mug"
en_gb_hat_product_translation:
slug: "logan-hat"
locale: "en_GB"
name: "Logan Hat"
description: <paragraph(2)>
translatable: "@hat"
de_de_hat_product_translation:
slug: "logan-hut"
locale: "de_DE"
name: "Logan Hut"
description: <paragraph(2)>
translatable: "@hat"
t_shirt_translation:
slug: "logan-t-shirt"
locale: "en_GB"
Expand All @@ -87,6 +110,14 @@ Sylius\Component\Core\Model\ProductVariant:
translations: ["@en_gb_mug_variant_translation", "@de_de_mug_variant_translation"]
channelPricings:
WEB_GB: "@gb_mug_web_channel_pricing"
hat_variant:
code: "LOGAN_HAT_CODE"
product: "@hat"
currentLocale: "en_GB"
currentTranslation: "@en_gb_hat_variant_translation"
translations: ["@en_gb_hat_variant_translation", "@de_de_hat_variant_translation"]
channelPricings:
WEB_GB: "@gb_hat_web_channel_pricing"
t_shirt_small:
code: "SMALL_LOGAN_T_SHIRT_CODE"
product: "@t_shirt"
Expand All @@ -104,6 +135,14 @@ Sylius\Component\Product\Model\ProductVariantTranslation:
locale: "de_DE"
name: "Logan Becher"
translatable: "@mug_variant"
en_gb_hat_variant_translation:
locale: "en_GB"
name: "Logan Hat"
translatable: "@hat_variant"
de_de_hat_variant_translation:
locale: "de_DE"
name: "Logan Hut"
translatable: "@hat_variant"
small_t_shirt_translation:
locale: "en_GB"
name: "Small Logan T-Shirt"
Expand All @@ -113,6 +152,9 @@ Sylius\Component\Core\Model\ChannelPricing:
gb_mug_web_channel_pricing:
channelCode: "WEB_GB"
price: 1999
gb_hat_web_channel_pricing:
channelCode: "WEB_GB"
price: 2999
gb_small_t_shirt_web_channel_pricing:
channelCode: "WEB_GB"
price: 1999
Expand All @@ -131,6 +173,13 @@ Sylius\Component\Core\Model\Taxon:
translations: ["@en_gb_mug_taxon_translation", "@de_de_mug_taxon_translation"]
parent: "@category_taxon"
root: "@category_taxon"
hat_taxon:
code: "HAT"
currentLocale: "en_GB"
currentTranslation: "@en_gb_hat_taxon_translation"
translations: ["@en_gb_hat_taxon_translation", "@de_de_hat_taxon_translation"]
parent: "@category_taxon"
root: "@category_taxon"
t_shirt_taxon:
code: "T_SHIRTS"
currentLocale: "en_GB"
Expand Down Expand Up @@ -169,6 +218,12 @@ Sylius\Component\Taxonomy\Model\TaxonTranslation:
name: "Brands"
description: <paragraph(2)>
translatable: "@brand_taxon"
en_gb_hat_taxon_translation:
slug: "categories/hats"
locale: "en_GB"
name: "Hats"
description: <paragraph(2)>
translatable: "@hat_taxon"
de_de_category_translation:
slug: "kategorien"
locale: "de_DE"
Expand All @@ -193,17 +248,29 @@ Sylius\Component\Taxonomy\Model\TaxonTranslation:
name: "Marken"
description: <paragraph(2)>
translatable: "@brand_taxon"
de_de_hat_taxon_translation:
slug: "kategorien/hut"
locale: "de_DE"
name: "Hut"
description: <paragraph(2)>
translatable: "@hat_taxon"

Sylius\Component\Core\Model\ProductTaxon:
mug_product_taxon:
product: "@mug"
taxon: "@mug_taxon"
hat_product_taxon:
product: "@hat"
taxon: "@hat_taxon"
t_shirt_product_taxon:
product: "@t_shirt"
taxon: "@t_shirt_taxon"
mug_brand_taxon:
product: "@mug"
taxon: "@brand_taxon"
hat_brand_taxon:
product: "@hat"
taxon: "@brand_taxon"
t_shirt_brand_taxon:
product: "@t_shirt"
taxon: "@brand_taxon"
Expand Down
36 changes: 34 additions & 2 deletions tests/Responses/Expected/mugs_list_page.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"position": 0,
"images": [],
"description": "@string@"
},
{
"code": "BRAND",
"slug": "brands",
"position": 1,
"images": [],
"description": "@string@"
}
],
"variants": [
Expand Down Expand Up @@ -57,6 +64,13 @@
"position": 0,
"images": [],
"description": "@string@"
},
{
"code": "BRAND",
"slug": "brands",
"position": 1,
"images": [],
"description": "@string@"
}
],
"variants": [
Expand Down Expand Up @@ -125,7 +139,7 @@
"taxon_slug": {
"state": {
"active": true,
"value": "categories/mugs",
"value": "categories\/mugs",
"urlParameters": {
"taxon_slug": "categories\/mugs"
},
Expand All @@ -139,6 +153,15 @@
"resetUrlParameters": [],
"name": "taxon_slug",
"choices": [
{
"active": false,
"default": false,
"urlParameters": {
"taxon_slug": "categories\/hats"
},
"label": "categories\/hats",
"count": 2
},
{
"active": true,
"default": false,
Expand All @@ -154,6 +177,15 @@
},
"label": "categories\/t-shirts",
"count": 2
},
{
"active": false,
"default": false,
"urlParameters": {
"taxon_slug": "brands"
},
"label": "brands",
"count": 6
}
]
},
Expand All @@ -173,7 +205,7 @@
},
"name": "price_range",
"minBounds": 1999,
"maxBounds": 1999
"maxBounds": 2999
},
"locale": {
"state": {
Expand Down
Loading

0 comments on commit ebb400f

Please sign in to comment.