Skip to content
This repository was archived by the owner on Dec 19, 2019. It is now read-only.

Commit 72f72dd

Browse files
authored
Merge pull request #4507 from magento-engcom/graphql-develop-prs
[Magento Community Engineering] Community Contributions - GraphQL
2 parents 7ffabd0 + b71d539 commit 72f72dd

File tree

64 files changed

+939
-236
lines changed

Some content is hidden

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

64 files changed

+939
-236
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright © Magento, Inc. All rights reserved.
22
# See COPYING.txt for license details.
33

4-
input PaymentMethodAdditionalDataInput {
4+
input PaymentMethodInput {
55
authorizenet_acceptjs: AuthorizenetInput @doc(description: "Defines the required attributes for Authorize.Net payments")
66
}
77

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/SortFields.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver\Category;
99

10+
use Magento\Catalog\Model\Category\Attribute\Source\Sortby;
11+
use Magento\Catalog\Model\Config;
1012
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1113
use Magento\Framework\GraphQl\Config\Element\Field;
1214
use Magento\Framework\GraphQl\Query\ResolverInterface;
@@ -17,32 +19,24 @@
1719
class SortFields implements ResolverInterface
1820
{
1921
/**
20-
* @var \Magento\Catalog\Model\Config
22+
* @var Config
2123
*/
2224
private $catalogConfig;
23-
24-
/**
25-
* @var \Magento\Store\Model\StoreManagerInterface
26-
*/
27-
private $storeManager;
28-
25+
2926
/**
30-
* @var \Magento\Catalog\Model\Category\Attribute\Source\Sortby
27+
* @var Sortby
3128
*/
3229
private $sortbyAttributeSource;
3330

3431
/**
35-
* @param \Magento\Catalog\Model\Config $catalogConfig
36-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
37-
* @oaram \Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource
32+
* @param Config $catalogConfig
33+
* @param Sortby $sortbyAttributeSource
3834
*/
3935
public function __construct(
40-
\Magento\Catalog\Model\Config $catalogConfig,
41-
\Magento\Store\Model\StoreManagerInterface $storeManager,
42-
\Magento\Catalog\Model\Category\Attribute\Source\Sortby $sortbyAttributeSource
36+
Config $catalogConfig,
37+
Sortby $sortbyAttributeSource
4338
) {
4439
$this->catalogConfig = $catalogConfig;
45-
$this->storeManager = $storeManager;
4640
$this->sortbyAttributeSource = $sortbyAttributeSource;
4741
}
4842

@@ -52,17 +46,19 @@ public function __construct(
5246
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
5347
{
5448
$sortFieldsOptions = $this->sortbyAttributeSource->getAllOptions();
49+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
50+
5551
array_walk(
5652
$sortFieldsOptions,
5753
function (&$option) {
5854
$option['label'] = (string)$option['label'];
5955
}
6056
);
6157
$data = [
62-
'default' => $this->catalogConfig->getProductListDefaultSortBy($this->storeManager->getStore()->getId()),
58+
'default' => $this->catalogConfig->getProductListDefaultSortBy($storeId),
6359
'options' => $sortFieldsOptions,
6460
];
65-
61+
6662
return $data;
6763
}
6864
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/Price.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,35 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver\Product;
99

10-
use Magento\Framework\Exception\LocalizedException;
11-
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
12-
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1310
use Magento\Catalog\Model\Product;
1411
use Magento\Catalog\Pricing\Price\FinalPrice;
1512
use Magento\Catalog\Pricing\Price\RegularPrice;
13+
use Magento\Framework\Exception\LocalizedException;
1614
use Magento\Framework\GraphQl\Config\Element\Field;
15+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
1716
use Magento\Framework\GraphQl\Query\ResolverInterface;
17+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1818
use Magento\Framework\Pricing\Adjustment\AdjustmentInterface;
1919
use Magento\Framework\Pricing\Amount\AmountInterface;
2020
use Magento\Framework\Pricing\PriceInfo\Factory as PriceInfoFactory;
21-
use Magento\Store\Model\StoreManagerInterface;
21+
use Magento\Store\Api\Data\StoreInterface;
2222

2323
/**
2424
* Format a product's price information to conform to GraphQL schema representation
2525
*/
2626
class Price implements ResolverInterface
2727
{
28-
/**
29-
* @var StoreManagerInterface
30-
*/
31-
private $storeManager;
32-
3328
/**
3429
* @var PriceInfoFactory
3530
*/
3631
private $priceInfoFactory;
3732

3833
/**
39-
* @param StoreManagerInterface $storeManager
4034
* @param PriceInfoFactory $priceInfoFactory
4135
*/
4236
public function __construct(
43-
StoreManagerInterface $storeManager,
4437
PriceInfoFactory $priceInfoFactory
4538
) {
46-
$this->storeManager = $storeManager;
4739
$this->priceInfoFactory = $priceInfoFactory;
4840
}
4941

@@ -80,11 +72,20 @@ public function resolve(
8072
$minimalPriceAmount = $finalPrice->getMinimalPrice();
8173
$maximalPriceAmount = $finalPrice->getMaximalPrice();
8274
$regularPriceAmount = $priceInfo->getPrice(RegularPrice::PRICE_CODE)->getAmount();
75+
$store = $context->getExtensionAttributes()->getStore();
8376

8477
$prices = [
85-
'minimalPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $minimalPriceAmount),
86-
'regularPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $regularPriceAmount),
87-
'maximalPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $maximalPriceAmount)
78+
'minimalPrice' => $this->createAdjustmentsArray(
79+
$priceInfo->getAdjustments(),
80+
$minimalPriceAmount,
81+
$store
82+
),
83+
'regularPrice' => $this->createAdjustmentsArray(
84+
$priceInfo->getAdjustments(),
85+
$regularPriceAmount,
86+
$store
87+
),
88+
'maximalPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $maximalPriceAmount, $store)
8889
];
8990

9091
return $prices;
@@ -95,13 +96,11 @@ public function resolve(
9596
*
9697
* @param AdjustmentInterface[] $adjustments
9798
* @param AmountInterface $amount
99+
* @param StoreInterface $store
98100
* @return array
99101
*/
100-
private function createAdjustmentsArray(array $adjustments, AmountInterface $amount) : array
102+
private function createAdjustmentsArray(array $adjustments, AmountInterface $amount, StoreInterface $store) : array
101103
{
102-
/** @var \Magento\Store\Model\Store $store */
103-
$store = $this->storeManager->getStore();
104-
105104
$priceArray = [
106105
'amount' => [
107106
'value' => $amount->getValue(),

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/ProductImage/Label.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\Framework\GraphQl\Config\Element\Field;
1414
use Magento\Framework\GraphQl\Query\ResolverInterface;
1515
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
16-
use Magento\Store\Model\StoreManagerInterface;
1716

1817
/**
1918
* Returns product's image label
@@ -25,21 +24,13 @@ class Label implements ResolverInterface
2524
*/
2625
private $productResource;
2726

28-
/**
29-
* @var StoreManagerInterface
30-
*/
31-
private $storeManager;
32-
3327
/**
3428
* @param ProductResourceModel $productResource
35-
* @param StoreManagerInterface $storeManager
3629
*/
3730
public function __construct(
38-
ProductResourceModel $productResource,
39-
StoreManagerInterface $storeManager
31+
ProductResourceModel $productResource
4032
) {
4133
$this->productResource = $productResource;
42-
$this->storeManager = $storeManager;
4334
}
4435

4536
/**
@@ -65,15 +56,16 @@ public function resolve(
6556
$imageType = $value['image_type'];
6657
$imagePath = $product->getData($imageType);
6758
$productId = (int)$product->getEntityId();
59+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
6860

6961
// null if image is not set
7062
if (null === $imagePath) {
71-
return $this->getAttributeValue($productId, 'name');
63+
return $this->getAttributeValue($productId, 'name', $storeId);
7264
}
7365

74-
$imageLabel = $this->getAttributeValue($productId, $imageType . '_label');
66+
$imageLabel = $this->getAttributeValue($productId, $imageType . '_label', $storeId);
7567
if (null === $imageLabel) {
76-
$imageLabel = $this->getAttributeValue($productId, 'name');
68+
$imageLabel = $this->getAttributeValue($productId, 'name', $storeId);
7769
}
7870

7971
return $imageLabel;
@@ -84,12 +76,11 @@ public function resolve(
8476
*
8577
* @param int $productId
8678
* @param string $attributeCode
79+
* @param int $storeId
8780
* @return null|string Null if attribute value is not exists
8881
*/
89-
private function getAttributeValue(int $productId, string $attributeCode): ?string
82+
private function getAttributeValue(int $productId, string $attributeCode, int $storeId): ?string
9083
{
91-
$storeId = $this->storeManager->getStore()->getId();
92-
9384
$value = $this->productResource->getAttributeRawValue($productId, $attributeCode, $storeId);
9485
return is_array($value) && empty($value) ? null : $value;
9586
}

app/code/Magento/CmsGraphQl/Model/Resolver/DataProvider/Page.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Cms\Api\GetPageByIdentifierInterface;
1212
use Magento\Cms\Api\PageRepositoryInterface;
1313
use Magento\Framework\Exception\NoSuchEntityException;
14-
use Magento\Store\Model\StoreManagerInterface;
1514
use Magento\Widget\Model\Template\FilterEmulate;
1615

1716
/**
@@ -29,11 +28,6 @@ class Page
2928
*/
3029
private $pageRepository;
3130

32-
/**
33-
* @var StoreManagerInterface
34-
*/
35-
private $storeManager;
36-
3731
/**
3832
* @var FilterEmulate
3933
*/
@@ -43,19 +37,16 @@ class Page
4337
* @param PageRepositoryInterface $pageRepository
4438
* @param FilterEmulate $widgetFilter
4539
* @param GetPageByIdentifierInterface $getPageByIdentifier
46-
* @param StoreManagerInterface $storeManager
4740
*/
4841
public function __construct(
4942
PageRepositoryInterface $pageRepository,
5043
FilterEmulate $widgetFilter,
51-
GetPageByIdentifierInterface $getPageByIdentifier,
52-
StoreManagerInterface $storeManager
44+
GetPageByIdentifierInterface $getPageByIdentifier
5345
) {
5446

5547
$this->pageRepository = $pageRepository;
5648
$this->widgetFilter = $widgetFilter;
5749
$this->pageByIdentifier = $getPageByIdentifier;
58-
$this->storeManager = $storeManager;
5950
}
6051

6152
/**
@@ -76,12 +67,12 @@ public function getDataByPageId(int $pageId): array
7667
* Returns page data by page identifier
7768
*
7869
* @param string $pageIdentifier
70+
* @param int $storeId
7971
* @return array
8072
* @throws NoSuchEntityException
8173
*/
82-
public function getDataByPageIdentifier(string $pageIdentifier): array
74+
public function getDataByPageIdentifier(string $pageIdentifier, int $storeId): array
8375
{
84-
$storeId = (int)$this->storeManager->getStore()->getId();
8576
$page = $this->pageByIdentifier->execute($pageIdentifier, $storeId);
8677

8778
return $this->convertPageData($page);

app/code/Magento/CmsGraphQl/Model/Resolver/Page.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ public function resolve(
5555
if (isset($args['id'])) {
5656
$pageData = $this->pageDataProvider->getDataByPageId((int)$args['id']);
5757
} elseif (isset($args['identifier'])) {
58-
$pageData = $this->pageDataProvider->getDataByPageIdentifier((string)$args['identifier']);
58+
$pageData = $this->pageDataProvider->getDataByPageIdentifier(
59+
(string)$args['identifier'],
60+
(int)$context->getExtensionAttributes()->getStore()->getId()
61+
);
5962
}
6063
} catch (NoSuchEntityException $e) {
6164
throw new GraphQlNoSuchEntityException(__($e->getMessage()), $e);

app/code/Magento/CmsGraphQl/composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"php": "~7.1.3||~7.2.0",
77
"magento/framework": "*",
88
"magento/module-cms": "*",
9-
"magento/module-store": "*",
109
"magento/module-widget": "*"
1110
},
1211
"suggest": {

app/code/Magento/CustomerGraphQl/Model/Customer/CreateCustomerAccount.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Magento\Framework\Api\DataObjectHelper;
1414
use Magento\Framework\Exception\LocalizedException;
1515
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
16-
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\Store\Api\Data\StoreInterface;
1717

1818
/**
1919
* Create new customer account
@@ -35,11 +35,6 @@ class CreateCustomerAccount
3535
*/
3636
private $accountManagement;
3737

38-
/**
39-
* @var StoreManagerInterface
40-
*/
41-
private $storeManager;
42-
4338
/**
4439
* @var ChangeSubscriptionStatus
4540
*/
@@ -48,35 +43,33 @@ class CreateCustomerAccount
4843
/**
4944
* @param DataObjectHelper $dataObjectHelper
5045
* @param CustomerInterfaceFactory $customerFactory
51-
* @param StoreManagerInterface $storeManager
5246
* @param AccountManagementInterface $accountManagement
5347
* @param ChangeSubscriptionStatus $changeSubscriptionStatus
5448
*/
5549
public function __construct(
5650
DataObjectHelper $dataObjectHelper,
5751
CustomerInterfaceFactory $customerFactory,
58-
StoreManagerInterface $storeManager,
5952
AccountManagementInterface $accountManagement,
6053
ChangeSubscriptionStatus $changeSubscriptionStatus
6154
) {
6255
$this->dataObjectHelper = $dataObjectHelper;
6356
$this->customerFactory = $customerFactory;
6457
$this->accountManagement = $accountManagement;
65-
$this->storeManager = $storeManager;
6658
$this->changeSubscriptionStatus = $changeSubscriptionStatus;
6759
}
6860

6961
/**
7062
* Creates new customer account
7163
*
7264
* @param array $data
65+
* @param StoreInterface $store
7366
* @return CustomerInterface
7467
* @throws GraphQlInputException
7568
*/
76-
public function execute(array $data): CustomerInterface
69+
public function execute(array $data, StoreInterface $store): CustomerInterface
7770
{
7871
try {
79-
$customer = $this->createAccount($data);
72+
$customer = $this->createAccount($data, $store);
8073
} catch (LocalizedException $e) {
8174
throw new GraphQlInputException(__($e->getMessage()));
8275
}
@@ -91,18 +84,18 @@ public function execute(array $data): CustomerInterface
9184
* Create account
9285
*
9386
* @param array $data
87+
* @param StoreInterface $store
9488
* @return CustomerInterface
9589
* @throws LocalizedException
9690
*/
97-
private function createAccount(array $data): CustomerInterface
91+
private function createAccount(array $data, StoreInterface $store): CustomerInterface
9892
{
9993
$customerDataObject = $this->customerFactory->create();
10094
$this->dataObjectHelper->populateWithArray(
10195
$customerDataObject,
10296
$data,
10397
CustomerInterface::class
10498
);
105-
$store = $this->storeManager->getStore();
10699
$customerDataObject->setWebsiteId($store->getWebsiteId());
107100
$customerDataObject->setStoreId($store->getId());
108101

0 commit comments

Comments
 (0)