Skip to content

Commit 36f072d

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents 48a2a57 + e67ce21 commit 36f072d

File tree

58 files changed

+1344
-284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1344
-284
lines changed

app/code/Magento/Customer/view/frontend/web/js/customer-data.js

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,11 @@ define([
198198
* Customer data initialization
199199
*/
200200
init: function () {
201-
var countryData,
202-
privateContentVersion = 'private_content_version',
201+
var privateContentVersion = 'private_content_version',
203202
privateContent = $.cookieStorage.get(privateContentVersion),
204203
localPrivateContent = $.localStorage.get(privateContentVersion),
205204
needVersion = 'need_version',
206-
expiredSectionNames = this.getExpiredSectionNames(),
207-
isLoading = false;
205+
expiredSectionNames = this.getExpiredSectionNames();
208206

209207
if (privateContent &&
210208
!$.cookieStorage.isSet(privateContentVersion) &&
@@ -213,7 +211,6 @@ define([
213211
$.cookieStorage.set(privateContentVersion, needVersion);
214212
$.localStorage.set(privateContentVersion, needVersion);
215213
this.reload([], false);
216-
isLoading = true;
217214
} else if (localPrivateContent !== privateContent) {
218215
if (!$.cookieStorage.isSet(privateContentVersion)) {
219216
privateContent = needVersion;
@@ -224,7 +221,6 @@ define([
224221
buffer.notify(sectionName, sectionData);
225222
});
226223
this.reload([], false);
227-
isLoading = true;
228224
} else if (expiredSectionNames.length > 0) {
229225
_.each(dataProvider.getFromStorage(storage.keys()), function (sectionData, sectionName) {
230226
buffer.notify(sectionName, sectionData);
@@ -239,14 +235,6 @@ define([
239235
this.reload(storageInvalidation.keys(), false);
240236
}
241237
}
242-
243-
if (!_.isEmpty(privateContent)) {
244-
countryData = this.get('directory-data');
245-
246-
if (_.isEmpty(countryData()) && !isLoading) {
247-
customerData.reload(['directory-data'], false);
248-
}
249-
}
250238
},
251239

252240
/**
@@ -332,6 +320,9 @@ define([
332320
},
333321

334322
/**
323+
* Avoid using this function directly 'cause of possible performance drawbacks.
324+
* Each customer section reload brings new non-cached ajax request.
325+
*
335326
* @param {Array} sectionNames
336327
* @param {Boolean} forceNewSectionTimestamp
337328
* @return {*}

app/code/Magento/Customer/view/frontend/web/js/zxcvbn.js

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/code/Magento/DirectoryGraphQl/Model/Resolver/Country.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\Reflection\DataObjectProcessor;
1616
use Magento\Directory\Api\CountryInformationAcquirerInterface;
1717
use Magento\Directory\Api\Data\CountryInformationInterface;
18+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1819

1920
/**
2021
* Country field resolver, used for GraphQL request processing.
@@ -53,6 +54,10 @@ public function resolve(
5354
array $value = null,
5455
array $args = null
5556
) {
57+
if (empty($args['id'])) {
58+
throw new GraphQlInputException(__('Country "id" value should be specified'));
59+
}
60+
5661
try {
5762
$country = $this->countryInformationAcquirer->getCountryInfo($args['id']);
5863
} catch (NoSuchEntityException $exception) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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\DownloadableGraphQl\Model\Cart\BuyRequest;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Framework\Exception\NoSuchEntityException;
12+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
13+
use Magento\QuoteGraphQl\Model\Cart\BuyRequest\BuyRequestDataProviderInterface;
14+
15+
/**
16+
* DataProvider for building downloadable product links in buy requests
17+
*/
18+
class DownloadableLinksDataProvider implements BuyRequestDataProviderInterface
19+
{
20+
/**
21+
* @var ProductRepositoryInterface
22+
*/
23+
private $productRepository;
24+
25+
/**
26+
* @param ProductRepositoryInterface $productRepository
27+
*/
28+
public function __construct(
29+
ProductRepositoryInterface $productRepository
30+
) {
31+
$this->productRepository = $productRepository;
32+
}
33+
34+
/**
35+
* @inheritdoc
36+
*/
37+
public function execute(array $cartItemData): array
38+
{
39+
$linksData = [];
40+
41+
if (isset($cartItemData['data']) && isset($cartItemData['data']['sku'])) {
42+
$sku = $cartItemData['data']['sku'];
43+
44+
try {
45+
$product = $this->productRepository->get($sku);
46+
} catch (NoSuchEntityException $e) {
47+
throw new GraphQlNoSuchEntityException(__('Could not find specified product.'));
48+
}
49+
50+
if ($product->getLinksPurchasedSeparately() && isset($cartItemData['downloadable_product_links'])) {
51+
$downloadableLinks = $cartItemData['downloadable_product_links'];
52+
$linksData = array_unique(array_column($downloadableLinks, 'link_id'));
53+
}
54+
}
55+
56+
return (count($linksData) > 0 ? ['links' => $linksData] : []);
57+
}
58+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\DownloadableGraphQl\Model;
9+
10+
use Magento\Downloadable\Api\Data\LinkInterface;
11+
use Magento\Framework\UrlInterface;
12+
13+
/**
14+
* Convert links to array
15+
*/
16+
class ConvertLinksToArray
17+
{
18+
/**
19+
* @var UrlInterface
20+
*/
21+
private $urlBuilder;
22+
23+
/**
24+
* @param UrlInterface $urlBuilder
25+
*/
26+
public function __construct(
27+
UrlInterface $urlBuilder
28+
) {
29+
$this->urlBuilder = $urlBuilder;
30+
}
31+
32+
/**
33+
* Format links from collection as array
34+
*
35+
* @param LinkInterface[] $links
36+
* @return array
37+
*/
38+
public function execute(array $links): array
39+
{
40+
$data = [];
41+
foreach ($links as $key => $link) {
42+
$data[$key] = [
43+
'id' => $link->getId(),
44+
'sort_order' => $link->getSortOrder(),
45+
'title' => $link->getTitle(),
46+
'sample_url' => $this->urlBuilder->getUrl(
47+
'downloadable/download/linkSample',
48+
['link_id' => $link->getId()]
49+
),
50+
'price' => $link->getPrice(),
51+
];
52+
}
53+
return $data;
54+
}
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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\DownloadableGraphQl\Model;
9+
10+
use Magento\Downloadable\Api\Data\SampleInterface;
11+
use Magento\Framework\UrlInterface;
12+
13+
/**
14+
* Convert samples to array
15+
*/
16+
class ConvertSamplesToArray
17+
{
18+
/**
19+
* @var UrlInterface
20+
*/
21+
private $urlBuilder;
22+
23+
/**
24+
* @param UrlInterface $urlBuilder
25+
*/
26+
public function __construct(
27+
UrlInterface $urlBuilder
28+
) {
29+
$this->urlBuilder = $urlBuilder;
30+
}
31+
32+
/**
33+
* Format samples from collection as array
34+
*
35+
* @param SampleInterface[] $samples
36+
* @return array
37+
*/
38+
public function execute(array $samples): array
39+
{
40+
$data = [];
41+
foreach ($samples as $key => $sample) {
42+
$data[$key] = [
43+
'id' => $sample->getId(),
44+
'sort_order' => $sample->getSortOrder(),
45+
'title' => $sample->getTitle(),
46+
'sample_url' => $this->urlBuilder->getUrl(
47+
'downloadable/download/sample',
48+
['sample_id' => $sample->getId()]
49+
),
50+
];
51+
}
52+
return $data;
53+
}
54+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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\DownloadableGraphQl\Model;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Downloadable\Api\Data\LinkInterface;
12+
use Magento\Downloadable\Model\ResourceModel\Link\Collection;
13+
use Magento\Downloadable\Model\ResourceModel\Link\CollectionFactory;
14+
15+
/**
16+
* Returns links of a particular downloadable product
17+
*/
18+
class GetDownloadableProductLinks
19+
{
20+
/**
21+
* @var CollectionFactory
22+
*/
23+
private $linkCollectionFactory;
24+
25+
/**
26+
* @param CollectionFactory $linkCollectionFactory
27+
*/
28+
public function __construct(
29+
CollectionFactory $linkCollectionFactory
30+
) {
31+
$this->linkCollectionFactory = $linkCollectionFactory;
32+
}
33+
34+
/**
35+
* Returns downloadable product links
36+
*
37+
* @param Product $product
38+
* @param array $selectedLinksIds
39+
* @return LinkInterface[]
40+
* @throws \Magento\Framework\Exception\LocalizedException
41+
*/
42+
public function execute(Product $product, array $selectedLinksIds = []): array
43+
{
44+
/** @var Collection */
45+
$links = $this->linkCollectionFactory->create();
46+
$links->addTitleToResult($product->getStoreId())
47+
->addPriceToResult($product->getStore()->getWebsiteId())
48+
->addProductToFilter($product->getId());
49+
50+
if (count($selectedLinksIds) > 0) {
51+
$links->addFieldToFilter('main_table.link_id', ['in' => $selectedLinksIds]);
52+
}
53+
return $links->getItems();
54+
}
55+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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\DownloadableGraphQl\Model;
9+
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Downloadable\Api\Data\SampleInterface;
12+
use Magento\Downloadable\Model\ResourceModel\Sample\CollectionFactory;
13+
14+
/**
15+
* Returns samples of a particular downloadable product
16+
*/
17+
class GetDownloadableProductSamples
18+
{
19+
/**
20+
* @var CollectionFactory
21+
*/
22+
private $sampleCollectionFactory;
23+
24+
/**
25+
* @param CollectionFactory $sampleCollectionFactory
26+
*/
27+
public function __construct(
28+
CollectionFactory $sampleCollectionFactory
29+
) {
30+
$this->sampleCollectionFactory = $sampleCollectionFactory;
31+
}
32+
33+
/**
34+
* Returns downloadable product samples
35+
*
36+
* @param Product $product
37+
* @return SampleInterface[]
38+
*/
39+
public function execute(Product $product): array
40+
{
41+
$samples = $this->sampleCollectionFactory->create()
42+
->addTitleToResult($product->getStoreId())
43+
->addProductToFilter($product->getId());
44+
return $samples->getItems();
45+
}
46+
}

0 commit comments

Comments
 (0)