Skip to content

Commit 765f380

Browse files
committed
Use store from context (extension attributes)
1 parent d2e3513 commit 765f380

33 files changed

+132
-187
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
4747
{
4848
$sortFieldsOptions = $this->sortbyAttributeSource->getAllOptions();
49-
$storeId = $context->getStoreId();
49+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
5050

5151
array_walk(
5252
$sortFieldsOptions,

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,32 +18,24 @@
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,20 +72,20 @@ public function resolve(
8072
$minimalPriceAmount = $finalPrice->getMinimalPrice();
8173
$maximalPriceAmount = $finalPrice->getMaximalPrice();
8274
$regularPriceAmount = $priceInfo->getPrice(RegularPrice::PRICE_CODE)->getAmount();
83-
$storeId = $context->getStoreId();
75+
$store = $context->getExtensionAttributes()->getStore();
8476

8577
$prices = [
8678
'minimalPrice' => $this->createAdjustmentsArray(
8779
$priceInfo->getAdjustments(),
8880
$minimalPriceAmount,
89-
$storeId
81+
$store
9082
),
9183
'regularPrice' => $this->createAdjustmentsArray(
9284
$priceInfo->getAdjustments(),
9385
$regularPriceAmount,
94-
$storeId
86+
$store
9587
),
96-
'maximalPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $maximalPriceAmount, $storeId)
88+
'maximalPrice' => $this->createAdjustmentsArray($priceInfo->getAdjustments(), $maximalPriceAmount, $store)
9789
];
9890

9991
return $prices;
@@ -104,15 +96,11 @@ public function resolve(
10496
*
10597
* @param AdjustmentInterface[] $adjustments
10698
* @param AmountInterface $amount
107-
* @param int $storeId
99+
* @param StoreInterface $store
108100
* @return array
109-
* @throws \Magento\Framework\Exception\NoSuchEntityException
110101
*/
111-
private function createAdjustmentsArray(array $adjustments, AmountInterface $amount, int $storeId) : array
102+
private function createAdjustmentsArray(array $adjustments, AmountInterface $amount, StoreInterface $store) : array
112103
{
113-
/** @var \Magento\Store\Model\Store $store */
114-
$store = $this->storeManager->getStore($storeId);
115-
116104
$priceArray = [
117105
'amount' => [
118106
'value' => $amount->getValue(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function resolve(
5656
$imageType = $value['image_type'];
5757
$imagePath = $product->getData($imageType);
5858
$productId = (int)$product->getEntityId();
59-
$storeId = $context->getStoreId();
59+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
6060

6161
// null if image is not set
6262
if (null === $imagePath) {

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/CustomerGraphQl/Model/Customer/CreateCustomerAccount.php

Lines changed: 6 additions & 16 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,36 +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
73-
* @param int $storeId
65+
* @param StoreInterface $store
7466
* @return CustomerInterface
7567
* @throws GraphQlInputException
7668
*/
77-
public function execute(array $data, int $storeId): CustomerInterface
69+
public function execute(array $data, StoreInterface $store): CustomerInterface
7870
{
7971
try {
80-
$customer = $this->createAccount($data, $storeId);
72+
$customer = $this->createAccount($data, $store);
8173
} catch (LocalizedException $e) {
8274
throw new GraphQlInputException(__($e->getMessage()));
8375
}
@@ -92,20 +84,18 @@ public function execute(array $data, int $storeId): CustomerInterface
9284
* Create account
9385
*
9486
* @param array $data
95-
* @param int $storeId
87+
* @param StoreInterface $store
9688
* @return CustomerInterface
9789
* @throws LocalizedException
98-
* @throws \Magento\Framework\Exception\NoSuchEntityException
9990
*/
100-
private function createAccount(array $data, int $storeId): CustomerInterface
91+
private function createAccount(array $data, StoreInterface $store): CustomerInterface
10192
{
10293
$customerDataObject = $this->customerFactory->create();
10394
$this->dataObjectHelper->populateWithArray(
10495
$customerDataObject,
10596
$data,
10697
CustomerInterface::class
10798
);
108-
$store = $this->storeManager->getStore($storeId);
10999
$customerDataObject->setWebsiteId($store->getWebsiteId());
110100
$customerDataObject->setStoreId($store->getId());
111101

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1313
use Magento\Customer\Api\Data\CustomerInterface;
1414
use Magento\Framework\Api\DataObjectHelper;
15+
use Magento\Store\Api\Data\StoreInterface;
1516

1617
/**
1718
* Update customer account data
@@ -69,13 +70,14 @@ public function __construct(
6970
*
7071
* @param CustomerInterface $customer
7172
* @param array $data
72-
* @param int $storeId
73+
* @param StoreInterface $store
7374
* @return void
7475
* @throws GraphQlAlreadyExistsException
7576
* @throws GraphQlAuthenticationException
7677
* @throws GraphQlInputException
78+
* @throws \Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException
7779
*/
78-
public function execute(CustomerInterface $customer, array $data, int $storeId): void
80+
public function execute(CustomerInterface $customer, array $data, StoreInterface $store): void
7981
{
8082
if (isset($data['email']) && $customer->getEmail() !== $data['email']) {
8183
if (!isset($data['password']) || empty($data['password'])) {
@@ -89,7 +91,7 @@ public function execute(CustomerInterface $customer, array $data, int $storeId):
8991
$filteredData = array_diff_key($data, array_flip($this->restrictedKeys));
9092
$this->dataObjectHelper->populateWithArray($customer, $filteredData, CustomerInterface::class);
9193

92-
$customer->setStoreId($storeId);
94+
$customer->setStoreId($store->getId());
9395

9496
$this->saveCustomer->execute($customer);
9597

app/code/Magento/CustomerGraphQl/Model/Resolver/CreateCustomer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function resolve(
5555
throw new GraphQlInputException(__('"input" value should be specified'));
5656
}
5757

58-
$customer = $this->createCustomerAccount->execute($args['input'], $context->getStoreId());
58+
$customer = $this->createCustomerAccount->execute($args['input'], $context->getExtensionAttributes()->getStore());
5959

6060
$data = $this->extractCustomerData->execute($customer);
6161
return ['customer' => $data];

app/code/Magento/CustomerGraphQl/Model/Resolver/UpdateCustomer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function resolve(
7272
}
7373

7474
$customer = $this->getCustomer->execute($context);
75-
$this->updateCustomerAccount->execute($customer, $args['input'], $context->getStoreId());
75+
$this->updateCustomerAccount->execute($customer, $args['input'], $context->getExtensionAttributes()->getStore());
7676

7777
$data = $this->extractCustomerData->execute($customer);
7878
return ['customer' => $data];

app/code/Magento/PaypalGraphQl/Model/Resolver/PaypalExpressToken.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public function resolve(
8585
$usedExpressButton = isset($args['input']['express_button']) ? $args['input']['express_button'] : false;
8686
$customerId = $context->getUserId();
8787

88-
$cart = $this->getCartForUser->execute($cartId, $customerId);
88+
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
89+
$cart = $this->getCartForUser->execute($cartId, $customerId, $storeId);
8990
$config = $this->configProvider->getConfig($paymentCode);
9091
$checkout = $this->checkoutProvider->getCheckout($config, $cart);
9192

0 commit comments

Comments
 (0)