Skip to content

Commit 5232cc8

Browse files
Merge branch 'MC-18527-merge-release' of github.com:magento-trigger/magento2ce into MC-18527-merge-release
2 parents 30072e2 + 59606fb commit 5232cc8

File tree

24 files changed

+336
-174
lines changed

24 files changed

+336
-174
lines changed

app/code/Magento/Catalog/Test/Mftf/Test/AdminCreateVirtualProductWithTierPriceTest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@
9797
<waitForPageLoad stepKey="waitForCategoryPageToLoad"/>
9898
<see selector="{{StorefrontCategoryMainSection.productLink}}" userInput="{{virtualProductBigQty.name}}" stepKey="seeVirtualProductNameOnCategoryPage"/>
9999

100+
<!--Run full reindex and clear caches -->
101+
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
102+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
103+
100104
<!-- Verify customer see created virtual product with tier price(from above step) on storefront page and is searchable by sku -->
101105
<amOnPage url="{{StorefrontHomePage.url}}" stepKey="goToStorefront"/>
102106
<waitForPageLoad stepKey="waitForStoreFrontProductPageLoad"/>

app/code/Magento/CatalogGraphQl/Model/Product/Option/DateType.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
use Magento\Catalog\Model\Product\Option\Type\Date as ProductDateOptionType;
1111
use Magento\Framework\Exception\LocalizedException;
1212
use Magento\Framework\Stdlib\DateTime;
13+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1314

1415
/**
15-
* @inheritdoc
16+
* CatalogGraphQl product option date type
17+
*
18+
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
1619
*/
1720
class DateType extends ProductDateOptionType
1821
{
@@ -43,6 +46,13 @@ private function formatValues($values)
4346
if (isset($values[$this->getOption()->getId()])) {
4447
$value = $values[$this->getOption()->getId()];
4548
$dateTime = \DateTime::createFromFormat(DateTime::DATETIME_PHP_FORMAT, $value);
49+
50+
if ($dateTime === false) {
51+
throw new GraphQlInputException(
52+
__('Invalid format provided. Please use \'Y-m-d H:i:s\' format.')
53+
);
54+
}
55+
4656
$values[$this->getOption()->getId()] = [
4757
'date' => $value,
4858
'year' => $dateTime->format('Y'),

app/code/Magento/CatalogSearch/Test/Mftf/Test/SearchEntityResultsTest.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@
283283
<testCaseId value="MC-14784"/>
284284
<group value="CatalogSearch"/>
285285
<group value="mtf_migrated"/>
286+
<skip>
287+
<issueId value="MC-21717"/>
288+
</skip>
286289
</annotations>
287290
<before>
288291
<createData entity="_defaultCategory" stepKey="createCategory"/>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ public function execute(ContextInterface $context): CustomerInterface
7070

7171
try {
7272
$customer = $this->customerRepository->getById($currentUserId);
73+
// @codeCoverageIgnoreStart
7374
} catch (NoSuchEntityException $e) {
7475
throw new GraphQlNoSuchEntityException(
7576
__('Customer with id "%customer_id" does not exist.', ['customer_id' => $currentUserId]),
7677
$e
7778
);
7879
} catch (LocalizedException $e) {
7980
throw new GraphQlInputException(__($e->getMessage()));
81+
// @codeCoverageIgnoreEnd
8082
}
8183

8284
if (true === $this->authentication->isLocked($currentUserId)) {
@@ -85,8 +87,10 @@ public function execute(ContextInterface $context): CustomerInterface
8587

8688
try {
8789
$confirmationStatus = $this->accountManagement->getConfirmationStatus($currentUserId);
90+
// @codeCoverageIgnoreStart
8891
} catch (LocalizedException $e) {
8992
throw new GraphQlInputException(__($e->getMessage()));
93+
// @codeCoverageIgnoreEnd
9094
}
9195

9296
if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) {

app/code/Magento/DownloadableGraphQl/Model/Cart/BuyRequest/DownloadableLinksDataProvider.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,7 @@ public function execute(array $cartItemData): array
4040

4141
if (isset($cartItemData['data']) && isset($cartItemData['data']['sku'])) {
4242
$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-
}
43+
$product = $this->productRepository->get($sku);
4944

5045
if ($product->getLinksPurchasedSeparately() && isset($cartItemData['downloadable_product_links'])) {
5146
$downloadableLinks = $cartItemData['downloadable_product_links'];

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ enum DownloadableFileTypeEnum @deprecated(reason: "`sample_url` serves to get th
4343
}
4444

4545
type DownloadableProductLinks @doc(description: "DownloadableProductLinks defines characteristics of a downloadable product") {
46-
id: Int @deprecated(reason: "This information shoud not be exposed on frontend")
46+
id: Int @deprecated(reason: "This information should not be exposed on frontend")
4747
title: String @doc(description: "The display name of the link")
4848
sort_order: Int @doc(description: "A number indicating the sort order")
4949
price: Float @doc(description: "The price of the downloadable product")
@@ -56,7 +56,7 @@ type DownloadableProductLinks @doc(description: "DownloadableProductLinks define
5656
}
5757

5858
type DownloadableProductSamples @doc(description: "DownloadableProductSamples defines characteristics of a downloadable product") {
59-
id: Int @deprecated(reason: "This information shoud not be exposed on frontend")
59+
id: Int @deprecated(reason: "This information should not be exposed on frontend")
6060
title: String @doc(description: "The display name of the sample")
6161
sort_order: Int @doc(description: "A number indicating the sort order")
6262
sample_url: String @doc(description: "URL to the downloadable sample")

app/code/Magento/QuoteGraphQl/Model/Cart/ExtractQuoteAddressData.php

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
namespace Magento\QuoteGraphQl\Model\Cart;
99

10-
use Magento\Customer\Model\Address\AbstractAddress;
1110
use Magento\Framework\Api\ExtensibleDataObjectConverter;
1211
use Magento\Quote\Api\Data\AddressInterface;
1312
use Magento\Quote\Model\Quote\Address as QuoteAddress;
@@ -41,28 +40,37 @@ public function execute(QuoteAddress $address): array
4140
$addressData = $this->dataObjectConverter->toFlatArray($address, [], AddressInterface::class);
4241
$addressData['model'] = $address;
4342

44-
$addressData = array_merge($addressData, [
45-
'country' => [
46-
'code' => $address->getCountryId(),
47-
'label' => $address->getCountry()
48-
],
49-
'region' => [
50-
'code' => $address->getRegionCode(),
51-
'label' => $address->getRegion()
52-
],
53-
'street' => $address->getStreet(),
54-
'items_weight' => $address->getWeight(),
55-
'customer_notes' => $address->getCustomerNotes()
56-
]);
43+
$addressData = array_merge(
44+
$addressData,
45+
[
46+
'country' => [
47+
'code' => $address->getCountryId(),
48+
'label' => $address->getCountry()
49+
],
50+
'region' => [
51+
'code' => $address->getRegionCode(),
52+
'label' => $address->getRegion()
53+
],
54+
'street' => $address->getStreet(),
55+
'items_weight' => $address->getWeight(),
56+
'customer_notes' => $address->getCustomerNotes()
57+
]
58+
);
5759

5860
if (!$address->hasItems()) {
5961
return $addressData;
6062
}
6163

6264
$addressItemsData = [];
6365
foreach ($address->getAllItems() as $addressItem) {
66+
if ($addressItem instanceof \Magento\Quote\Model\Quote\Item) {
67+
$itemId = $addressItem->getItemId();
68+
} else {
69+
$itemId = $addressItem->getQuoteItemId();
70+
}
71+
6472
$addressItemsData[] = [
65-
'cart_item_id' => $addressItem->getQuoteItemId(),
73+
'cart_item_id' => $itemId,
6674
'quantity' => $addressItem->getQty()
6775
];
6876
}
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\QuoteGraphQl\Model\Cart;
9+
10+
use Magento\Framework\GraphQl\Schema\Type\TypeRegistry;
11+
12+
/**
13+
* Validates address against required fields from schema
14+
*/
15+
class ValidateAddressFromSchema
16+
{
17+
/**
18+
* @var TypeRegistry
19+
*/
20+
private $typeRegistry;
21+
22+
/**
23+
* @param TypeRegistry $typeRegistry
24+
*/
25+
public function __construct(
26+
TypeRegistry $typeRegistry
27+
) {
28+
$this->typeRegistry = $typeRegistry;
29+
}
30+
31+
/**
32+
* Validate data from address against mandatory fields from graphql schema for address
33+
*
34+
* @param array $address
35+
* @return bool
36+
*/
37+
public function execute(array $address = []) : bool
38+
{
39+
/** @var \Magento\Framework\GraphQL\Schema\Type\Input\InputObjectType $cartAddressInput */
40+
$cartAddressInput = $this->typeRegistry->get('CartAddressInput');
41+
$fields = $cartAddressInput->getFields();
42+
43+
foreach ($fields as $field) {
44+
if ($field->getType() instanceof \Magento\Framework\GraphQL\Schema\Type\NonNull) {
45+
// an array key has to exist but it's value should not be null
46+
if (array_key_exists($field->name, $address)
47+
&& !is_array($address[$field->name])
48+
&& !isset($address[$field->name])) {
49+
return false;
50+
}
51+
}
52+
}
53+
return true;
54+
}
55+
}

app/code/Magento/QuoteGraphQl/Model/Resolver/BillingAddress.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1414
use Magento\Quote\Api\Data\CartInterface;
1515
use Magento\QuoteGraphQl\Model\Cart\ExtractQuoteAddressData;
16+
use Magento\QuoteGraphQl\Model\Cart\ValidateAddressFromSchema;
1617

1718
/**
1819
* @inheritdoc
@@ -24,12 +25,21 @@ class BillingAddress implements ResolverInterface
2425
*/
2526
private $extractQuoteAddressData;
2627

28+
/**
29+
* @var ValidateAddressFromSchema
30+
*/
31+
private $validateAddressFromSchema;
32+
2733
/**
2834
* @param ExtractQuoteAddressData $extractQuoteAddressData
35+
* @param ValidateAddressFromSchema $validateAddressFromSchema
2936
*/
30-
public function __construct(ExtractQuoteAddressData $extractQuoteAddressData)
31-
{
37+
public function __construct(
38+
ExtractQuoteAddressData $extractQuoteAddressData,
39+
ValidateAddressFromSchema $validateAddressFromSchema
40+
) {
3241
$this->extractQuoteAddressData = $extractQuoteAddressData;
42+
$this->validateAddressFromSchema = $validateAddressFromSchema;
3343
}
3444

3545
/**
@@ -44,11 +54,10 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
4454
$cart = $value['model'];
4555

4656
$billingAddress = $cart->getBillingAddress();
47-
if (null === $billingAddress) {
57+
$addressData = $this->extractQuoteAddressData->execute($billingAddress);
58+
if (!$this->validateAddressFromSchema->execute($addressData)) {
4859
return null;
4960
}
50-
51-
$addressData = $this->extractQuoteAddressData->execute($billingAddress);
5261
return $addressData;
5362
}
5463
}

app/code/Magento/QuoteGraphQl/Model/Resolver/ShippingAddresses.php

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1414
use Magento\Quote\Model\Quote;
1515
use Magento\QuoteGraphQl\Model\Cart\ExtractQuoteAddressData;
16-
use Magento\Framework\GraphQl\Schema\Type\TypeRegistry;
17-
use Magento\Framework\App\ObjectManager;
16+
use Magento\QuoteGraphQl\Model\Cart\ValidateAddressFromSchema;
1817

1918
/**
2019
* @inheritdoc
@@ -27,20 +26,20 @@ class ShippingAddresses implements ResolverInterface
2726
private $extractQuoteAddressData;
2827

2928
/**
30-
* @var TypeRegistry
29+
* @var ValidateAddressFromSchema
3130
*/
32-
private $typeRegistry;
31+
private $validateAddressFromSchema;
3332

3433
/**
3534
* @param ExtractQuoteAddressData $extractQuoteAddressData
36-
* @param TypeRegistry|null $typeRegistry
35+
* @param ValidateAddressFromSchema $validateAddressFromSchema
3736
*/
3837
public function __construct(
3938
ExtractQuoteAddressData $extractQuoteAddressData,
40-
TypeRegistry $typeRegistry = null
39+
ValidateAddressFromSchema $validateAddressFromSchema
4140
) {
4241
$this->extractQuoteAddressData = $extractQuoteAddressData;
43-
$this->typeRegistry = $typeRegistry ?: ObjectManager::getInstance()->get(TypeRegistry::class);
42+
$this->validateAddressFromSchema = $validateAddressFromSchema;
4443
}
4544

4645
/**
@@ -61,36 +60,11 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
6160
foreach ($shippingAddresses as $shippingAddress) {
6261
$address = $this->extractQuoteAddressData->execute($shippingAddress);
6362

64-
if ($this->validateAddressFromSchema($address)) {
63+
if ($this->validateAddressFromSchema->execute($address)) {
6564
$addressesData[] = $address;
6665
}
6766
}
6867
}
6968
return $addressesData;
7069
}
71-
72-
/**
73-
* Validate data from address against mandatory fields from graphql schema for address
74-
*
75-
* @param array $address
76-
* @return bool
77-
*/
78-
private function validateAddressFromSchema(array $address) : bool
79-
{
80-
/** @var \Magento\Framework\GraphQL\Schema\Type\Input\InputObjectType $cartAddressInput */
81-
$cartAddressInput = $this->typeRegistry->get('CartAddressInput');
82-
$fields = $cartAddressInput->getFields();
83-
84-
foreach ($fields as $field) {
85-
if ($field->getType() instanceof \Magento\Framework\GraphQL\Schema\Type\NonNull) {
86-
// an array key has to exist but it's value should not be null
87-
if (array_key_exists($field->name, $address)
88-
&& !is_array($address[$field->name])
89-
&& !isset($address[$field->name])) {
90-
return false;
91-
}
92-
}
93-
}
94-
return true;
95-
}
9670
}

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ type Cart {
196196
applied_coupons: [AppliedCoupon] @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\AppliedCoupons") @doc(description:"An array of `AppliedCoupon` objects. Each object contains the `code` text attribute, which specifies the coupon code")
197197
email: String @resolver (class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartEmail")
198198
shipping_addresses: [ShippingCartAddress]! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\ShippingAddresses")
199-
billing_address: BillingCartAddress! @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\BillingAddress")
199+
billing_address: BillingCartAddress @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\BillingAddress")
200200
available_payment_methods: [AvailablePaymentMethod] @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AvailablePaymentMethods") @doc(description: "Available payment methods")
201201
selected_payment_method: SelectedPaymentMethod @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SelectedPaymentMethod")
202202
prices: CartPrices @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartPrices")
@@ -205,15 +205,15 @@ type Cart {
205205
}
206206

207207
interface CartAddressInterface @typeResolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\CartAddressTypeResolver") {
208-
firstname: String
209-
lastname: String
208+
firstname: String!
209+
lastname: String!
210210
company: String
211-
street: [String]
212-
city: String
211+
street: [String!]!
212+
city: String!
213213
region: CartAddressRegion
214214
postcode: String
215-
country: CartAddressCountry
216-
telephone: String
215+
country: CartAddressCountry!
216+
telephone: String!
217217
}
218218

219219
type ShippingCartAddress implements CartAddressInterface {
@@ -234,13 +234,13 @@ type CartItemQuantity {
234234
}
235235

236236
type CartAddressRegion {
237-
code: String
238-
label: String
237+
code: String!
238+
label: String!
239239
}
240240

241241
type CartAddressCountry {
242-
code: String
243-
label: String
242+
code: String!
243+
label: String!
244244
}
245245

246246
type SelectedShippingMethod {

0 commit comments

Comments
 (0)