Skip to content

Commit 8926c42

Browse files
committed
magento/graphql-ce#710: Links to the downloadable_product_samples are direct links
magento/graphql-ce#729: Links to the downloadable_product_links are direct links
1 parent 05f093e commit 8926c42

File tree

3 files changed

+29
-52
lines changed

3 files changed

+29
-52
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
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\App\ObjectManager;
2322
use Magento\Framework\UrlInterface;
2423

2524
/**
@@ -66,13 +65,13 @@ public function __construct(
6665
DownloadableHelper $downloadableHelper,
6766
SampleCollection $sampleCollection,
6867
LinkCollection $linkCollection,
69-
UrlInterface $urlBuilder = null
68+
UrlInterface $urlBuilder
7069
) {
7170
$this->enumLookup = $enumLookup;
7271
$this->downloadableHelper = $downloadableHelper;
7372
$this->sampleCollection = $sampleCollection;
7473
$this->linkCollection = $linkCollection;
75-
$this->urlBuilder = $urlBuilder ?: ObjectManager::getInstance()->get(UrlInterface::class);
74+
$this->urlBuilder = $urlBuilder;
7675
}
7776

7877
/**
@@ -154,7 +153,10 @@ private function formatLinks(LinkCollection $links) : array
154153
}
155154

156155
$resultData[$linkKey]['sample_file'] = $link->getSampleFile();
157-
$resultData[$linkKey]['sample_url'] = $link->getSampleUrl();
156+
$resultData[$linkKey]['sample_url'] = $this->urlBuilder->getUrl(
157+
'downloadable/download/linkSample',
158+
['link_id' => $link->getId()]
159+
);
158160
}
159161
return $resultData;
160162
}
@@ -165,7 +167,7 @@ private function formatLinks(LinkCollection $links) : array
165167
* @param Collection $samples
166168
* @return array
167169
*/
168-
private function formatSamples(Collection $samples) : array
170+
private function formatSamples(Collection $samples): array
169171
{
170172
$resultData = [];
171173
foreach ($samples as $sampleKey => $sample) {
@@ -175,8 +177,11 @@ private function formatSamples(Collection $samples) : array
175177
$resultData[$sampleKey]['sort_order'] = $sample->getSortOrder();
176178
$resultData[$sampleKey]['sample_type']
177179
= $this->enumLookup->getEnumValueFromField('DownloadableFileTypeEnum', $sample->getSampleType());
178-
$resultData[$sampleKey]['sample_file'] = $this->urlBuilder->getUrl('downloadable/download/sample', ['sample_id' => $sample->getId()]);
179-
$resultData[$sampleKey]['sample_url'] = $sample->getSampleUrl();
180+
$resultData[$sampleKey]['sample_file'] = $sample->getSampleFile();
181+
$resultData[$sampleKey]['sample_url'] = $this->urlBuilder->getUrl(
182+
'downloadable/download/sample',
183+
['sample_id' => $sample->getId()]
184+
);
180185
}
181186
return $resultData;
182187
}

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
}

dev/tests/api-functional/testsuite/Magento/GraphQl/DownloadableProduct/DownloadableProductViewTest.php

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,16 @@ public function testQueryAllFieldsDownloadableProductsWithDownloadableFileAndSam
5353
links_purchased_separately
5454
5555
downloadable_product_links{
56-
id
5756
sample_url
58-
sample_type
59-
60-
is_shareable
61-
number_of_downloads
6257
sort_order
6358
title
64-
link_type
65-
6659
price
6760
}
6861
downloadable_product_samples{
6962
title
7063
sort_order
7164
sort_order
72-
sample_type
73-
sample_file
65+
sample_url
7466
}
7567
}
7668
}
@@ -82,8 +74,6 @@ public function testQueryAllFieldsDownloadableProductsWithDownloadableFileAndSam
8274
$config = ObjectManager::getInstance()->get(\Magento\Config\Model\ResourceModel\Config::class);
8375
$config->saveConfig(
8476
\Magento\Downloadable\Model\Link::XML_PATH_CONFIG_IS_SHAREABLE,
85-
0,
86-
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
8777
0
8878
);
8979
$response = $this->graphQlQuery($query);
@@ -143,22 +133,15 @@ public function testDownloadableProductQueryWithNoSample()
143133
links_purchased_separately
144134
145135
downloadable_product_links{
146-
id
147136
sample_url
148-
sample_type
149-
is_shareable
150-
number_of_downloads
151137
sort_order
152138
title
153-
link_type
154139
price
155140
}
156141
downloadable_product_samples{
157142
title
158143
sort_order
159-
sort_order
160-
sample_type
161-
sample_file
144+
sample_url
162145
}
163146
}
164147
}
@@ -197,12 +180,8 @@ public function testDownloadableProductQueryWithNoSample()
197180
$this->assertResponseFields(
198181
$response['products']['items'][0]['downloadable_product_links'][0],
199182
[
200-
'id' => $downloadableProductLink->getId(),
201-
'is_shareable' => false,
202-
'number_of_downloads' => $downloadableProductLink->getNumberOfDownloads(),
203183
'sort_order' => $downloadableProductLink->getSortOrder(),
204184
'title' => $downloadableProductLink->getTitle(),
205-
'link_type' => strtoupper($downloadableProductLink->getLinkType()),
206185
'price' => $downloadableProductLink->getPrice()
207186
]
208187
);
@@ -221,18 +200,12 @@ private function assertDownloadableProductLinks($product, $actualResponse)
221200
/** @var LinkInterface $downloadableProductLinks */
222201
$downloadableProductLinks = $product->getExtensionAttributes()->getDownloadableProductLinks();
223202
$downloadableProductLink = $downloadableProductLinks[1];
224-
203+
$this->assertNotEmpty('sample_url', $actualResponse['downloadable_product_links'][1]);
225204
$this->assertResponseFields(
226205
$actualResponse['downloadable_product_links'][1],
227206
[
228-
'id' => $downloadableProductLink->getId(),
229-
'sample_url' => $downloadableProductLink->getSampleUrl(),
230-
'sample_type' => strtoupper($downloadableProductLink->getSampleType()),
231-
'is_shareable' => false,
232-
'number_of_downloads' => $downloadableProductLink->getNumberOfDownloads(),
233207
'sort_order' => $downloadableProductLink->getSortOrder(),
234208
'title' => $downloadableProductLink->getTitle(),
235-
'link_type' => strtoupper($downloadableProductLink->getLinkType()),
236209
'price' => $downloadableProductLink->getPrice()
237210
]
238211
);
@@ -251,13 +224,12 @@ private function assertDownloadableProductSamples($product, $actualResponse)
251224
/** @var SampleInterface $downloadableProductSamples */
252225
$downloadableProductSamples = $product->getExtensionAttributes()->getDownloadableProductSamples();
253226
$downloadableProductSample = $downloadableProductSamples[0];
227+
$this->assertNotEmpty('sample_url', $actualResponse['downloadable_product_samples'][0]);
254228
$this->assertResponseFields(
255229
$actualResponse['downloadable_product_samples'][0],
256230
[
257231
'title' => $downloadableProductSample->getTitle(),
258-
'sort_order' =>$downloadableProductSample->getSortOrder(),
259-
'sample_type' => strtoupper($downloadableProductSample->getSampleType()),
260-
'sample_file' => $downloadableProductSample->getSampleFile()
232+
'sort_order' => $downloadableProductSample->getSortOrder()
261233
]
262234
);
263235
}

0 commit comments

Comments
 (0)