Skip to content

Commit 6cf4b06

Browse files
committed
Merge branch '2.4-develop' into ECP-98
2 parents d99c4f0 + 847f941 commit 6cf4b06

File tree

33 files changed

+992
-192
lines changed

33 files changed

+992
-192
lines changed

app/code/Magento/Catalog/Model/Product/ProductFrontendAction/Synchronizer.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,16 @@ private function filterNewestActions(array $productsData, $typeId)
125125
$lifetime = $this->getLifeTimeByNamespace($typeId);
126126
$actionsNumber = $lifetime * self::TIME_TO_DO_ONE_ACTION;
127127

128-
uasort($productsData, function (array $firstProduct, array $secondProduct) {
129-
return $firstProduct['added_at'] > $secondProduct['added_at'];
130-
});
128+
uasort(
129+
$productsData,
130+
function (array $firstProduct, array $secondProduct) {
131+
if (isset($firstProduct['added_at'], $secondProduct['added_at'])) {
132+
return $firstProduct['added_at'] > $secondProduct['added_at'];
133+
}
134+
135+
return false;
136+
}
137+
);
131138

132139
return array_slice($productsData, 0, $actionsNumber, true);
133140
}
@@ -185,15 +192,17 @@ public function syncActions(array $productsData, $typeId)
185192

186193
foreach ($productsData as $productId => $productData) {
187194
/** @var ProductFrontendActionInterface $action */
188-
$action = $this->productFrontendActionFactory->create([
189-
'data' => [
190-
'visitor_id' => $customerId ? null : $visitorId,
191-
'customer_id' => $this->session->getCustomerId(),
192-
'added_at' => $productData['added_at'],
193-
'product_id' => $productId,
194-
'type_id' => $typeId
195+
$action = $this->productFrontendActionFactory->create(
196+
[
197+
'data' => [
198+
'visitor_id' => $customerId ? null : $visitorId,
199+
'customer_id' => $this->session->getCustomerId(),
200+
'added_at' => $productData['added_at'],
201+
'product_id' => $productId,
202+
'type_id' => $typeId
203+
]
195204
]
196-
]);
205+
);
197206

198207
$this->entityManager->save($action);
199208
}

app/code/Magento/Catalog/Setup/Patch/Data/UpdateDefaultAttributeValue.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
67

78
namespace Magento\Catalog\Setup\Patch\Data;
89

910
use Magento\Catalog\Setup\CategorySetup;
1011
use Magento\Catalog\Setup\CategorySetupFactory;
11-
use Magento\Framework\App\ResourceConnection;
1212
use Magento\Framework\Setup\ModuleDataSetupInterface;
1313
use Magento\Framework\Setup\Patch\DataPatchInterface;
1414
use Magento\Framework\Setup\Patch\PatchVersionInterface;
1515

1616
/**
17-
* Class UpdateDefaultAttributeValue
18-
* @package Magento\Catalog\Setup\Patch
17+
* Updates 'is_anchor' attribute default value.
1918
*/
2019
class UpdateDefaultAttributeValue implements DataPatchInterface, PatchVersionInterface
2120
{
@@ -30,7 +29,6 @@ class UpdateDefaultAttributeValue implements DataPatchInterface, PatchVersionInt
3029
private $categorySetupFactory;
3130

3231
/**
33-
* PatchInitial constructor.
3432
* @param ModuleDataSetupInterface $moduleDataSetup
3533
* @param CategorySetupFactory $categorySetupFactory
3634
*/
@@ -43,17 +41,24 @@ public function __construct(
4341
}
4442

4543
/**
46-
* {@inheritdoc}
44+
* @inheritdoc
4745
*/
4846
public function apply()
4947
{
5048
/** @var CategorySetup $categorySetup */
5149
$categorySetup = $this->categorySetupFactory->create(['setup' => $this->moduleDataSetup]);
52-
$categorySetup->updateAttribute(3, 54, 'default_value', 1);
50+
$categorySetup->updateAttribute(
51+
CategorySetup::CATEGORY_ENTITY_TYPE_ID,
52+
'is_anchor',
53+
'default_value',
54+
1
55+
);
56+
57+
return $this;
5358
}
5459

5560
/**
56-
* {@inheritdoc}
61+
* @inheritdoc
5762
*/
5863
public static function getDependencies()
5964
{
@@ -63,15 +68,15 @@ public static function getDependencies()
6368
}
6469

6570
/**
66-
* {@inheritdoc}
71+
* @inheritdoc
6772
*/
6873
public static function getVersion()
6974
{
7075
return '2.0.3';
7176
}
7277

7378
/**
74-
* {@inheritdoc}
79+
* @inheritdoc
7580
*/
7681
public function getAliases()
7782
{

app/code/Magento/Catalog/view/frontend/layout/default.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
<item name="updateRequestConfig" xsi:type="array">
2727
<item name="url" xsi:type="serviceUrl" path="/products-render-info"/>
2828
</item>
29+
<item name="requestConfig" xsi:type="array">
30+
<item name="syncUrl" xsi:type="url" path="catalog/product/frontend_action_synchronize"/>
31+
</item>
2932
</item>
3033
</argument>
3134
</arguments>

app/code/Magento/CatalogGraphQl/DataProvider/Product/SearchCriteriaBuilder.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ private function addVisibilityFilter(SearchCriteriaInterface $searchCriteria, bo
129129
? $this->visibility->getVisibleInSearchIds()
130130
: $this->visibility->getVisibleInCatalogIds();
131131

132-
$this->addFilter($searchCriteria, 'visibility', $visibilityIds);
132+
$this->addFilter($searchCriteria, 'visibility', $visibilityIds, 'in');
133133
}
134134

135135
/**
@@ -155,13 +155,20 @@ private function preparePriceAggregation(SearchCriteriaInterface $searchCriteria
155155
* @param SearchCriteriaInterface $searchCriteria
156156
* @param string $field
157157
* @param mixed $value
158+
* @param string|null $condition
158159
*/
159-
private function addFilter(SearchCriteriaInterface $searchCriteria, string $field, $value): void
160-
{
160+
private function addFilter(
161+
SearchCriteriaInterface $searchCriteria,
162+
string $field,
163+
$value,
164+
?string $condition = null
165+
): void {
161166
$filter = $this->filterBuilder
162167
->setField($field)
163168
->setValue($value)
169+
->setConditionType($condition)
164170
->create();
171+
165172
$this->filterGroupBuilder->addFilter($filter);
166173
$filterGroups = $searchCriteria->getFilterGroups();
167174
$filterGroups[] = $this->filterGroupBuilder->create();

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

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,20 @@
77

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

10-
use Magento\Catalog\Api\ProductRepositoryInterface;
1110
use Magento\CatalogGraphQl\DataProvider\Product\SearchCriteriaBuilder;
12-
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\Search;
13-
use Magento\Framework\App\ObjectManager;
1411
use Magento\Framework\GraphQl\Config\Element\Field;
1512
use Magento\Framework\GraphQl\Query\ResolverInterface;
1613
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
17-
use Magento\Framework\GraphQl\Query\Resolver\Argument\SearchCriteria\Builder;
18-
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\Filter;
1914
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
15+
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\ProductQueryInterface;
2016

2117
/**
2218
* Category products resolver, used by GraphQL endpoints to retrieve products assigned to a category
2319
*/
2420
class Products implements ResolverInterface
2521
{
2622
/**
27-
* @var \Magento\Catalog\Api\ProductRepositoryInterface
28-
*/
29-
private $productRepository;
30-
31-
/**
32-
* @var Builder
33-
* @deprecated
34-
*/
35-
private $searchCriteriaBuilder;
36-
37-
/**
38-
* @var Filter
39-
* @deprecated
40-
*/
41-
private $filterQuery;
42-
43-
/**
44-
* @var Search
23+
* @var ProductQueryInterface
4524
*/
4625
private $searchQuery;
4726

@@ -51,25 +30,15 @@ class Products implements ResolverInterface
5130
private $searchApiCriteriaBuilder;
5231

5332
/**
54-
* @param ProductRepositoryInterface $productRepository
55-
* @param Builder $searchCriteriaBuilder
56-
* @param Filter $filterQuery
57-
* @param Search $searchQuery
33+
* @param ProductQueryInterface $searchQuery
5834
* @param SearchCriteriaBuilder $searchApiCriteriaBuilder
5935
*/
6036
public function __construct(
61-
ProductRepositoryInterface $productRepository,
62-
Builder $searchCriteriaBuilder,
63-
Filter $filterQuery,
64-
Search $searchQuery = null,
65-
SearchCriteriaBuilder $searchApiCriteriaBuilder = null
37+
ProductQueryInterface $searchQuery,
38+
SearchCriteriaBuilder $searchApiCriteriaBuilder
6639
) {
67-
$this->productRepository = $productRepository;
68-
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
69-
$this->filterQuery = $filterQuery;
70-
$this->searchQuery = $searchQuery ?? ObjectManager::getInstance()->get(Search::class);
71-
$this->searchApiCriteriaBuilder = $searchApiCriteriaBuilder ??
72-
ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
40+
$this->searchQuery = $searchQuery;
41+
$this->searchApiCriteriaBuilder = $searchApiCriteriaBuilder;
7342
}
7443

7544
/**
@@ -94,18 +63,17 @@ public function resolve(
9463
'eq' => $value['id']
9564
]
9665
];
97-
$searchCriteria = $this->searchApiCriteriaBuilder->build($args, false);
98-
$searchResult = $this->searchQuery->getResult($searchCriteria, $info);
66+
$searchResult = $this->searchQuery->getResult($args, $info);
9967

10068
//possible division by 0
101-
if ($searchCriteria->getPageSize()) {
102-
$maxPages = ceil($searchResult->getTotalCount() / $searchCriteria->getPageSize());
69+
if ($searchResult->getPageSize()) {
70+
$maxPages = ceil($searchResult->getTotalCount() / $searchResult->getPageSize());
10371
} else {
10472
$maxPages = 0;
10573
}
10674

107-
$currentPage = $searchCriteria->getCurrentPage();
108-
if ($searchCriteria->getCurrentPage() > $maxPages && $searchResult->getTotalCount() > 0) {
75+
$currentPage = $searchResult->getCurrentPage();
76+
if ($searchResult->getCurrentPage() > $maxPages && $searchResult->getTotalCount() > 0) {
10977
$currentPage = new GraphQlInputException(
11078
__(
11179
'currentPage value %1 specified is greater than the number of pages available.',
@@ -118,7 +86,7 @@ public function resolve(
11886
'total_count' => $searchResult->getTotalCount(),
11987
'items' => $searchResult->getProductsSearchResult(),
12088
'page_info' => [
121-
'page_size' => $searchCriteria->getPageSize(),
89+
'page_size' => $searchResult->getPageSize(),
12290
'current_page' => $currentPage,
12391
'total_pages' => $maxPages
12492
]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function getMinimumProductPrice(SaleableInterface $product, StoreInterfa
8686
$priceProvider = $this->priceProviderPool->getProviderByProductType($product->getTypeId());
8787
$regularPrice = $priceProvider->getMinimalRegularPrice($product)->getValue();
8888
$finalPrice = $priceProvider->getMinimalFinalPrice($product)->getValue();
89-
$minPriceArray = $this->formatPrice($regularPrice, $finalPrice, $store);
89+
$minPriceArray = $this->formatPrice((float) $regularPrice, (float) $finalPrice, $store);
9090
$minPriceArray['model'] = $product;
9191
return $minPriceArray;
9292
}
@@ -103,7 +103,7 @@ private function getMaximumProductPrice(SaleableInterface $product, StoreInterfa
103103
$priceProvider = $this->priceProviderPool->getProviderByProductType($product->getTypeId());
104104
$regularPrice = $priceProvider->getMaximalRegularPrice($product)->getValue();
105105
$finalPrice = $priceProvider->getMaximalFinalPrice($product)->getValue();
106-
$maxPriceArray = $this->formatPrice($regularPrice, $finalPrice, $store);
106+
$maxPriceArray = $this->formatPrice((float) $regularPrice, (float) $finalPrice, $store);
107107
$maxPriceArray['model'] = $product;
108108
return $maxPriceArray;
109109
}

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

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

88
namespace Magento\CatalogGraphQl\Model\Resolver;
99

10+
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\ProductQueryInterface;
1011
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
1112
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\Filter;
1213
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\Search;
@@ -24,51 +25,24 @@
2425
class Products implements ResolverInterface
2526
{
2627
/**
27-
* @var Builder
28-
* @deprecated
29-
*/
30-
private $searchCriteriaBuilder;
31-
32-
/**
33-
* @var Search
28+
* @var ProductQueryInterface
3429
*/
3530
private $searchQuery;
3631

37-
/**
38-
* @var Filter
39-
* @deprecated
40-
*/
41-
private $filterQuery;
42-
43-
/**
44-
* @var SearchFilter
45-
* @deprecated
46-
*/
47-
private $searchFilter;
48-
4932
/**
5033
* @var SearchCriteriaBuilder
5134
*/
5235
private $searchApiCriteriaBuilder;
5336

5437
/**
55-
* @param Builder $searchCriteriaBuilder
56-
* @param Search $searchQuery
57-
* @param Filter $filterQuery
58-
* @param SearchFilter $searchFilter
38+
* @param ProductQueryInterface $searchQuery
5939
* @param SearchCriteriaBuilder|null $searchApiCriteriaBuilder
6040
*/
6141
public function __construct(
62-
Builder $searchCriteriaBuilder,
63-
Search $searchQuery,
64-
Filter $filterQuery,
65-
SearchFilter $searchFilter,
42+
ProductQueryInterface $searchQuery,
6643
SearchCriteriaBuilder $searchApiCriteriaBuilder = null
6744
) {
68-
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
6945
$this->searchQuery = $searchQuery;
70-
$this->filterQuery = $filterQuery;
71-
$this->searchFilter = $searchFilter;
7246
$this->searchApiCriteriaBuilder = $searchApiCriteriaBuilder ??
7347
\Magento\Framework\App\ObjectManager::getInstance()->get(SearchCriteriaBuilder::class);
7448
}
@@ -95,11 +69,7 @@ public function resolve(
9569
);
9670
}
9771

98-
//get product children fields queried
99-
$productFields = (array)$info->getFieldSelection(1);
100-
$includeAggregations = isset($productFields['filters']) || isset($productFields['aggregations']);
101-
$searchCriteria = $this->searchApiCriteriaBuilder->build($args, $includeAggregations);
102-
$searchResult = $this->searchQuery->getResult($searchCriteria, $info, $args);
72+
$searchResult = $this->searchQuery->getResult($args, $info);
10373

10474
if ($searchResult->getCurrentPage() > $searchResult->getTotalPages() && $searchResult->getTotalCount() > 0) {
10575
throw new GraphQlInputException(

0 commit comments

Comments
 (0)