From 3d7a5d11b283e1b3c35787e85e5a9396f9e34133 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Wed, 6 Feb 2019 13:18:12 -0600 Subject: [PATCH 1/3] GraphQL-256: [BugFix] Configurable products > Variants > Attributes are empty -- fix static tests --- .../Model/Resolver/ConfigurableVariant.php | 4 +--- .../Model/Resolver/Variant/Attributes.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php index 2a218409dcee..3e07fecb2ebe 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php @@ -71,9 +71,7 @@ public function __construct( } /** - * Fetch and format configurable variants. - * - * {@inheritDoc} + * @inheritdoc */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php index 3c30b9c102ff..d3351d216d21 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php @@ -7,6 +7,8 @@ namespace Magento\ConfigurableProductGraphQl\Model\Resolver\Variant; +use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; +use Magento\Framework\GraphQl\Query\Resolver\Value; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; use Magento\Framework\GraphQl\Config\Element\Field; use Magento\Framework\GraphQl\Query\ResolverInterface; @@ -20,6 +22,14 @@ class Attributes implements ResolverInterface * Format product's option data to conform to GraphQL schema * * {@inheritdoc} + * + * @param Field $field + * @param ContextInterface $context + * @param ResolveInfo $info + * @param array|null $value + * @param array|null $args + * @throws \Exception + * @return mixed|Value */ public function resolve( Field $field, From 41ff41da0348d95ff4959666427503d328d49217 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Wed, 6 Feb 2019 13:22:16 -0600 Subject: [PATCH 2/3] GraphQL-256: [BugFix] Configurable products > Variants > Attributes are empty -- fix static tests --- .../ConfigurableProductGraphQl/Model/Variant/Collection.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php index 5b62d5d0d143..9fda4ec0173e 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php @@ -96,7 +96,6 @@ public function addParentProduct(Product $product) : void if (!empty($this->childrenMap)) { $this->childrenMap = []; - } $this->parentProducts[$product->getId()] = $product; } From 0dd75839a6b8fcb9358329a56277069bb2e3b69f Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Thu, 7 Feb 2019 09:18:42 +0200 Subject: [PATCH 3/3] graphQl-256: fixed issue with array access --- .../Model/Resolver/Variant/Attributes.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php index d3351d216d21..b8e2ba523116 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php @@ -7,6 +7,7 @@ namespace Magento\ConfigurableProductGraphQl\Model\Resolver\Variant; +use Magento\Catalog\Model\Product; use Magento\Framework\GraphQl\Query\Resolver\ContextInterface; use Magento\Framework\GraphQl\Query\Resolver\Value; use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; @@ -45,12 +46,14 @@ public function resolve( $data = []; foreach ($value['options'] as $option) { $code = $option['attribute_code']; - if (!isset($value['product']['model'][$code])) { + /** @var Product|null $model */ + $model = $value['product']['model'] ?? null; + if (!$model || !$model->getData($code)) { continue; } foreach ($option['values'] as $optionValue) { - if ($optionValue['value_index'] != $value['product']['model'][$code]) { + if ($optionValue['value_index'] != $model->getData($code)) { continue; } $data[] = [