Skip to content

Commit 632a7c6

Browse files
authored
Merge pull request #6302 from magento-honey-badgers/HB-PR-delivery-Oct
[honey] PR
2 parents a7bde28 + 8311af5 commit 632a7c6

File tree

15 files changed

+393
-62
lines changed

15 files changed

+393
-62
lines changed

app/code/Magento/CatalogGraphQl/DataProvider/Product/LayeredNavigation/Builder/Price.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function build(AggregationInterface $aggregation, ?int $storeId): array
7272
);
7373
}
7474

75-
return [$result];
75+
return [self::PRICE_BUCKET => $result];
7676
}
7777

7878
/**

app/code/Magento/CatalogGraphQl/Model/Resolver/Aggregations.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77

88
namespace Magento\CatalogGraphQl\Model\Resolver;
99

10+
use Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation\LayerBuilder;
11+
use Magento\Directory\Model\PriceCurrency;
12+
use Magento\Framework\App\ObjectManager;
1013
use Magento\Framework\GraphQl\Config\Element\Field;
1114
use Magento\Framework\GraphQl\Query\ResolverInterface;
1215
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13-
use Magento\CatalogGraphQl\DataProvider\Product\LayeredNavigation\LayerBuilder;
1416
use Magento\Store\Api\Data\StoreInterface;
1517

1618
/**
@@ -28,16 +30,24 @@ class Aggregations implements ResolverInterface
2830
*/
2931
private $layerBuilder;
3032

33+
/**
34+
* @var PriceCurrency
35+
*/
36+
private $priceCurrency;
37+
3138
/**
3239
* @param \Magento\CatalogGraphQl\Model\Resolver\Layer\DataProvider\Filters $filtersDataProvider
3340
* @param LayerBuilder $layerBuilder
41+
* @param PriceCurrency $priceCurrency
3442
*/
3543
public function __construct(
3644
\Magento\CatalogGraphQl\Model\Resolver\Layer\DataProvider\Filters $filtersDataProvider,
37-
LayerBuilder $layerBuilder
45+
LayerBuilder $layerBuilder,
46+
PriceCurrency $priceCurrency = null
3847
) {
3948
$this->filtersDataProvider = $filtersDataProvider;
4049
$this->layerBuilder = $layerBuilder;
50+
$this->priceCurrency = $priceCurrency ?: ObjectManager::getInstance()->get(PriceCurrency::class);
4151
}
4252

4353
/**
@@ -60,7 +70,18 @@ public function resolve(
6070
/** @var StoreInterface $store */
6171
$store = $context->getExtensionAttributes()->getStore();
6272
$storeId = (int)$store->getId();
63-
return $this->layerBuilder->build($aggregations, $storeId);
73+
$results = $this->layerBuilder->build($aggregations, $storeId);
74+
if (isset($results['price_bucket'])) {
75+
foreach ($results['price_bucket']['options'] as &$value) {
76+
list($from, $to) = explode('-', $value['label']);
77+
$newLabel = $this->priceCurrency->convertAndRound($from)
78+
. '-'
79+
. $this->priceCurrency->convertAndRound($to);
80+
$value['label'] = $newLabel;
81+
$value['value'] = str_replace('-', '_', $newLabel);
82+
}
83+
}
84+
return $results;
6485
} else {
6586
return [];
6687
}

app/code/Magento/CatalogGraphQl/Model/Resolver/Category/DataProvider/Breadcrumbs.php

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

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

10+
use Magento\Catalog\Api\Data\CategoryInterface;
1011
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory;
1112

1213
/**
@@ -46,6 +47,7 @@ public function getData(string $categoryPath): array
4647
$collection = $this->collectionFactory->create();
4748
$collection->addAttributeToSelect(['name', 'url_key', 'url_path']);
4849
$collection->addAttributeToFilter('entity_id', $parentCategoryIds);
50+
$collection->addAttributeToFilter(CategoryInterface::KEY_IS_ACTIVE, 1);
4951

5052
foreach ($collection as $category) {
5153
$breadcrumbsData[] = [

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

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

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

10+
use Magento\Catalog\Model\Category;
11+
use Magento\Catalog\Model\Category\FileInfo;
12+
use Magento\Framework\Exception\LocalizedException;
13+
use Magento\Framework\Filesystem\DirectoryList;
1014
use Magento\Framework\GraphQl\Config\Element\Field;
15+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1116
use Magento\Framework\GraphQl\Query\ResolverInterface;
1217
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
13-
use Magento\Framework\Exception\LocalizedException;
18+
use Magento\Framework\UrlInterface;
1419
use Magento\Store\Api\Data\StoreInterface;
15-
use Magento\Framework\Filesystem\DirectoryList;
16-
use Magento\Catalog\Model\Category\FileInfo;
17-
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1820

1921
/**
2022
* Resolve category image to a fully qualified URL
@@ -52,15 +54,15 @@ public function resolve(
5254
if (!isset($value['model'])) {
5355
throw new LocalizedException(__('"model" value should be specified'));
5456
}
55-
/** @var \Magento\Catalog\Model\Category $category */
57+
/** @var Category $category */
5658
$category = $value['model'];
5759
$imagePath = $category->getData('image');
5860
if (empty($imagePath)) {
5961
return null;
6062
}
6163
/** @var StoreInterface $store */
6264
$store = $context->getExtensionAttributes()->getStore();
63-
$baseUrl = $store->getBaseUrl();
65+
$baseUrl = $store->getBaseUrl(UrlInterface::URL_TYPE_WEB);
6466

6567
$filenameWithMedia = $this->fileInfo->isBeginsWithMediaDirectoryPath($imagePath)
6668
? $imagePath : $this->formatFileNameWithMediaCategoryFolder($imagePath);

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/ProductSearch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function getList(
113113
$searchResults = $this->searchResultsFactory->create();
114114
$searchResults->setSearchCriteria($searchCriteriaForCollection);
115115
$searchResults->setItems($collection->getItems());
116-
$searchResults->setTotalCount($searchResult->getTotalCount());
116+
$searchResults->setTotalCount($collection->getSize());
117117
return $searchResults;
118118
}
119119

app/code/Magento/CatalogGraphQl/Model/Resolver/Products/SearchCriteria/CollectionProcessor/FilterProcessor/CategoryFilter.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public function __construct(
5151
*/
5252
public function apply(Filter $filter, AbstractDb $collection)
5353
{
54+
$conditionType = $filter->getConditionType();
55+
if ($conditionType !== 'eq') {
56+
return true;
57+
}
58+
5459
$categoryIds = $filter->getValue();
5560
if (!is_array($categoryIds)) {
5661
$categoryIds = [$categoryIds];

app/code/Magento/CatalogGraphQl/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"magento/module-eav": "*",
88
"magento/module-catalog": "*",
99
"magento/module-catalog-inventory": "*",
10+
"magento/module-directory": "*",
1011
"magento/module-search": "*",
1112
"magento/module-store": "*",
1213
"magento/module-eav-graph-ql": "*",

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

Lines changed: 74 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,24 @@
77

88
namespace Magento\QuoteGraphQl\Model\Resolver;
99

10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\Exception\CouldNotSaveException;
1012
use Magento\Framework\GraphQl\Config\Element\Field;
13+
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
1114
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
15+
use Magento\Framework\GraphQl\Exception\GraphQlNoSuchEntityException;
1216
use Magento\Framework\GraphQl\Query\ResolverInterface;
1317
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
14-
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
15-
use Magento\Quote\Api\CartRepositoryInterface;
1618
use Magento\GraphQl\Model\Query\ContextInterface;
17-
use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException;
19+
use Magento\Quote\Api\CartRepositoryInterface;
20+
use Magento\Quote\Model\Cart\CustomerCartResolver;
21+
use Magento\Quote\Model\QuoteIdToMaskedQuoteIdInterface;
22+
use Magento\QuoteGraphQl\Model\Cart\GetCartForUser;
1823

1924
/**
2025
* Merge Carts Resolver
26+
*
27+
* @SuppressWarnings(PHPMD.LongVariable)
2128
*/
2229
class MergeCarts implements ResolverInterface
2330
{
@@ -31,44 +38,95 @@ class MergeCarts implements ResolverInterface
3138
*/
3239
private $cartRepository;
3340

41+
/**
42+
* @var CustomerCartResolver
43+
*/
44+
private $customerCartResolver;
45+
46+
/**
47+
* @var QuoteIdToMaskedQuoteIdInterface
48+
*/
49+
private $quoteIdToMaskedQuoteId;
50+
3451
/**
3552
* @param GetCartForUser $getCartForUser
3653
* @param CartRepositoryInterface $cartRepository
54+
* @param CustomerCartResolver|null $customerCartResolver
55+
* @param QuoteIdToMaskedQuoteIdInterface|null $quoteIdToMaskedQuoteId
3756
*/
3857
public function __construct(
3958
GetCartForUser $getCartForUser,
40-
CartRepositoryInterface $cartRepository
59+
CartRepositoryInterface $cartRepository,
60+
CustomerCartResolver $customerCartResolver = null,
61+
QuoteIdToMaskedQuoteIdInterface $quoteIdToMaskedQuoteId = null
4162
) {
4263
$this->getCartForUser = $getCartForUser;
4364
$this->cartRepository = $cartRepository;
65+
$this->customerCartResolver = $customerCartResolver
66+
?: ObjectManager::getInstance()->get(CustomerCartResolver::class);
67+
$this->quoteIdToMaskedQuoteId = $quoteIdToMaskedQuoteId
68+
?: ObjectManager::getInstance()->get(QuoteIdToMaskedQuoteIdInterface::class);
4469
}
4570

4671
/**
4772
* @inheritdoc
4873
*/
49-
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
50-
{
74+
public function resolve(
75+
Field $field,
76+
$context,
77+
ResolveInfo $info,
78+
array $value = null,
79+
array $args = null
80+
) {
5181
if (empty($args['source_cart_id'])) {
52-
throw new GraphQlInputException(__('Required parameter "source_cart_id" is missing'));
53-
}
54-
55-
if (empty($args['destination_cart_id'])) {
56-
throw new GraphQlInputException(__('Required parameter "destination_cart_id" is missing'));
82+
throw new GraphQlInputException(__(
83+
'Required parameter "source_cart_id" is missing'
84+
));
5785
}
5886

5987
/** @var ContextInterface $context */
6088
if (false === $context->getExtensionAttributes()->getIsCustomer()) {
61-
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
89+
throw new GraphQlAuthorizationException(__(
90+
'The current customer isn\'t authorized.'
91+
));
92+
}
93+
$currentUserId = $context->getUserId();
94+
95+
if (!isset($args['destination_cart_id'])) {
96+
try {
97+
$cart = $this->customerCartResolver->resolve($currentUserId);
98+
} catch (CouldNotSaveException $exception) {
99+
throw new GraphQlNoSuchEntityException(
100+
__('Could not create empty cart for customer'),
101+
$exception
102+
);
103+
}
104+
$customerMaskedCartId = $this->quoteIdToMaskedQuoteId->execute(
105+
(int) $cart->getId()
106+
);
107+
} else {
108+
if (empty($args['destination_cart_id'])) {
109+
throw new GraphQlInputException(__(
110+
'The parameter "destination_cart_id" cannot be empty'
111+
));
112+
}
62113
}
63114

64115
$guestMaskedCartId = $args['source_cart_id'];
65-
$customerMaskedCartId = $args['destination_cart_id'];
116+
$customerMaskedCartId = $customerMaskedCartId ?? $args['destination_cart_id'];
66117

67-
$currentUserId = $context->getUserId();
68118
$storeId = (int)$context->getExtensionAttributes()->getStore()->getId();
69119
// passing customerId as null enforces source cart should always be a guestcart
70-
$guestCart = $this->getCartForUser->execute($guestMaskedCartId, null, $storeId);
71-
$customerCart = $this->getCartForUser->execute($customerMaskedCartId, $currentUserId, $storeId);
120+
$guestCart = $this->getCartForUser->execute(
121+
$guestMaskedCartId,
122+
null,
123+
$storeId
124+
);
125+
$customerCart = $this->getCartForUser->execute(
126+
$customerMaskedCartId,
127+
$currentUserId,
128+
$storeId
129+
);
72130
$customerCart->merge($guestCart);
73131
$guestCart->setIsActive(false);
74132
$this->cartRepository->save($customerCart);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Mutation {
2020
setPaymentMethodOnCart(input: SetPaymentMethodOnCartInput): SetPaymentMethodOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentMethodOnCart")
2121
setGuestEmailOnCart(input: SetGuestEmailOnCartInput): SetGuestEmailOnCartOutput @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\SetGuestEmailOnCart")
2222
setPaymentMethodAndPlaceOrder(input: SetPaymentMethodAndPlaceOrderInput): PlaceOrderOutput @deprecated(reason: "Should use setPaymentMethodOnCart and placeOrder mutations in single request.") @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\SetPaymentAndPlaceOrder")
23-
mergeCarts(source_cart_id: String!, destination_cart_id: String!): Cart! @doc(description:"Merges the source cart into the destination cart") @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\MergeCarts")
23+
mergeCarts(source_cart_id: String!, destination_cart_id: String): Cart! @doc(description:"Merges the source cart into the destination cart") @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\MergeCarts")
2424
placeOrder(input: PlaceOrderInput): PlaceOrderOutput @resolver(class: "\\Magento\\QuoteGraphQl\\Model\\Resolver\\PlaceOrder")
2525
addProductsToCart(cartId: String!, cartItems: [CartItemInput!]!): AddProductsToCartOutput @doc(description:"Add any type of product to the cart") @resolver(class: "Magento\\QuoteGraphQl\\Model\\Resolver\\AddProductsToCart")
2626
}

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoriesQuery/CategoriesFilterTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,9 @@ public function testMinimumMatchQueryLength()
395395
* Test category image full name is returned
396396
*
397397
* @magentoApiDataFixture Magento/Catalog/_files/catalog_category_with_long_image_name.php
398+
* @magentoConfigFixture default_store web/seo/use_rewrites 0
398399
*/
399-
public function testCategoryImageName()
400+
public function testCategoryImageNameAndSeoDisabled()
400401
{
401402
/** @var CategoryCollection $categoryCollection */
402403
$categoryCollection = Bootstrap::getObjectManager()->get(CategoryCollection::class);
@@ -427,14 +428,13 @@ public function testCategoryImageName()
427428
$categories = $response['categories'];
428429
$this->assertArrayNotHasKey('errors', $response);
429430
$this->assertNotEmpty($response['categories']['items']);
430-
$expectedImageUrl = str_replace('index.php/', '', $expectedImageUrl);
431-
$categories['items'][0]['image'] = str_replace('index.php/', '', $categories['items'][0]['image']);
432431
$this->assertEquals('Parent Image Category', $categories['items'][0]['name']);
433432
$this->assertEquals($expectedImageUrl, $categories['items'][0]['image']);
434433
}
435434

436435
/**
437436
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
437+
* @magentoConfigFixture default_store web/seo/use_rewrites 1
438438
*/
439439
public function testFilterByUrlPathTopLevelCategory()
440440
{

dev/tests/api-functional/testsuite/Magento/GraphQl/Catalog/CategoryTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,45 @@ public function testCategoryImage(?string $imagePrefix)
660660
$this->assertEquals($expectedImageUrl, $childCategory['image']);
661661
}
662662

663+
/**
664+
* Testing breadcrumbs that shouldn't include disabled parent categories
665+
*
666+
* @magentoApiDataFixture Magento/Catalog/_files/categories.php
667+
*/
668+
public function testBreadCrumbsWithDisabledParentCategory()
669+
{
670+
$parentCategoryId = 4;
671+
$childCategoryId = 5;
672+
$category = $this->categoryRepository->get($parentCategoryId);
673+
$category->setIsActive(false);
674+
$this->categoryRepository->save($category);
675+
676+
$query = <<<QUERY
677+
{
678+
category(id: {$childCategoryId}) {
679+
name
680+
breadcrumbs {
681+
category_id
682+
category_name
683+
}
684+
}
685+
}
686+
QUERY;
687+
$response = $this->graphQlQuery($query);
688+
$expectedResponse = [
689+
'category' => [
690+
'name' => 'Category 1.1.1',
691+
'breadcrumbs' => [
692+
[
693+
'category_id' => 3,
694+
'category_name' => "Category 1",
695+
]
696+
]
697+
]
698+
];
699+
$this->assertEquals($expectedResponse, $response);
700+
}
701+
663702
/**
664703
* @return array
665704
*/

0 commit comments

Comments
 (0)