Skip to content

Commit f17ca76

Browse files
authored
Merge pull request #4446 from magento-engcom/graphql-develop-prs
[Magento Community Engineering] Community Contributions - GraphQL
2 parents ede25ae + 216f796 commit f17ca76

30 files changed

+6454
-150
lines changed

app/code/Magento/ConfigurableProductGraphQl/Model/Variant/Collection.php

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Model\Product;
12-
use Magento\Catalog\Model\ProductFactory;
1312
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\Collection as ChildCollection;
1413
use Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory;
1514
use Magento\Framework\EntityManager\MetadataPool;
1615
use Magento\Framework\Api\SearchCriteriaBuilder;
17-
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product as DataProvider;
16+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\CollectionProcessorInterface;
1817

1918
/**
2019
* Collection for fetching configurable child product data.
@@ -26,21 +25,11 @@ class Collection
2625
*/
2726
private $childCollectionFactory;
2827

29-
/**
30-
* @var ProductFactory
31-
*/
32-
private $productFactory;
33-
3428
/**
3529
* @var SearchCriteriaBuilder
3630
*/
3731
private $searchCriteriaBuilder;
3832

39-
/**
40-
* @var DataProvider
41-
*/
42-
private $productDataProvider;
43-
4433
/**
4534
* @var MetadataPool
4635
*/
@@ -61,25 +50,27 @@ class Collection
6150
*/
6251
private $attributeCodes = [];
6352

53+
/**
54+
* @var CollectionProcessorInterface
55+
*/
56+
private $collectionProcessor;
57+
6458
/**
6559
* @param CollectionFactory $childCollectionFactory
66-
* @param ProductFactory $productFactory
6760
* @param SearchCriteriaBuilder $searchCriteriaBuilder
68-
* @param DataProvider $productDataProvider
6961
* @param MetadataPool $metadataPool
62+
* @param CollectionProcessorInterface $collectionProcessor
7063
*/
7164
public function __construct(
7265
CollectionFactory $childCollectionFactory,
73-
ProductFactory $productFactory,
7466
SearchCriteriaBuilder $searchCriteriaBuilder,
75-
DataProvider $productDataProvider,
76-
MetadataPool $metadataPool
67+
MetadataPool $metadataPool,
68+
CollectionProcessorInterface $collectionProcessor
7769
) {
7870
$this->childCollectionFactory = $childCollectionFactory;
79-
$this->productFactory = $productFactory;
8071
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
81-
$this->productDataProvider = $productDataProvider;
8272
$this->metadataPool = $metadataPool;
73+
$this->collectionProcessor = $collectionProcessor;
8374
}
8475

8576
/**
@@ -148,7 +139,11 @@ private function fetch() : array
148139
/** @var ChildCollection $childCollection */
149140
$childCollection = $this->childCollectionFactory->create();
150141
$childCollection->setProductFilter($product);
151-
$childCollection->addAttributeToSelect($attributeData);
142+
$this->collectionProcessor->process(
143+
$childCollection,
144+
$this->searchCriteriaBuilder->create(),
145+
$attributeData
146+
);
152147

153148
/** @var Product $childProduct */
154149
foreach ($childCollection->getItems() as $childProduct) {

app/code/Magento/DownloadableGraphQl/Model/Resolver/Product/DownloadableOptions.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Magento\Framework\GraphQl\Config\Element\Field;
2020
use Magento\Framework\GraphQl\Query\EnumLookup;
2121
use Magento\Framework\GraphQl\Query\ResolverInterface;
22+
use Magento\Framework\UrlInterface;
2223

2324
/**
2425
* @inheritdoc
@@ -47,22 +48,30 @@ class DownloadableOptions implements ResolverInterface
4748
*/
4849
private $linkCollection;
4950

51+
/**
52+
* @var UrlInterface
53+
*/
54+
private $urlBuilder;
55+
5056
/**
5157
* @param EnumLookup $enumLookup
5258
* @param DownloadableHelper $downloadableHelper
5359
* @param SampleCollection $sampleCollection
5460
* @param LinkCollection $linkCollection
61+
* @param UrlInterface|null $urlBuilder
5562
*/
5663
public function __construct(
5764
EnumLookup $enumLookup,
5865
DownloadableHelper $downloadableHelper,
5966
SampleCollection $sampleCollection,
60-
LinkCollection $linkCollection
67+
LinkCollection $linkCollection,
68+
UrlInterface $urlBuilder
6169
) {
6270
$this->enumLookup = $enumLookup;
6371
$this->downloadableHelper = $downloadableHelper;
6472
$this->sampleCollection = $sampleCollection;
6573
$this->linkCollection = $linkCollection;
74+
$this->urlBuilder = $urlBuilder;
6675
}
6776

6877
/**
@@ -144,7 +153,10 @@ private function formatLinks(LinkCollection $links) : array
144153
}
145154

146155
$resultData[$linkKey]['sample_file'] = $link->getSampleFile();
147-
$resultData[$linkKey]['sample_url'] = $link->getSampleUrl();
156+
$resultData[$linkKey]['sample_url'] = $this->urlBuilder->getUrl(
157+
'downloadable/download/linkSample',
158+
['link_id' => $link->getId()]
159+
);
148160
}
149161
return $resultData;
150162
}
@@ -155,7 +167,7 @@ private function formatLinks(LinkCollection $links) : array
155167
* @param Collection $samples
156168
* @return array
157169
*/
158-
private function formatSamples(Collection $samples) : array
170+
private function formatSamples(Collection $samples): array
159171
{
160172
$resultData = [];
161173
foreach ($samples as $sampleKey => $sample) {
@@ -166,7 +178,10 @@ private function formatSamples(Collection $samples) : array
166178
$resultData[$sampleKey]['sample_type']
167179
= $this->enumLookup->getEnumValueFromField('DownloadableFileTypeEnum', $sample->getSampleType());
168180
$resultData[$sampleKey]['sample_file'] = $sample->getSampleFile();
169-
$resultData[$sampleKey]['sample_url'] = $sample->getSampleUrl();
181+
$resultData[$sampleKey]['sample_url'] = $this->urlBuilder->getUrl(
182+
'downloadable/download/sample',
183+
['sample_id' => $sample->getId()]
184+
);
170185
}
171186
return $resultData;
172187
}

app/code/Magento/DownloadableGraphQl/etc/schema.graphqls

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ type DownloadableProduct implements ProductInterface, CustomizableProductInterfa
2424
links_title: String @doc(description: "The heading above the list of downloadable products")
2525
}
2626

27-
enum DownloadableFileTypeEnum @doc(description: "This enumeration specifies whether a link or sample is a file or URL") {
27+
enum DownloadableFileTypeEnum @deprecated(reason: "`sample_url` serves to get the downloadable sample") {
2828
FILE
2929
URL
3030
}
3131

3232
type DownloadableProductLinks @doc(description: "DownloadableProductLinks defines characteristics of a downloadable product") {
33-
id: Int @doc(description: "The unique ID for the link to the downloadable product")
33+
id: Int @deprecated(reason: "This information shoud not be exposed on frontend")
3434
title: String @doc(description: "The display name of the link")
3535
sort_order: Int @doc(description: "A number indicating the sort order")
36-
is_shareable: Boolean @doc(description: "Indicates whether the link is shareable")
36+
is_shareable: Boolean @deprecated(reason: "This information shoud not be exposed on frontend")
3737
price: Float @doc(description: "The price of the downloadable product")
38-
number_of_downloads: Int @doc(description: "The maximum number of times the product can be downloaded. A value of 0 means unlimited.")
39-
link_type: DownloadableFileTypeEnum @doc(description: "Either FILE or URL")
40-
sample_type: DownloadableFileTypeEnum @doc(description: "Either FILE or URL")
41-
sample_file: String @doc(description: "The relative path to the downloadable sample")
42-
sample_url: String @doc(description: "The relative URL to the downloadable sample")
38+
number_of_downloads: Int @deprecated(reason: "This information shoud not be exposed on frontend")
39+
link_type: DownloadableFileTypeEnum @deprecated(reason: "`sample_url` serves to get the downloadable sample")
40+
sample_type: DownloadableFileTypeEnum @deprecated(reason: "`sample_url` serves to get the downloadable sample")
41+
sample_file: String @deprecated(reason: "`sample_url` serves to get the downloadable sample")
42+
sample_url: String @doc(description: "URL to the downloadable sample")
4343
}
4444

4545
type DownloadableProductSamples @doc(description: "DownloadableProductSamples defines characteristics of a downloadable product") {
46-
id: Int @doc(description: "The unique ID for the downloadable product sample")
46+
id: Int @deprecated(reason: "This information shoud not be exposed on frontend")
4747
title: String @doc(description: "The display name of the sample")
4848
sort_order: Int @doc(description: "A number indicating the sort order")
49-
sample_type: DownloadableFileTypeEnum @doc(description: "Either FILE or URL")
50-
sample_file: String @doc(description: "The relative path to the downloadable sample")
51-
sample_url: String @doc(description: "The relative URL to the downloadable sample")
49+
sample_type: DownloadableFileTypeEnum @deprecated(reason: "`sample_url` serves to get the downloadable sample")
50+
sample_file: String @deprecated(reason: "`sample_url` serves to get the downloadable sample")
51+
sample_url: String @doc(description: "URL to the downloadable sample")
5252
}

app/code/Magento/SendFriendGraphQl/Model/Provider/GetVisibleProduct.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@ public function execute(int $productId): ProductInterface
4949
$product = $this->productRepository->getById($productId);
5050

5151
if (!in_array(
52-
$product->getVisibility(),
53-
$this->visibility->getVisibleInCatalogIds()
52+
(int) $product->getVisibility(),
53+
$this->visibility->getVisibleInSiteIds(),
54+
true
5455
)) {
5556
throw new GraphQlNoSuchEntityException(
5657
__("The product that was requested doesn't exist. Verify the product and try again.")
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestModuleFedex\Model;
9+
10+
use Magento\Framework\Exception\NotFoundException;
11+
use Magento\Framework\HTTP\AsyncClient\Request;
12+
use Magento\Framework\Module\Dir;
13+
use Magento\Framework\Filesystem\Io\File;
14+
use Magento\Framework\Stdlib\ArrayManager;
15+
16+
/**
17+
* Load mock response body for Fedex rate request
18+
*/
19+
class MockResponseBodyLoader
20+
{
21+
private const RESPONSE_FILE_PATTERN = '%s/_files/mock_response_%s_%s.json';
22+
private const PATH_COUNTRY = 'RequestedShipment/Recipient/Address/CountryCode';
23+
private const PATH_SERVICE_TYPE = 'RequestedShipment/ServiceType';
24+
25+
/**
26+
* @var Dir
27+
*/
28+
private $moduleDirectory;
29+
30+
/**
31+
* @var File
32+
*/
33+
private $fileIo;
34+
35+
/**
36+
* @var ArrayManager
37+
*/
38+
private $arrayManager;
39+
40+
/**
41+
* @param Dir $moduleDirectory
42+
* @param File $fileIo
43+
* @param ArrayManager
44+
*/
45+
public function __construct(
46+
Dir $moduleDirectory,
47+
File $fileIo,
48+
ArrayManager $arrayManager
49+
) {
50+
$this->moduleDirectory = $moduleDirectory;
51+
$this->fileIo = $fileIo;
52+
$this->arrayManager = $arrayManager;
53+
}
54+
55+
/**
56+
* Loads mock response xml for a given request
57+
*
58+
* @param array $request
59+
* @return string
60+
* @throws NotFoundException
61+
*/
62+
public function loadForRequest(array $request): string
63+
{
64+
$moduleDir = $this->moduleDirectory->getDir('Magento_TestModuleFedex');
65+
66+
$type = strtolower($this->arrayManager->get(static::PATH_SERVICE_TYPE, $request) ?? 'general');
67+
$country = strtolower($this->arrayManager->get(static::PATH_COUNTRY, $request) ?? '');
68+
69+
$responsePath = sprintf(static::RESPONSE_FILE_PATTERN, $moduleDir, $type, $country);
70+
71+
if (!$this->fileIo->fileExists($responsePath)) {
72+
throw new NotFoundException(
73+
__('"%1" is not a valid mock response type for country "%2".', $type, $country)
74+
);
75+
}
76+
77+
return $this->fileIo->read($responsePath);
78+
}
79+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestModuleFedex\Model;
9+
10+
/**
11+
* Mock Fedex soap client factory
12+
*/
13+
class MockSoapClient extends \SoapClient
14+
{
15+
/**
16+
* @var MockResponseBodyLoader
17+
*/
18+
private $mockResponseBodyLoader;
19+
20+
/**
21+
* @param string $wsdl
22+
* @param MockResponseBodyLoader $mockResponseBodyLoader
23+
* @param array|null $options
24+
*/
25+
public function __construct(
26+
string $wsdl,
27+
MockResponseBodyLoader $mockResponseBodyLoader,
28+
array $options = null
29+
) {
30+
parent::__construct($wsdl, $options);
31+
$this->mockResponseBodyLoader = $mockResponseBodyLoader;
32+
}
33+
34+
/**
35+
* Fetch mock Fedex rates
36+
*
37+
* @param array $rateRequest
38+
* @return \stdClass
39+
* @throws \Magento\Framework\Exception\NotFoundException
40+
*/
41+
public function getRates(array $rateRequest): \stdClass
42+
{
43+
$response = $this->mockResponseBodyLoader->loadForRequest($rateRequest);
44+
45+
return json_decode($response);
46+
}
47+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\TestModuleFedex\Model;
9+
10+
use Magento\Framework\App\ObjectManager;
11+
12+
/**
13+
* Mock Fedex soap client factory
14+
*/
15+
class MockSoapClientFactory extends \Magento\Framework\Webapi\Soap\ClientFactory
16+
{
17+
/**
18+
* Create instance of the mock SoapClient
19+
*
20+
* @param string $wsdl
21+
* @param array $options
22+
* @return \SoapClient
23+
*/
24+
public function create($wsdl, array $options = []): \SoapClient
25+
{
26+
return ObjectManager::getInstance()->create(
27+
MockSoapClient::class,
28+
[
29+
'wsdl' => $wsdl,
30+
'options' => $options,
31+
]
32+
);
33+
}
34+
}

0 commit comments

Comments
 (0)