Skip to content

Commit 2cb7026

Browse files
committed
Merge remote-tracking branch 'origin/2.3-develop' into fix/typos/batch
2 parents 4a13339 + d1ebc31 commit 2cb7026

File tree

217 files changed

+6131
-2920
lines changed

Some content is hidden

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

217 files changed

+6131
-2920
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function build($productId)
8787
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
8888
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
8989
->order('t.min_price ' . Select::SQL_ASC)
90+
->order(BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField . ' ' . Select::SQL_ASC)
9091
->limit(1);
9192
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
9293

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByBasePrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ public function build($productId)
9595
->where('t.attribute_id = ?', $priceAttribute->getAttributeId())
9696
->where('t.value IS NOT NULL')
9797
->order('t.value ' . Select::SQL_ASC)
98+
->order(BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField . ' ' . Select::SQL_ASC)
9899
->limit(1);
99100
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
100101

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderBySpecialPrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public function build($productId)
139139
'special_to.value IS NULL OR ' . $connection->getDatePartSql('special_to.value') .' >= ?',
140140
$currentDate
141141
)->order('t.value ' . Select::SQL_ASC)
142+
->order(BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField . ' ' . Select::SQL_ASC)
142143
->limit(1);
143144
$specialPrice = $this->baseSelectProcessor->process($specialPrice);
144145

app/code/Magento/Catalog/Model/ResourceModel/Product/LinkedProductSelectBuilderByTierPrice.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ public function build($productId)
9797
->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())
9898
->where('t.qty = ?', 1)
9999
->order('t.value ' . Select::SQL_ASC)
100+
->order(BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS . '.' . $linkField . ' ' . Select::SQL_ASC)
100101
->limit(1);
101102
$priceSelect = $this->baseSelectProcessor->process($priceSelect);
102103

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPriceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testBuild()
8484
$select->expects($this->any())->method('from')->willReturnSelf();
8585
$select->expects($this->any())->method('joinInner')->willReturnSelf();
8686
$select->expects($this->any())->method('where')->willReturnSelf();
87-
$select->expects($this->once())->method('order')->willReturnSelf();
87+
$select->expects($this->exactly(2))->method('order')->willReturnSelf();
8888
$select->expects($this->once())->method('limit')->willReturnSelf();
8989
$this->resourceMock->expects($this->any())->method('getConnection')->willReturn($connection);
9090
$this->metadataPoolMock->expects($this->once())->method('getMetadata')->willReturn($metadata);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogGraphQl\Model;
8+
9+
use Magento\Framework\GraphQl\Config\Data\TypeResolverInterface;
10+
use Magento\Framework\Exception\InputException;
11+
12+
/**
13+
* {@inheritdoc}
14+
*/
15+
class ConcreteTypeResolver implements TypeResolverInterface
16+
{
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
public function resolveType(array $data)
21+
{
22+
if (!isset($data['type_id'])) {
23+
throw new InputException(
24+
__('%1 key doesn\'t exist in product data', [$data['type_id']])
25+
);
26+
}
27+
28+
if ($data['type_id'] == 'simple') {
29+
return 'SimpleProduct';
30+
}
31+
32+
return null;
33+
}
34+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogGraphQl\Model\Config;
8+
9+
use Magento\Framework\Config\ReaderInterface;
10+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
11+
use Magento\Framework\GraphQl\Type\Entity\MapperInterface;
12+
use Magento\Framework\Reflection\TypeProcessor;
13+
use Magento\EavGraphQl\Model\Resolver\Query\Type;
14+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\CollectionFactory;
15+
use Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection;
16+
17+
/**
18+
* Adds custom/eav attribute to Catalog product types in the GraphQL config.
19+
*/
20+
class AttributeReader implements ReaderInterface
21+
{
22+
/**
23+
* @var MapperInterface
24+
*/
25+
private $mapper;
26+
27+
/**
28+
* @var Type
29+
*/
30+
private $typeLocator;
31+
32+
/**
33+
* @var CollectionFactory
34+
*/
35+
private $collectionFactory;
36+
37+
/**
38+
* @param MapperInterface $mapper
39+
* @param Type $typeLocator
40+
* @param CollectionFactory $collectionFactory
41+
*/
42+
public function __construct(
43+
MapperInterface $mapper,
44+
Type $typeLocator,
45+
CollectionFactory $collectionFactory
46+
) {
47+
$this->mapper = $mapper;
48+
$this->typeLocator = $typeLocator;
49+
$this->collectionFactory = $collectionFactory;
50+
}
51+
52+
/**
53+
* Read configuration scope
54+
*
55+
* @param string|null $scope
56+
* @return array
57+
* @throws GraphQlInputException
58+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
59+
*/
60+
public function read($scope = null)
61+
{
62+
$targetStructures = $this->mapper->getMappedTypes(\Magento\Catalog\Model\Product::ENTITY);
63+
$config =[];
64+
/** @var Collection $collection */
65+
$collection = $this->collectionFactory->create();
66+
$collection->addFieldToFilter('is_user_defined', '1');
67+
$collection->addFieldToFilter('attribute_code', ['neq' => 'cost']);
68+
/** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $attribute */
69+
foreach ($collection as $attribute) {
70+
$attributeCode = $attribute->getAttributeCode();
71+
$locatedType = $this->typeLocator->getType(
72+
$attributeCode,
73+
\Magento\Catalog\Model\Product::ENTITY
74+
) ?: 'String';
75+
$locatedType = $locatedType === TypeProcessor::NORMALIZED_ANY_TYPE ? 'String' : ucfirst($locatedType);
76+
foreach ($targetStructures as $structure) {
77+
$config[$structure]['fields'][$attributeCode] = [
78+
'name' => $attributeCode,
79+
'type' => $locatedType,
80+
'arguments' => []
81+
];
82+
}
83+
}
84+
85+
return $config;
86+
}
87+
}

app/code/Magento/GraphQlCatalog/Model/Resolver/Products.php renamed to app/code/Magento/CatalogGraphQl/Model/Resolver/Products.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,14 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\GraphQlCatalog\Model\Resolver;
7+
namespace Magento\CatalogGraphQl\Model\Resolver;
88

9-
use Magento\Framework\Api\Search\SearchCriteriaInterfaceFactory;
109
use Magento\GraphQl\Model\ResolverContextInterface;
1110
use Magento\GraphQl\Model\ResolverInterface;
1211
use Magento\Framework\GraphQl\Argument\SearchCriteria\Builder;
1312
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
14-
use Magento\GraphQl\Model\ContextInterface;
15-
use Magento\GraphQlCatalog\Model\Resolver\Products\Query\Filter;
16-
use Magento\GraphQlCatalog\Model\Resolver\Products\Query\Search;
13+
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\Filter;
14+
use Magento\CatalogGraphQl\Model\Resolver\Products\Query\Search;
1715

1816
/**
1917
* Products field resolver, used for GraphQL request processing.
@@ -63,7 +61,12 @@ public function resolve(array $args, ResolverContextInterface $context)
6361
$searchResult = $this->filterQuery->getResult($searchCriteria);
6462
}
6563

66-
$maxPages = ceil($searchResult->getTotalCount() / $searchCriteria->getPageSize());
64+
//possible division by 0
65+
if ($searchCriteria->getPageSize()) {
66+
$maxPages = ceil($searchResult->getTotalCount() / $searchCriteria->getPageSize());
67+
} else {
68+
$maxPages = 0;
69+
}
6770
if ($searchCriteria->getCurrentPage() > $maxPages && $searchResult->getTotalCount() > 0) {
6871
throw new GraphQlInputException(
6972
__(

app/code/Magento/GraphQlCatalog/Model/Resolver/Products/DataProvider/Product.php renamed to app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider;
7+
namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider;
88

99
use Magento\Catalog\Api\ProductRepositoryInterface;
1010
use Magento\Catalog\Model\Product\Option;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
namespace Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product\Formatter;
7+
namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\Formatter;
88

99
use Magento\Catalog\Model\Product;
10-
use Magento\GraphQlCatalog\Model\Resolver\Products\DataProvider\Product\FormatterInterface;
10+
use Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Product\FormatterInterface;
1111

1212
/**
1313
* Grabs the data from the product

0 commit comments

Comments
 (0)