From 9bee85bb51954a899517451babbe4abca90edb2e Mon Sep 17 00:00:00 2001 From: Alexandr Voronoy Date: Sat, 24 Nov 2018 23:57:57 +0200 Subject: [PATCH 01/23] Fixed variant collection --- .../Model/Resolver/ConfigurableVariant.php | 2 +- .../Model/Resolver/Variant/Attributes.php | 4 +- .../Model/Variant/Collection.php | 50 ++++++++++++++----- 3 files changed, 40 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php index a6e39f693b0e5..2e1d483c0330d 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php @@ -85,7 +85,7 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value return $this->valueFactory->create($result); } - $this->variantCollection->addParentId((int)$value[$linkField]); + $this->variantCollection->addParentId($value['model']); $fields = $this->getProductFields($info); $matchedFields = $this->attributeCollection->getRequestAttributes($fields); $this->variantCollection->addEavAttributes($matchedFields); diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php index 658e898f09f81..3c30b9c102ff4 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php @@ -35,12 +35,12 @@ public function resolve( $data = []; foreach ($value['options'] as $option) { $code = $option['attribute_code']; - if (!isset($value['product'][$code])) { + if (!isset($value['product']['model'][$code])) { continue; } foreach ($option['values'] as $optionValue) { - if ($optionValue['value_index'] != $value['product'][$code]) { + if ($optionValue['value_index'] != $value['product']['model'][$code]) { continue; } $data[] = [ diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php index 0d86e16574395..a1b2a81337186 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php @@ -47,9 +47,9 @@ class Collection private $metadataPool; /** - * @var int[] + * @var Product[] */ - private $parentIds = []; + private $parentProduct = []; /** * @var array @@ -83,18 +83,18 @@ public function __construct( } /** - * Add parent Id to collection filter + * Add parent to collection filter * - * @param int $id + * @param Product $product * @return void */ - public function addParentId(int $id) : void + public function addParentId(Product $product) : void { - if (!in_array($id, $this->parentIds) && !empty($this->childrenMap)) { + if (!in_array($product, $this->parentProduct) && !empty($this->childrenMap)) { $this->childrenMap = []; - $this->parentIds[] = $id; - } elseif (!in_array($id, $this->parentIds)) { - $this->parentIds[] = $id; + $this->parentProduct[] = $product; + } elseif (!in_array($product, $this->parentProduct)) { + $this->parentProduct[] = $product; } } @@ -130,20 +130,24 @@ public function getChildProductsByParentId(int $id) : array * Fetch all children products from parent id's. * * @return array + * @throws \Exception */ private function fetch() : array { - if (empty($this->parentIds) || !empty($this->childrenMap)) { + if (empty($this->parentProduct) || !empty($this->childrenMap)) { return $this->childrenMap; } $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); - foreach ($this->parentIds as $id) { + foreach ($this->parentProduct as $product) { + + $attributeData = $this->getAttributesCode($product); /** @var ChildCollection $childCollection */ $childCollection = $this->childCollectionFactory->create(); + $childCollection->addAttributeToSelect($attributeData); + /** @var Product $product */ - $product = $this->productFactory->create(); - $product->setData($linkField, $id); + $product->setData($linkField, $product->getId()); $childCollection->setProductFilter($product); /** @var Product $childProduct */ @@ -160,4 +164,24 @@ private function fetch() : array return $this->childrenMap; } + + /** + * Get attributes code + * + * @param \Magento\Catalog\Model\Product $currentProduct + * @return array + */ + private function getAttributesCode(Product $currentProduct): array + { + $attributeCode = []; + $allowAttributes = $currentProduct->getTypeInstance()->getConfigurableAttributes($currentProduct); + foreach ($allowAttributes as $attribute) { + $productAttribute = $attribute->getProductAttribute(); + if (!\in_array($productAttribute->getAttributeCode(), $attributeCode)) { + $attributeCode[] = $productAttribute->getAttributeCode(); + } + } + + return $attributeCode; + } } From 7efedf0ca305c8ded89780ffbaee323c204c5c19 Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Tue, 11 Dec 2018 17:36:16 +0100 Subject: [PATCH 02/23] Get downloadable products for customer --- .../Resolver/CustomerDownloadableProducts.php | 83 +++++++++++++++++++ .../GetPurchasedDownloadableProducts.php | 58 +++++++++++++ .../DownloadableGraphQl/etc/schema.graphqls | 16 ++++ 3 files changed, 157 insertions(+) create mode 100644 app/code/Magento/DownloadableGraphQl/Model/Resolver/CustomerDownloadableProducts.php create mode 100644 app/code/Magento/DownloadableGraphQl/Model/ResourceModel/GetPurchasedDownloadableProducts.php diff --git a/app/code/Magento/DownloadableGraphQl/Model/Resolver/CustomerDownloadableProducts.php b/app/code/Magento/DownloadableGraphQl/Model/Resolver/CustomerDownloadableProducts.php new file mode 100644 index 0000000000000..b981e02885665 --- /dev/null +++ b/app/code/Magento/DownloadableGraphQl/Model/Resolver/CustomerDownloadableProducts.php @@ -0,0 +1,83 @@ +getPurchasedDownloadableProducts = $getPurchasedDownloadableProducts; + $this->urlBuilder = $urlBuilder; + } + + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + $currentUserId = $context->getUserId(); + $purchasedProducts = $this->getPurchasedDownloadableProducts->execute($currentUserId); + $productsData = []; + + /* The fields names are hardcoded since there's no existing name reference in the code */ + foreach ($purchasedProducts as $purchasedProduct) { + if ($purchasedProduct['number_of_downloads_bought']) { + $remainingDownloads = $purchasedProduct['number_of_downloads_bought'] - + $purchasedProduct['number_of_downloads_used']; + } else { + $remainingDownloads = __('Unlimited'); + } + + $productsData[] = [ + 'order_increment_id' => $purchasedProduct['order_increment_id'], + 'date' => $purchasedProduct['created_at'], + 'status' => $purchasedProduct['status'], + 'download_url' => $this->urlBuilder->getUrl( + 'downloadable/download/link', + ['id' => $purchasedProduct['link_hash'], '_secure' => true] + ), + 'remaining_downloads' => $remainingDownloads + ]; + } + + return ['items' => $productsData]; + } +} diff --git a/app/code/Magento/DownloadableGraphQl/Model/ResourceModel/GetPurchasedDownloadableProducts.php b/app/code/Magento/DownloadableGraphQl/Model/ResourceModel/GetPurchasedDownloadableProducts.php new file mode 100644 index 0000000000000..e8c29e90609f8 --- /dev/null +++ b/app/code/Magento/DownloadableGraphQl/Model/ResourceModel/GetPurchasedDownloadableProducts.php @@ -0,0 +1,58 @@ +resourceConnection = $resourceConnection; + } + + /** + * Return available purchased products for customer + * + * @param int $customerId + * @return array + */ + public function execute(int $customerId): array + { + $connection = $this->resourceConnection->getConnection(); + $allowedItemsStatuses = [Item::LINK_STATUS_PENDING_PAYMENT, Item::LINK_STATUS_PAYMENT_REVIEW]; + $downloadablePurchasedTable = $connection->getTableName('downloadable_link_purchased'); + + /* The fields names are hardcoded since there's no existing name reference in the code */ + $selectQuery = $connection->select() + ->from($downloadablePurchasedTable) + ->joinLeft( + ['item' => $connection->getTableName('downloadable_link_purchased_item')], + "$downloadablePurchasedTable.purchased_id = item.purchased_id" + ) + ->where("$downloadablePurchasedTable.customer_id = ?", $customerId) + ->where('item.status NOT IN (?)', $allowedItemsStatuses); + + return $connection->fetchAll($selectQuery); + } +} diff --git a/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls b/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls index 8e877ffe8360a..2e653cc1ee7b2 100644 --- a/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls +++ b/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls @@ -1,6 +1,22 @@ # Copyright © Magento, Inc. All rights reserved. # See COPYING.txt for license details. +type Query { + customerDownloadableProducts: customerDownloadableProducts @resolver(class: "Magento\\DownloadableGraphQl\\Model\\Resolver\\CustomerDownloadableProducts") @doc(description: "The query returns the contents of a customer's downloadable products") +} + +type customerDownloadableProducts { + items: [customerDownloadableProduct] @doc(description: "List of downloadable items") +} + +type customerDownloadableProduct { + order_increment_id: String + date: String + status: String + download_url: String + remaining_downloads: String +} + type DownloadableProduct implements ProductInterface, CustomizableProductInterface @doc(description: "DownloadableProduct defines a product that the customer downloads") { downloadable_product_samples: [DownloadableProductSamples] @resolver(class: "Magento\\DownloadableGraphQl\\Model\\Resolver\\Product\\DownloadableOptions") @doc(description: "An array containing information about samples of this downloadable product.") downloadable_product_links: [DownloadableProductLinks] @resolver(class: "Magento\\DownloadableGraphQl\\Model\\Resolver\\Product\\DownloadableOptions") @doc(description: "An array containing information about the links for this downloadable product") From 556e70cd9773608045f2ea111f734bdcdb8a84fe Mon Sep 17 00:00:00 2001 From: Yaroslav Rogoza Date: Tue, 11 Dec 2018 17:42:24 +0100 Subject: [PATCH 03/23] Description adjustment --- app/code/Magento/DownloadableGraphQl/etc/schema.graphqls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls b/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls index 2e653cc1ee7b2..47380efdd1688 100644 --- a/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls +++ b/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls @@ -6,7 +6,7 @@ type Query { } type customerDownloadableProducts { - items: [customerDownloadableProduct] @doc(description: "List of downloadable items") + items: [customerDownloadableProduct] @doc(description: "List of purchased downloadable items") } type customerDownloadableProduct { From 23c9822613fb48fad2e8a8b7b5fd1f23a0657002 Mon Sep 17 00:00:00 2001 From: vitaliyboyko Date: Tue, 29 Jan 2019 21:25:15 +0200 Subject: [PATCH 04/23] graphQl-256: fixed get attribute codes method --- .../Model/Variant/Collection.php | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php index 87aff13cb9874..5b62d5d0d1431 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php @@ -9,9 +9,9 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Model\Product; -use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory; -use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection as ChildCollection; use Magento\Catalog\Model\ProductFactory; +use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection as ChildCollection; +use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory; use Magento\Framework\EntityManager\MetadataPool; use Magento\Framework\Api\SearchCriteriaBuilder; use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product as DataProvider; @@ -143,7 +143,6 @@ private function fetch() : array $linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField(); foreach ($this->parentProducts as $product) { - $attributeData = $this->getAttributesCodes($product); /** @var ChildCollection $childCollection */ $childCollection = $this->childCollectionFactory->create(); @@ -169,24 +168,20 @@ private function fetch() : array } /** - * Get attributes codes + * Get attributes code * - * @param Product $currentProduct + * @param \Magento\Catalog\Model\Product $currentProduct * @return array */ private function getAttributesCodes(Product $currentProduct): array { $attributeCodes = []; - $attributes = $currentProduct->getAttributes(); - foreach ($attributes as $key => $attribute) { - $isVisible = (int)$attribute->getIsVisibleOnFront(); - if (!$isVisible) { - continue; - } - if (!in_array($key, $attributeCodes)) { - continue; + $allowAttributes = $currentProduct->getTypeInstance()->getConfigurableAttributes($currentProduct); + foreach ($allowAttributes as $attribute) { + $productAttribute = $attribute->getProductAttribute(); + if (!\in_array($productAttribute->getAttributeCode(), $attributeCodes)) { + $attributeCodes[] = $productAttribute->getAttributeCode(); } - $attributeCodes[] = $key; } return $attributeCodes; From cda1eff78bd2689539e867525bfef4a1f7b81d8b Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 30 Jan 2019 14:17:43 +0200 Subject: [PATCH 05/23] graphQl-256: added additional check to test --- .../GraphQl/ConfigurableProduct/ConfigurableProductViewTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductViewTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductViewTest.php index 735ae7fff646b..d2d7a3d5efc32 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductViewTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductViewTest.php @@ -407,6 +407,7 @@ private function assertConfigurableVariants($actualResponse) $variantArray['product']['price'] ); $configurableOptions = $this->getConfigurableOptions(); + $this->assertEquals(1, count($variantArray['attributes'])); foreach ($variantArray['attributes'] as $attribute) { $hasAssertion = false; foreach ($configurableOptions as $option) { From 31dd5b227bacc8d36a0158b3059845ad0cbe31af Mon Sep 17 00:00:00 2001 From: Patrick McLain Date: Fri, 4 Jan 2019 23:19:40 -0500 Subject: [PATCH 06/23] Add queries for directory information --- .../Model/Resolver/Countries.php | 63 ++++++++++++++++ .../Model/Resolver/Country.php | 67 +++++++++++++++++ .../Model/Resolver/Currency.php | 59 +++++++++++++++ app/code/Magento/DirectoryGraphQl/README.md | 4 + .../DirectoryGraphQl/Test/Mftf/README.md | 3 + .../Magento/DirectoryGraphQl/composer.json | 25 +++++++ .../Magento/DirectoryGraphQl/etc/module.xml | 15 ++++ .../DirectoryGraphQl/etc/schema.graphqls | 37 ++++++++++ .../Magento/DirectoryGraphQl/registration.php | 9 +++ composer.json | 1 + composer.lock | 6 +- .../GraphQl/Directory/CountriesTest.php | 45 +++++++++++ .../Magento/GraphQl/Directory/CountryTest.php | 74 +++++++++++++++++++ .../GraphQl/Directory/CurrencyTest.php | 44 +++++++++++ 14 files changed, 449 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/DirectoryGraphQl/Model/Resolver/Countries.php create mode 100644 app/code/Magento/DirectoryGraphQl/Model/Resolver/Country.php create mode 100644 app/code/Magento/DirectoryGraphQl/Model/Resolver/Currency.php create mode 100644 app/code/Magento/DirectoryGraphQl/README.md create mode 100644 app/code/Magento/DirectoryGraphQl/Test/Mftf/README.md create mode 100644 app/code/Magento/DirectoryGraphQl/composer.json create mode 100644 app/code/Magento/DirectoryGraphQl/etc/module.xml create mode 100644 app/code/Magento/DirectoryGraphQl/etc/schema.graphqls create mode 100644 app/code/Magento/DirectoryGraphQl/registration.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CountriesTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CountryTest.php create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CurrencyTest.php diff --git a/app/code/Magento/DirectoryGraphQl/Model/Resolver/Countries.php b/app/code/Magento/DirectoryGraphQl/Model/Resolver/Countries.php new file mode 100644 index 0000000000000..dc788801f3e6a --- /dev/null +++ b/app/code/Magento/DirectoryGraphQl/Model/Resolver/Countries.php @@ -0,0 +1,63 @@ +dataProcessor = $dataProcessor; + $this->countryInformationAcquirer = $countryInformationAcquirer; + } + + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + $countries = $this->countryInformationAcquirer->getCountriesInfo(); + + $output = []; + foreach ($countries as $country) { + $output[] = $this->dataProcessor->buildOutputDataArray($country, CountryInformationInterface::class); + } + + return $output; + } +} diff --git a/app/code/Magento/DirectoryGraphQl/Model/Resolver/Country.php b/app/code/Magento/DirectoryGraphQl/Model/Resolver/Country.php new file mode 100644 index 0000000000000..ea39f12a7bcb5 --- /dev/null +++ b/app/code/Magento/DirectoryGraphQl/Model/Resolver/Country.php @@ -0,0 +1,67 @@ +dataProcessor = $dataProcessor; + $this->countryInformationAcquirer = $countryInformationAcquirer; + } + + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + try { + $country = $this->countryInformationAcquirer->getCountryInfo($args['id']); + } catch (NoSuchEntityException $exception) { + throw new GraphQlNoSuchEntityException(__($exception->getMessage()), $exception); + } + + return $this->dataProcessor->buildOutputDataArray( + $country, + CountryInformationInterface::class + ); + } +} diff --git a/app/code/Magento/DirectoryGraphQl/Model/Resolver/Currency.php b/app/code/Magento/DirectoryGraphQl/Model/Resolver/Currency.php new file mode 100644 index 0000000000000..fb2db6c312ac1 --- /dev/null +++ b/app/code/Magento/DirectoryGraphQl/Model/Resolver/Currency.php @@ -0,0 +1,59 @@ +dataProcessor = $dataProcessor; + $this->currencyInformationAcquirer = $currencyInformationAcquirer; + } + + /** + * @inheritdoc + */ + public function resolve( + Field $field, + $context, + ResolveInfo $info, + array $value = null, + array $args = null + ) { + return $this->dataProcessor->buildOutputDataArray( + $this->currencyInformationAcquirer->getCurrencyInfo(), + CurrencyInformationInterface::class + ); + } +} diff --git a/app/code/Magento/DirectoryGraphQl/README.md b/app/code/Magento/DirectoryGraphQl/README.md new file mode 100644 index 0000000000000..1a5c969b39edf --- /dev/null +++ b/app/code/Magento/DirectoryGraphQl/README.md @@ -0,0 +1,4 @@ +# DirectoryGraphQl + +**DirectoryGraphQl** provides type and resolver information for the GraphQl module +to generate directory information endpoints. diff --git a/app/code/Magento/DirectoryGraphQl/Test/Mftf/README.md b/app/code/Magento/DirectoryGraphQl/Test/Mftf/README.md new file mode 100644 index 0000000000000..8e2e188c1fe97 --- /dev/null +++ b/app/code/Magento/DirectoryGraphQl/Test/Mftf/README.md @@ -0,0 +1,3 @@ +# Directory Graph Ql Functional Tests + +The Functional Test Module for **Magento Directory Graph Ql** module. diff --git a/app/code/Magento/DirectoryGraphQl/composer.json b/app/code/Magento/DirectoryGraphQl/composer.json new file mode 100644 index 0000000000000..0a81102a92767 --- /dev/null +++ b/app/code/Magento/DirectoryGraphQl/composer.json @@ -0,0 +1,25 @@ +{ + "name": "magento/module-directory-graph-ql", + "description": "N/A", + "type": "magento2-module", + "require": { + "php": "~7.1.3||~7.2.0", + "magento/module-directory": "*", + "magento/framework": "*" + }, + "suggest": { + "magento/module-graph-ql": "*" + }, + "license": [ + "OSL-3.0", + "AFL-3.0" + ], + "autoload": { + "files": [ + "registration.php" + ], + "psr-4": { + "Magento\\DirectoryGraphQl\\": "" + } + } +} diff --git a/app/code/Magento/DirectoryGraphQl/etc/module.xml b/app/code/Magento/DirectoryGraphQl/etc/module.xml new file mode 100644 index 0000000000000..8c2bb4325b611 --- /dev/null +++ b/app/code/Magento/DirectoryGraphQl/etc/module.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls b/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls new file mode 100644 index 0000000000000..40ef6975fad8b --- /dev/null +++ b/app/code/Magento/DirectoryGraphQl/etc/schema.graphqls @@ -0,0 +1,37 @@ +# Copyright © Magento, Inc. All rights reserved. +# See COPYING.txt for license details. + +type Query { + currency: Currency @resolver(class: "Magento\\DirectoryGraphQl\\Model\\Resolver\\Currency") @doc(description: "The currency query returns information about store currency.") + countries: [Country] @resolver(class: "Magento\\DirectoryGraphQl\\Model\\Resolver\\Countries") @doc(description: "The countries query provides information for all countries.") + country (id: String): Country @resolver(class: "Magento\\DirectoryGraphQl\\Model\\Resolver\\Country") @doc(description: "The countries query provides information for a single country.") +} + +type Currency { + base_currency_code: String + base_currency_symbol: String + default_display_currecy_code: String + default_display_currecy_symbol: String + available_currency_codes: [String] + exchange_rates: [ExchangeRate] +} + +type ExchangeRate { + currency_to: String + rate: Float +} + +type Country { + id: String + two_letter_abbreviation: String + three_letter_abbreviation: String + full_name_locale: String + full_name_english: String + available_regions: [Region] +} + +type Region { + id: Int + code: String + name: String +} diff --git a/app/code/Magento/DirectoryGraphQl/registration.php b/app/code/Magento/DirectoryGraphQl/registration.php new file mode 100644 index 0000000000000..6bb7fd8d4e44d --- /dev/null +++ b/app/code/Magento/DirectoryGraphQl/registration.php @@ -0,0 +1,9 @@ +graphQlQuery($query); + $this->assertArrayHasKey('countries', $result); + $this->assertArrayHasKey('id', $result['countries'][0]); + $this->assertArrayHasKey('two_letter_abbreviation', $result['countries'][0]); + $this->assertArrayHasKey('three_letter_abbreviation', $result['countries'][0]); + $this->assertArrayHasKey('full_name_locale', $result['countries'][0]); + $this->assertArrayHasKey('full_name_english', $result['countries'][0]); + $this->assertArrayHasKey('available_regions', $result['countries'][0]); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CountryTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CountryTest.php new file mode 100644 index 0000000000000..dda5ef342247d --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CountryTest.php @@ -0,0 +1,74 @@ +graphQlQuery($query); + $this->assertArrayHasKey('country', $result); + $this->assertArrayHasKey('id', $result['country']); + $this->assertArrayHasKey('two_letter_abbreviation', $result['country']); + $this->assertArrayHasKey('three_letter_abbreviation', $result['country']); + $this->assertArrayHasKey('full_name_locale', $result['country']); + $this->assertArrayHasKey('full_name_english', $result['country']); + $this->assertArrayHasKey('available_regions', $result['country']); + $this->assertArrayHasKey('id', $result['country']['available_regions'][0]); + $this->assertArrayHasKey('code', $result['country']['available_regions'][0]); + $this->assertArrayHasKey('name', $result['country']['available_regions'][0]); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage GraphQL response contains errors: The country isn't available. + */ + public function testGetCountryNotFoundException() + { + $query = <<graphQlQuery($query); + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CurrencyTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CurrencyTest.php new file mode 100644 index 0000000000000..1ff0b53dda0bb --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Directory/CurrencyTest.php @@ -0,0 +1,44 @@ +graphQlQuery($query); + $this->assertArrayHasKey('currency', $result); + $this->assertArrayHasKey('base_currency_code', $result['currency']); + $this->assertArrayHasKey('base_currency_symbol', $result['currency']); + $this->assertArrayHasKey('default_display_currecy_code', $result['currency']); + $this->assertArrayHasKey('default_display_currecy_symbol', $result['currency']); + $this->assertArrayHasKey('available_currency_codes', $result['currency']); + $this->assertArrayHasKey('exchange_rates', $result['currency']); + } +} From d9eb81ef9ca1ced55730062380d7a5a91522680d Mon Sep 17 00:00:00 2001 From: Govind Sharma Date: Mon, 4 Feb 2019 19:25:01 +0530 Subject: [PATCH 07/23] Update DownloadableProductTypeResolver.php --- .../Model/DownloadableProductTypeResolver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php b/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php index 59c007d910764..15c9ff24635d3 100644 --- a/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php +++ b/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php @@ -8,6 +8,7 @@ namespace Magento\DownloadableGraphQl\Model; use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface; +use Magento\Downloadable\Model\Product\Type as Type; /** * {@inheritdoc} @@ -19,7 +20,7 @@ class DownloadableProductTypeResolver implements TypeResolverInterface */ public function resolveType(array $data) : string { - if (isset($data['type_id']) && $data['type_id'] == 'downloadable') { + if (isset($data['type_id']) && $data['type_id'] == Type::TYPE_DOWNLOADABLE) { return 'DownloadableProduct'; } return ''; From 0095028d46b8f2193402af899eeb6b50ad15213f Mon Sep 17 00:00:00 2001 From: Govind Sharma Date: Mon, 4 Feb 2019 19:27:21 +0530 Subject: [PATCH 08/23] Update BundleProductTypeResolver.php --- .../Magento/BundleGraphQl/Model/BundleProductTypeResolver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php b/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php index b904d3f62a748..de4a38164f45f 100644 --- a/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php +++ b/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php @@ -8,6 +8,7 @@ namespace Magento\BundleGraphQl\Model; use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface; +use Magento\Bundle\Model\Product\Type as Type; /** * {@inheritdoc} @@ -19,7 +20,7 @@ class BundleProductTypeResolver implements TypeResolverInterface */ public function resolveType(array $data) : string { - if (isset($data['type_id']) && $data['type_id'] == 'bundle') { + if (isset($data['type_id']) && $data['type_id'] == Type::TYPE_CODE) { return 'BundleProduct'; } return ''; From 9769418788445f90e625c2374d9c934e8980f241 Mon Sep 17 00:00:00 2001 From: Govind Sharma Date: Mon, 4 Feb 2019 19:29:28 +0530 Subject: [PATCH 09/23] Update GroupedProductTypeResolver.php --- .../Model/GroupedProductTypeResolver.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php b/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php index 087cf10c8d6bb..cc570ff761617 100644 --- a/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php +++ b/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php @@ -8,7 +8,7 @@ namespace Magento\GroupedProductGraphQl\Model; use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface; - +use Magento\GroupedProduct\Model\Product\Type\Grouped as Type; /** * {@inheritdoc} */ @@ -19,7 +19,7 @@ class GroupedProductTypeResolver implements TypeResolverInterface */ public function resolveType(array $data) : string { - if (isset($data['type_id']) && $data['type_id'] == 'grouped') { + if (isset($data['type_id']) && $data['type_id'] == Type::TYPE_CODE) { return 'GroupedProduct'; } return ''; From 4c2072a0a5ff8a4a01ced50002fb042399fee11c Mon Sep 17 00:00:00 2001 From: Govind Sharma Date: Mon, 4 Feb 2019 21:29:25 +0530 Subject: [PATCH 10/23] Update BundleProductTypeResolver.php --- .../Magento/BundleGraphQl/Model/BundleProductTypeResolver.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php b/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php index de4a38164f45f..81e4e1ec8d874 100644 --- a/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php +++ b/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php @@ -15,13 +15,15 @@ */ class BundleProductTypeResolver implements TypeResolverInterface { + const BUNDLE_PRODUCT = 'BundleProduct'; + /** * {@inheritdoc} */ public function resolveType(array $data) : string { if (isset($data['type_id']) && $data['type_id'] == Type::TYPE_CODE) { - return 'BundleProduct'; + return self::BUNDLE_PRODUCT; } return ''; } From 274c885f6c99b088ce81e7d5c45b62dba120172e Mon Sep 17 00:00:00 2001 From: Govind Sharma Date: Mon, 4 Feb 2019 21:31:20 +0530 Subject: [PATCH 11/23] Update DownloadableProductTypeResolver.php --- .../Model/DownloadableProductTypeResolver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php b/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php index 15c9ff24635d3..60dc78ed30404 100644 --- a/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php +++ b/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php @@ -15,13 +15,14 @@ */ class DownloadableProductTypeResolver implements TypeResolverInterface { + const DOWNLOADABLE_PRODUCT = 'DownloadableProduct'; /** * {@inheritdoc} */ public function resolveType(array $data) : string { if (isset($data['type_id']) && $data['type_id'] == Type::TYPE_DOWNLOADABLE) { - return 'DownloadableProduct'; + return self::DOWNLOADABLE_PRODUCT; } return ''; } From 821c1abd3bb64af4fde79d71cbe64ff8d08c2f02 Mon Sep 17 00:00:00 2001 From: Govind Sharma Date: Mon, 4 Feb 2019 21:32:52 +0530 Subject: [PATCH 12/23] Update GroupedProductTypeResolver.php --- .../GroupedProductGraphQl/Model/GroupedProductTypeResolver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php b/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php index cc570ff761617..85f74a9a8df1e 100644 --- a/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php +++ b/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php @@ -14,13 +14,14 @@ */ class GroupedProductTypeResolver implements TypeResolverInterface { + const GROUPED_PRODUCT = 'GroupedProduct'; /** * {@inheritdoc} */ public function resolveType(array $data) : string { if (isset($data['type_id']) && $data['type_id'] == Type::TYPE_CODE) { - return 'GroupedProduct'; + return self::GROUPED_PRODUCT; } return ''; } From 1bbeb21dfdf2a54a298556f556dec7dec7ae4d7e Mon Sep 17 00:00:00 2001 From: RomanKis Date: Tue, 5 Feb 2019 11:19:00 +0200 Subject: [PATCH 13/23] graphQl-255: Test coverage for PR-243 --- .../Catalog/CategoryProductsCountTest.php | 150 +++++++++++++++++- 1 file changed, 144 insertions(+), 6 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsCountTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsCountTest.php index eddd456a7b866..46309c6d97dfa 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsCountTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsCountTest.php @@ -7,11 +7,16 @@ namespace Magento\GraphQl\Catalog; -use Magento\TestFramework\TestCase\GraphQlAbstract; +use Magento\Catalog\Api\CategoryLinkManagementInterface; use Magento\Catalog\Api\ProductRepositoryInterface; -use Magento\TestFramework\Helper\Bootstrap; -use Magento\Catalog\Model\Product\Visibility; use Magento\Catalog\Model\Product\Attribute\Source\Status as productStatus; +use Magento\Catalog\Model\Product\Visibility; +use Magento\CatalogInventory\Model\Configuration; +use Magento\Config\Model\ResourceModel\Config; +use Magento\Framework\App\Config\ReinitableConfigInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\TestFramework\ObjectManager; +use Magento\TestFramework\TestCase\GraphQlAbstract; /** * Class CategoryProductsCountTest @@ -25,10 +30,39 @@ class CategoryProductsCountTest extends GraphQlAbstract */ private $productRepository; + /** + * @var Config $config + */ + private $resourceConfig; + + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + + /** + * @var ReinitableConfigInterface + */ + private $reinitConfig; + + /** + * @var CategoryLinkManagementInterface + */ + private $categoryLinkManagement; + + /** + * @inheritdoc + */ protected function setUp() { - $objectManager = Bootstrap::getObjectManager(); + parent::setUp(); + + $objectManager = ObjectManager::getInstance(); $this->productRepository = $objectManager->create(ProductRepositoryInterface::class); + $this->resourceConfig = $objectManager->get(Config::class); + $this->scopeConfig = $objectManager->get(ScopeConfigInterface::class); + $this->reinitConfig = $objectManager->get(ReinitableConfigInterface::class); + $this->categoryLinkManagement = $objectManager->get(CategoryLinkManagementInterface::class); } /** @@ -82,6 +116,15 @@ public function testCategoryWithInvisibleProduct() public function testCategoryWithOutOfStockProductManageStockEnabled() { $categoryId = 2; + $sku = 'simple-out-of-stock'; + $manageStock = $this->scopeConfig->getValue(Configuration::XML_PATH_MANAGE_STOCK); + + $this->resourceConfig->saveConfig(Configuration::XML_PATH_MANAGE_STOCK, 1); + $this->reinitConfig->reinit(); + + // need to resave product to reindex it with new configuration. + $product = $this->productRepository->get($sku); + $this->productRepository->save($product); $query = <<graphQlQuery($query); + $this->resourceConfig->saveConfig(Configuration::XML_PATH_MANAGE_STOCK, $manageStock); + $this->reinitConfig->reinit(); + self::assertEquals(0, $response['category']['product_count']); } /** - * @magentoApiDataFixture Magento/Catalog/_files/category_product.php + * @magentoApiDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php */ public function testCategoryWithOutOfStockProductManageStockDisabled() { - $categoryId = 333; + $categoryId = 2; + $sku = 'simple-out-of-stock'; + $manageStock = $this->scopeConfig->getValue(Configuration::XML_PATH_MANAGE_STOCK); + + $this->resourceConfig->saveConfig(Configuration::XML_PATH_MANAGE_STOCK, 0); + $this->reinitConfig->reinit(); + + // need to resave product to reindex it with new configuration. + $product = $this->productRepository->get($sku); + $this->productRepository->save($product); $query = <<graphQlQuery($query); + $this->resourceConfig->saveConfig(Configuration::XML_PATH_MANAGE_STOCK, $manageStock); + $this->reinitConfig->reinit(); + self::assertEquals(1, $response['category']['product_count']); } @@ -140,4 +198,84 @@ public function testCategoryWithDisabledProduct() self::assertEquals(0, $response['category']['product_count']); } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/product_simple_out_of_stock.php + */ + public function testCategoryWithOutOfStockProductShowOutOfStockProduct() + { + $showOutOfStock = $this->scopeConfig->getValue(Configuration::XML_PATH_SHOW_OUT_OF_STOCK); + + $this->resourceConfig->saveConfig(Configuration::XML_PATH_SHOW_OUT_OF_STOCK, 1); + $this->reinitConfig->reinit(); + + $categoryId = 2; + + $query = <<graphQlQuery($query); + + $this->resourceConfig->saveConfig(Configuration::XML_PATH_SHOW_OUT_OF_STOCK, $showOutOfStock); + $this->reinitConfig->reinit(); + + self::assertEquals(1, $response['category']['product_count']); + } + + /** + * @magentoApiDataFixture Magento/CatalogRule/_files/configurable_product.php + */ + public function testCategoryWithConfigurableChildrenOutOfStock() + { + $categoryId = 2; + + $this->categoryLinkManagement->assignProductToCategories('configurable', [$categoryId]); + + foreach (['simple1', 'simple2'] as $sku) { + $product = $this->productRepository->get($sku); + $product->setStockData(['is_in_stock' => 0]); + $this->productRepository->save($product); + } + + $query = <<graphQlQuery($query); + + self::assertEquals(0, $response['category']['product_count']); + } + + /** + * @magentoApiDataFixture Magento/Catalog/_files/category_product.php + */ + public function testCategoryWithProductNotAvailableOnWebsite() + { + $product = $this->productRepository->getById(333); + $product->setWebsiteIds([]); + $this->productRepository->save($product); + + $categoryId = 333; + + $query = <<graphQlQuery($query); + + self::assertEquals(0, $response['category']['product_count']); + } } From 9fa6a28ae6f46fa85a4ea0b8c0c5b24e0cba92b4 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 5 Feb 2019 10:58:26 -0600 Subject: [PATCH 14/23] GraphQl-42: [My Account] My Downloadable Products --- app/code/Magento/DownloadableGraphQl/etc/schema.graphqls | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls b/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls index 47380efdd1688..e2cacdf7608d6 100644 --- a/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls +++ b/app/code/Magento/DownloadableGraphQl/etc/schema.graphqls @@ -2,14 +2,14 @@ # See COPYING.txt for license details. type Query { - customerDownloadableProducts: customerDownloadableProducts @resolver(class: "Magento\\DownloadableGraphQl\\Model\\Resolver\\CustomerDownloadableProducts") @doc(description: "The query returns the contents of a customer's downloadable products") + customerDownloadableProducts: CustomerDownloadableProducts @resolver(class: "Magento\\DownloadableGraphQl\\Model\\Resolver\\CustomerDownloadableProducts") @doc(description: "The query returns the contents of a customer's downloadable products") } -type customerDownloadableProducts { - items: [customerDownloadableProduct] @doc(description: "List of purchased downloadable items") +type CustomerDownloadableProducts { + items: [CustomerDownloadableProduct] @doc(description: "List of purchased downloadable items") } -type customerDownloadableProduct { +type CustomerDownloadableProduct { order_increment_id: String date: String status: String From cc559341a4f21808d5feb9432f6d34b19900a264 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 5 Feb 2019 12:01:19 -0600 Subject: [PATCH 15/23] GraphQL-334: Changed hard coded values according to TYPE_CODE -- fix static tests --- .../Model/BundleProductTypeResolver.php | 4 ++-- .../Model/Resolver/ConfigurableVariant.php | 4 +--- .../Model/Resolver/Variant/Attributes.php | 12 +++++++++++- .../Model/Variant/Collection.php | 1 - .../Model/DownloadableProductTypeResolver.php | 4 ++-- .../Model/GroupedProductTypeResolver.php | 5 +++-- 6 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php b/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php index 81e4e1ec8d874..211d625fbc754 100644 --- a/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php +++ b/app/code/Magento/BundleGraphQl/Model/BundleProductTypeResolver.php @@ -11,14 +11,14 @@ use Magento\Bundle\Model\Product\Type as Type; /** - * {@inheritdoc} + * @inheritdoc */ class BundleProductTypeResolver implements TypeResolverInterface { const BUNDLE_PRODUCT = 'BundleProduct'; /** - * {@inheritdoc} + * @inheritdoc */ public function resolveType(array $data) : string { diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/ConfigurableVariant.php index 2a218409dcee6..3e07fecb2ebe7 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 3c30b9c102ff4..40638fe2f0cd7 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; @@ -19,7 +21,15 @@ class Attributes implements ResolverInterface /** * Format product's option data to conform to GraphQL schema * - * {@inheritdoc} + * @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, diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php index 5b62d5d0d1431..9fda4ec0173ec 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; } diff --git a/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php b/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php index 60dc78ed30404..4bef5d3d57b0b 100644 --- a/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php +++ b/app/code/Magento/DownloadableGraphQl/Model/DownloadableProductTypeResolver.php @@ -11,13 +11,13 @@ use Magento\Downloadable\Model\Product\Type as Type; /** - * {@inheritdoc} + * @inheritdoc */ class DownloadableProductTypeResolver implements TypeResolverInterface { const DOWNLOADABLE_PRODUCT = 'DownloadableProduct'; /** - * {@inheritdoc} + * @inheritdoc */ public function resolveType(array $data) : string { diff --git a/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php b/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php index 85f74a9a8df1e..8818766692fe2 100644 --- a/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php +++ b/app/code/Magento/GroupedProductGraphQl/Model/GroupedProductTypeResolver.php @@ -9,14 +9,15 @@ use Magento\Framework\GraphQl\Query\Resolver\TypeResolverInterface; use Magento\GroupedProduct\Model\Product\Type\Grouped as Type; + /** - * {@inheritdoc} + * @inheritdoc */ class GroupedProductTypeResolver implements TypeResolverInterface { const GROUPED_PRODUCT = 'GroupedProduct'; /** - * {@inheritdoc} + * @inheritdoc */ public function resolveType(array $data) : string { From 71e751d7e39817a7b29da20077346622bbc0a16c Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Tue, 5 Feb 2019 13:32:00 -0600 Subject: [PATCH 16/23] GraphQL-334: Changed hard coded values according to TYPE_CODE -- fix static tests --- .../Model/Resolver/Variant/Attributes.php | 4 ++-- 1 file changed, 2 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 40638fe2f0cd7..9f8f728a85eaa 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Resolver/Variant/Attributes.php @@ -19,10 +19,10 @@ class Attributes implements ResolverInterface { /** - * Format product's option data to conform to GraphQL schema - * * @inheritdoc * + * Format product's option data to conform to GraphQL schema + * * @param Field $field * @param ContextInterface $context * @param ResolveInfo $info From 62fd888833477a6bb35623e333f0e8798afb293f Mon Sep 17 00:00:00 2001 From: Lyzun Oleksandr Date: Wed, 6 Feb 2019 12:09:22 +0100 Subject: [PATCH 17/23] Show only active categories --- .../Products/DataProvider/CategoryTree.php | 12 +++- .../ExtractDataFromCategoryTree.php | 71 +++++++++++++++---- .../Magento/GraphQl/Catalog/CategoryTest.php | 71 +++++++++++-------- .../Magento/Catalog/_files/categories.php | 2 +- 4 files changed, 113 insertions(+), 43 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php index f2634574a2d15..fc5a563c82b4e 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/CategoryTree.php @@ -101,11 +101,21 @@ public function getTree(ResolveInfo $resolveInfo, int $rootCategoryId): \Iterato $collection->addFieldToFilter('level', ['gt' => $level]); $collection->addFieldToFilter('level', ['lteq' => $level + $depth - self::DEPTH_OFFSET]); + $collection->addAttributeToFilter('is_active', 1, "left"); $collection->setOrder('level'); + $collection->setOrder( + 'position', + $collection::SORT_ORDER_DESC + ); $collection->getSelect()->orWhere( - $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() . ' = ?', + $collection->getSelect() + ->getConnection() + ->quoteIdentifier( + 'e.' . $this->metadata->getMetadata(CategoryInterface::class)->getIdentifierField() + ) . ' = ?', $rootCategoryId ); + return $collection->getIterator(); } diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php index ac8d5709c85b3..47675edcbcae9 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php @@ -4,12 +4,9 @@ * See COPYING.txt for license details. */ declare(strict_types=1); - namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider; - use Magento\CatalogGraphQl\Model\Category\Hydrator; use Magento\Catalog\Api\Data\CategoryInterface; - /** * Extract data from category tree */ @@ -19,7 +16,14 @@ class ExtractDataFromCategoryTree * @var Hydrator */ private $categoryHydrator; - + /** + * @var CategoryInterface; + */ + private $iteratingCategory; + /** + * @var int + */ + private $startCategoryFetchLevel = 1; /** * @param Hydrator $categoryHydrator */ @@ -28,7 +32,6 @@ public function __construct( ) { $this->categoryHydrator = $categoryHydrator; } - /** * Extract data from category tree * @@ -42,14 +45,58 @@ public function execute(\Iterator $iterator): array /** @var CategoryInterface $category */ $category = $iterator->current(); $iterator->next(); - $nextCategory = $iterator->current(); - $tree[$category->getId()] = $this->categoryHydrator->hydrateCategory($category); - $tree[$category->getId()]['model'] = $category; - if ($nextCategory && (int) $nextCategory->getLevel() !== (int) $category->getLevel()) { - $tree[$category->getId()]['children'] = $this->execute($iterator); + $pathElements = explode("/", $category->getPath()); + if (empty($tree)) { + $this->startCategoryFetchLevel = count($pathElements) - 1; + } + $this->iteratingCategory = $category; + $currentLevelTree = $this->explodePathToArray($pathElements, $this->startCategoryFetchLevel); + if (empty($tree)) { + $tree = $currentLevelTree; } + $tree = $this->mergeCategoriesTrees($currentLevelTree, $tree); + } + return $tree; + } + /** + * Merge together complex categories trees + * + * @param array $tree1 + * @param array $tree2 + * @return array + */ + private function mergeCategoriesTrees(array &$tree1, array &$tree2): array + { + $mergedTree = $tree1; + foreach ($tree2 as $currentKey => &$value) { + if (is_array($value) && isset($mergedTree[$currentKey]) && is_array($mergedTree[$currentKey])) { + $mergedTree[$currentKey] = $this->mergeCategoriesTrees($mergedTree[$currentKey], $value); + } else { + $mergedTree[$currentKey] = $value; + } + } + return $mergedTree; + } + /** + * Recursive method to generate tree for one category path + * + * @param array $pathElements + * @param int $index + * @return array + */ + private function explodePathToArray(array $pathElements, int $index): array + { + $tree = []; + $tree[$pathElements[$index]]['id'] = $pathElements[$index]; + if ($index === count($pathElements) - 1) { + $tree[$pathElements[$index]] = $this->categoryHydrator->hydrateCategory($this->iteratingCategory); + $tree[$pathElements[$index]]['model'] = $this->iteratingCategory; + } + $currentIndex = $index; + $index++; + if (isset($pathElements[$index])) { + $tree[$pathElements[$currentIndex]]['children'] = $this->explodePathToArray($pathElements, $index); } - return $tree; } -} +} \ No newline at end of file diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php index 54e98367ab8ca..e40e9e3c52ec1 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php @@ -4,9 +4,7 @@ * See COPYING.txt for license details. */ declare(strict_types=1); - namespace Magento\GraphQl\Catalog; - use Magento\Catalog\Api\Data\CategoryInterface; use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection; use Magento\Framework\DataObject; @@ -14,19 +12,16 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\TestFramework\ObjectManager; - class CategoryTest extends GraphQlAbstract { /** * @var \Magento\TestFramework\ObjectManager */ private $objectManager; - protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); } - /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Catalog/_files/categories.php @@ -70,21 +65,19 @@ public function testCategoriesTree() } } QUERY; - // get customer ID token /** @var \Magento\Integration\Api\CustomerTokenServiceInterface $customerTokenService */ $customerTokenService = $this->objectManager->create( \Magento\Integration\Api\CustomerTokenServiceInterface::class ); $customerToken = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); - $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; $response = $this->graphQlQuery($query, [], '', $headerMap); $responseDataObject = new DataObject($response); //Some sort of smoke testing self::assertEquals( - 'Ololo', - $responseDataObject->getData('category/children/7/children/1/description') + 'Its a description of Test Category 1.2', + $responseDataObject->getData('category/children/0/children/1/description') ); self::assertEquals( 'default-category', @@ -99,19 +92,53 @@ public function testCategoriesTree() $responseDataObject->getData('category/children/0/default_sort_by') ); self::assertCount( - 8, + 7, $responseDataObject->getData('category/children') ); self::assertCount( 2, - $responseDataObject->getData('category/children/7/children') + $responseDataObject->getData('category/children/0/children') ); self::assertEquals( - 5, - $responseDataObject->getData('category/children/7/children/1/children/0/id') + 13, + $responseDataObject->getData('category/children/0/children/1/id') + ); + } + /** + * @magentoApiDataFixture Magento/Customer/_files/customer.php + * @magentoApiDataFixture Magento/Catalog/_files/categories.php + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testGetCategoryById() + { + $rootCategoryId = 13; + $query = <<objectManager->create( + \Magento\Integration\Api\CustomerTokenServiceInterface::class + ); + $customerToken = $customerTokenService->createCustomerAccessToken('customer@example.com', 'password'); + $headerMap = ['Authorization' => 'Bearer ' . $customerToken]; + $response = $this->graphQlQuery($query, [], '', $headerMap); + $responseDataObject = new DataObject($response); + //Some sort of smoke testing + self::assertEquals( + 'Category 1.2', + $responseDataObject->getData('category/name') + ); + self::assertEquals( + 13, + $responseDataObject->getData('category/id') ); } - /** * @magentoApiDataFixture Magento/Catalog/_files/categories.php * @SuppressWarnings(PHPMD.ExcessiveMethodLength) @@ -259,17 +286,14 @@ public function testCategoryProducts() } } QUERY; - $response = $this->graphQlQuery($query); $this->assertArrayHasKey('products', $response['category']); $this->assertArrayHasKey('total_count', $response['category']['products']); $this->assertGreaterThanOrEqual(1, $response['category']['products']['total_count']); $this->assertEquals(1, $response['category']['products']['page_info']['current_page']); $this->assertEquals(20, $response['category']['products']['page_info']['page_size']); - $this->assertArrayHasKey('sku', $response['category']['products']['items'][0]); $firstProductSku = $response['category']['products']['items'][0]['sku']; - /** * @var ProductRepositoryInterface $productRepository */ @@ -279,7 +303,6 @@ public function testCategoryProducts() $this->assertAttributes($response['category']['products']['items'][0]); $this->assertWebsites($firstProduct, $response['category']['products']['items'][0]['websites']); } - /** * @magentoApiDataFixture Magento/Catalog/_files/categories.php */ @@ -291,9 +314,7 @@ public function testAnchorCategory() /** @var CategoryInterface $category */ $category = $categoryCollection->getFirstItem(); $categoryId = $category->getId(); - $this->assertNotEmpty($categoryId, "Preconditions failed: category is not available."); - $query = <<graphQlQuery($query); $expectedResponse = [ 'category' => [ @@ -324,14 +344,12 @@ public function testAnchorCategory() ]; $this->assertEquals($expectedResponse, $response); } - /** * @param ProductInterface $product * @param array $actualResponse */ private function assertBaseFields($product, $actualResponse) { - $assertionMap = [ ['response_field' => 'attribute_set_id', 'expected_value' => $product->getAttributeSetId()], ['response_field' => 'created_at', 'expected_value' => $product->getCreatedAt()], @@ -365,10 +383,8 @@ private function assertBaseFields($product, $actualResponse) ['response_field' => 'type_id', 'expected_value' => $product->getTypeId()], ['response_field' => 'updated_at', 'expected_value' => $product->getUpdatedAt()], ]; - $this->assertResponseFields($actualResponse, $assertionMap); } - /** * @param ProductInterface $product * @param array $actualResponse @@ -385,10 +401,8 @@ private function assertWebsites($product, $actualResponse) 'is_default' => true, ] ]; - $this->assertEquals($actualResponse, $assertionMap); } - /** * @param array $actualResponse */ @@ -410,9 +424,8 @@ private function assertAttributes($actualResponse) 'special_from_date', 'special_to_date', ]; - foreach ($eavAttributes as $eavAttribute) { $this->assertArrayHasKey($eavAttribute, $actualResponse); } } -} +} \ No newline at end of file diff --git a/dev/tests/integration/testsuite/Magento/Catalog/_files/categories.php b/dev/tests/integration/testsuite/Magento/Catalog/_files/categories.php index a903274793c34..a5ab961932461 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/_files/categories.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/_files/categories.php @@ -178,7 +178,7 @@ ->setParentId(3) ->setPath('1/2/3/13') ->setLevel(3) - ->setDescription('Ololo') + ->setDescription('Its a description of Test Category 1.2') ->setAvailableSortBy('name') ->setDefaultSortBy('name') ->setIsActive(true) From 2b4d5012ca47bcfeaaa205dc35cd7803bf095b5a Mon Sep 17 00:00:00 2001 From: Vaha Date: Wed, 6 Feb 2019 16:19:59 +0200 Subject: [PATCH 18/23] 250 - added label from store view --- .../Model/Options/Collection.php | 2 + ...rableProductFrontendLabelAttributeTest.php | 57 +++++++++++++++++++ ...igurable_with_frontend_label_attribute.php | 21 +++++++ ...with_frontend_label_attribute_rollback.php | 7 +++ 4 files changed, 87 insertions(+) create mode 100644 dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductFrontendLabelAttributeTest.php create mode 100644 dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute.php create mode 100644 dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute_rollback.php diff --git a/app/code/Magento/ConfigurableProductGraphQl/Model/Options/Collection.php b/app/code/Magento/ConfigurableProductGraphQl/Model/Options/Collection.php index 90ed5cf54892d..36ee00d55339b 100644 --- a/app/code/Magento/ConfigurableProductGraphQl/Model/Options/Collection.php +++ b/app/code/Magento/ConfigurableProductGraphQl/Model/Options/Collection.php @@ -124,6 +124,8 @@ private function fetch() : array $this->attributeMap[$productId][$attribute->getId()]['attribute_code'] = $attribute->getProductAttribute()->getAttributeCode(); $this->attributeMap[$productId][$attribute->getId()]['values'] = $attributeData['options']; + $this->attributeMap[$productId][$attribute->getId()]['label'] + = $attribute->getProductAttribute()->getStoreLabel(); } return $this->attributeMap; diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductFrontendLabelAttributeTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductFrontendLabelAttributeTest.php new file mode 100644 index 0000000000000..19effcf74258f --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductFrontendLabelAttributeTest.php @@ -0,0 +1,57 @@ +graphQlQuery($query); + + $this->assertArrayHasKey('products', $response); + $this->assertArrayHasKey('items', $response['products']); + $this->assertArrayHasKey(0, $response['products']['items']); + + $product = $response['products']['items'][0]; + $this->assertArrayHasKey('configurable_options', $product); + $this->assertArrayHasKey(0, $product['configurable_options']); + $this->assertArrayHasKey('label', $product['configurable_options'][0]); + + $option = $product['configurable_options'][0]; + $this->assertEquals($expectLabelValue, $option['label']); + } +} \ No newline at end of file diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute.php new file mode 100644 index 0000000000000..169223965a2d6 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute.php @@ -0,0 +1,21 @@ +get(FrontendLabel::class); +$frontendLabelAttribute->setStoreId(1); +$frontendLabelAttribute->setLabel('Default Store View label'); + +$frontendLabels = $attribute->getFrontendLabels(); +$frontendLabels[] = $frontendLabelAttribute; + +$attribute->setFrontendLabels($frontendLabels); +$attributeRepository->save($attribute); \ No newline at end of file diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute_rollback.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute_rollback.php new file mode 100644 index 0000000000000..b33d581fe11f8 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute_rollback.php @@ -0,0 +1,7 @@ + Date: Wed, 6 Feb 2019 14:19:49 -0600 Subject: [PATCH 19/23] GraphQL-353: Add queries for directory information -- fix static tests --- app/code/Magento/DirectoryGraphQl/etc/module.xml | 7 +------ composer.lock | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/DirectoryGraphQl/etc/module.xml b/app/code/Magento/DirectoryGraphQl/etc/module.xml index 8c2bb4325b611..5d6ec613f36b3 100644 --- a/app/code/Magento/DirectoryGraphQl/etc/module.xml +++ b/app/code/Magento/DirectoryGraphQl/etc/module.xml @@ -6,10 +6,5 @@ */ --> - - - - - - + diff --git a/composer.lock b/composer.lock index 697e7df3e19aa..c751b1a067efe 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "3f58ddc5609e6a934ee3706006357646", + "content-hash": "1f32126b38a1cd8a64b36be01147d14a", "packages": [ { "name": "braintree/braintree_php", @@ -2165,7 +2165,7 @@ }, { "name": "Gert de Pagter", - "email": "backendtea@gmail.com" + "email": "BackEndTea@gmail.com" } ], "description": "Symfony polyfill for ctype functions", From fd83649d37cd4b463644b02107cca5fb245705a5 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Wed, 6 Feb 2019 14:31:54 -0600 Subject: [PATCH 20/23] GraphQL-250: [BugFix] Configurable Options Label doesn't return the Store View Label -- fix static tests --- .../ConfigurableProductFrontendLabelAttributeTest.php | 3 +-- .../product_configurable_with_frontend_label_attribute.php | 3 ++- ...uct_configurable_with_frontend_label_attribute_rollback.php | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductFrontendLabelAttributeTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductFrontendLabelAttributeTest.php index 19effcf74258f..32cd3a9a51dcc 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductFrontendLabelAttributeTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/ConfigurableProduct/ConfigurableProductFrontendLabelAttributeTest.php @@ -3,7 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ - declare(strict_types=1); namespace Magento\GraphQl\ConfigurableProduct; @@ -54,4 +53,4 @@ public function testGetFrontendLabelAttribute() $option = $product['configurable_options'][0]; $this->assertEquals($expectLabelValue, $option['label']); } -} \ No newline at end of file +} diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute.php index 169223965a2d6..69607ffb445ba 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); use Magento\Eav\Model\Entity\Attribute\FrontendLabel; use Magento\TestFramework\Helper\Bootstrap; @@ -18,4 +19,4 @@ $frontendLabels[] = $frontendLabelAttribute; $attribute->setFrontendLabels($frontendLabels); -$attributeRepository->save($attribute); \ No newline at end of file +$attributeRepository->save($attribute); diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute_rollback.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute_rollback.php index b33d581fe11f8..616bd44666efc 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute_rollback.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/product_configurable_with_frontend_label_attribute_rollback.php @@ -3,5 +3,6 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); -require __DIR__ . '/configurable_products_rollback.php'; \ No newline at end of file +require __DIR__ . '/configurable_products_rollback.php'; From d6c826caeb101a1ea3132be7ea8d08917fee1c1d Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Wed, 6 Feb 2019 15:07:29 -0600 Subject: [PATCH 21/23] GraphQL-139: [BugFix] Show only active categories -- fix static tests --- .../DataProvider/ExtractDataFromCategoryTree.php | 13 +++++++++++-- .../Magento/GraphQl/Catalog/CategoryTest.php | 12 +++++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php index 47675edcbcae9..3525ccbb6a2d1 100644 --- a/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php +++ b/app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ExtractDataFromCategoryTree.php @@ -4,9 +4,12 @@ * See COPYING.txt for license details. */ declare(strict_types=1); + namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider; + use Magento\CatalogGraphQl\Model\Category\Hydrator; use Magento\Catalog\Api\Data\CategoryInterface; + /** * Extract data from category tree */ @@ -16,14 +19,17 @@ class ExtractDataFromCategoryTree * @var Hydrator */ private $categoryHydrator; + /** - * @var CategoryInterface; + * @var CategoryInterface */ private $iteratingCategory; + /** * @var int */ private $startCategoryFetchLevel = 1; + /** * @param Hydrator $categoryHydrator */ @@ -32,6 +38,7 @@ public function __construct( ) { $this->categoryHydrator = $categoryHydrator; } + /** * Extract data from category tree * @@ -58,6 +65,7 @@ public function execute(\Iterator $iterator): array } return $tree; } + /** * Merge together complex categories trees * @@ -77,6 +85,7 @@ private function mergeCategoriesTrees(array &$tree1, array &$tree2): array } return $mergedTree; } + /** * Recursive method to generate tree for one category path * @@ -99,4 +108,4 @@ private function explodePathToArray(array $pathElements, int $index): array } return $tree; } -} \ No newline at end of file +} diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php index e40e9e3c52ec1..c5fd2c49b9924 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php @@ -4,7 +4,9 @@ * See COPYING.txt for license details. */ declare(strict_types=1); + namespace Magento\GraphQl\Catalog; + use Magento\Catalog\Api\Data\CategoryInterface; use Magento\Catalog\Model\ResourceModel\Category\Collection as CategoryCollection; use Magento\Framework\DataObject; @@ -12,16 +14,19 @@ use Magento\Catalog\Api\Data\ProductInterface; use Magento\Catalog\Api\ProductRepositoryInterface; use Magento\TestFramework\ObjectManager; + class CategoryTest extends GraphQlAbstract { /** * @var \Magento\TestFramework\ObjectManager */ private $objectManager; + protected function setUp() { $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); } + /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Catalog/_files/categories.php @@ -104,6 +109,7 @@ public function testCategoriesTree() $responseDataObject->getData('category/children/0/children/1/id') ); } + /** * @magentoApiDataFixture Magento/Customer/_files/customer.php * @magentoApiDataFixture Magento/Catalog/_files/categories.php @@ -139,6 +145,7 @@ public function testGetCategoryById() $responseDataObject->getData('category/id') ); } + /** * @magentoApiDataFixture Magento/Catalog/_files/categories.php * @SuppressWarnings(PHPMD.ExcessiveMethodLength) @@ -344,6 +351,7 @@ public function testAnchorCategory() ]; $this->assertEquals($expectedResponse, $response); } + /** * @param ProductInterface $product * @param array $actualResponse @@ -385,6 +393,7 @@ private function assertBaseFields($product, $actualResponse) ]; $this->assertResponseFields($actualResponse, $assertionMap); } + /** * @param ProductInterface $product * @param array $actualResponse @@ -403,6 +412,7 @@ private function assertWebsites($product, $actualResponse) ]; $this->assertEquals($actualResponse, $assertionMap); } + /** * @param array $actualResponse */ @@ -428,4 +438,4 @@ private function assertAttributes($actualResponse) $this->assertArrayHasKey($eavAttribute, $actualResponse); } } -} \ No newline at end of file +} From 53a487e1e284102dbd721a3a31f3c05d57af8c43 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Sun, 10 Feb 2019 22:31:10 -0600 Subject: [PATCH 22/23] GraphQL-353: Add queries for directory information -- Update composer files --- composer.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.lock b/composer.lock index f43bb300bc4ef..48aef8b603d4a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4b6f2eede23af2202078a4c3043616c6", + "content-hash": "f22c780b1ed27ba951c0562e20078a70", "packages": [ { "name": "braintree/braintree_php", From e0547d60ad4a668dcc335611a2a70bfd7afbb182 Mon Sep 17 00:00:00 2001 From: Valerii Naida Date: Mon, 11 Feb 2019 10:00:19 -0600 Subject: [PATCH 23/23] GraphQL-139: [BugFix] Show only active categories -- skip tests with bad isolation --- .../Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php | 1 + .../GraphQl/ConfigurableProduct/ConfigurableProductViewTest.php | 2 ++ 2 files changed, 3 insertions(+) diff --git a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php index 6b57f84e4b9c4..1419aff867d2d 100644 --- a/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php +++ b/dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryProductsVariantsTest.php @@ -24,6 +24,7 @@ class CategoryProductsVariantsTest extends GraphQlAbstract */ public function testGetSimpleProductsFromCategory() { + $this->markTestIncomplete('https://github.com/magento/graphql-ce/issues/360'); $query = <<markTestIncomplete('https://github.com/magento/graphql-ce/issues/361'); + $productSku = 'configurable'; $query