Skip to content

Commit 38b2773

Browse files
authored
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - #13011: [Port to 2.3-develop] Sort configurable attribute options by sort_order (by @wardcapp) - #12853: Fix import grouped products (by @PieterCappelle) - #12640: MAGETWO-61422 Respect Category Top Navigation Max Depth setting (by @arnoudhgz) Fixed GitHub Issues: - #7441: Configurable attribute options are not sorted (reported by @DariuszMaciejewski) has been fixed in #13011 by @wardcapp in 2.3-develop branch Related commits: 1. 0d7f309 - #12793: 2.2 Importing Group Products No Longer Works (reported by @mzenner1) has been fixed in #12853 by @PieterCappelle in 2.3-develop branch Related commits: 1. 01013fa 2. b566ca7 - #7543: Category Top Navigation / Maximal Depth configuration not working (reported by @ovsokolov) has been fixed in #12640 by @arnoudhgz in 2.3-develop branch Related commits: 1. 07233f2 2. 0a6ac4c 3. b6215b6 4. 15523e8
2 parents 0fc931c + f6af757 commit 38b2773

File tree

6 files changed

+125
-8
lines changed

6 files changed

+125
-8
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Category/Collection.php

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
namespace Magento\Catalog\Model\ResourceModel\Category;
77

88
use Magento\CatalogUrlRewrite\Model\CategoryUrlRewriteGenerator;
9+
use Magento\Framework\App\Config\ScopeConfigInterface;
10+
use Magento\Store\Model\ScopeInterface;
911

1012
/**
1113
* Category resource collection
1214
*
1315
* @api
1416
* @author Magento Core Team <core@magentocommerce.com>
17+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1518
* @since 100.0.2
1619
*/
1720
class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\AbstractCollection
@@ -58,6 +61,61 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac
5861
*/
5962
protected $_loadWithProductCount = false;
6063

64+
/**
65+
* Core store config
66+
*
67+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
68+
*/
69+
private $scopeConfig;
70+
71+
/**
72+
* Constructor
73+
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
74+
* @param \Psr\Log\LoggerInterface $logger
75+
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
76+
* @param \Magento\Framework\Event\ManagerInterface $eventManager
77+
* @param \Magento\Eav\Model\Config $eavConfig
78+
* @param \Magento\Framework\App\ResourceConnection $resource
79+
* @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
80+
* @param \Magento\Eav\Model\ResourceModel\Helper $resourceHelper
81+
* @param \Magento\Framework\Validator\UniversalFactory $universalFactory
82+
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
83+
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
84+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
85+
*
86+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
87+
*/
88+
public function __construct(
89+
\Magento\Framework\Data\Collection\EntityFactory $entityFactory,
90+
\Psr\Log\LoggerInterface $logger,
91+
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
92+
\Magento\Framework\Event\ManagerInterface $eventManager,
93+
\Magento\Eav\Model\Config $eavConfig,
94+
\Magento\Framework\App\ResourceConnection $resource,
95+
\Magento\Eav\Model\EntityFactory $eavEntityFactory,
96+
\Magento\Eav\Model\ResourceModel\Helper $resourceHelper,
97+
\Magento\Framework\Validator\UniversalFactory $universalFactory,
98+
\Magento\Store\Model\StoreManagerInterface $storeManager,
99+
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
100+
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig = null
101+
) {
102+
parent::__construct(
103+
$entityFactory,
104+
$logger,
105+
$fetchStrategy,
106+
$eventManager,
107+
$eavConfig,
108+
$resource,
109+
$eavEntityFactory,
110+
$resourceHelper,
111+
$universalFactory,
112+
$storeManager,
113+
$connection
114+
);
115+
$this->scopeConfig = $scopeConfig ?:
116+
\Magento\Framework\App\ObjectManager::getInstance()->get(ScopeConfigInterface::class);
117+
}
118+
61119
/**
62120
* Init collection and determine table names
63121
*
@@ -404,6 +462,23 @@ public function addRootLevelFilter()
404462
return $this;
405463
}
406464

465+
/**
466+
* Add navigation max depth filter
467+
*
468+
* @return $this
469+
*/
470+
public function addNavigationMaxDepthFilter()
471+
{
472+
$navigationMaxDepth = (int)$this->scopeConfig->getValue(
473+
'catalog/navigation/max_depth',
474+
ScopeInterface::SCOPE_STORE
475+
);
476+
if ($navigationMaxDepth > 0) {
477+
$this->addLevelFilter($navigationMaxDepth);
478+
}
479+
return $this;
480+
}
481+
407482
/**
408483
* Add order field
409484
*

app/code/Magento/Catalog/Plugin/Block/Topmenu.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ protected function getCategoryTree($storeId, $rootId)
183183
$collection->addFieldToFilter('path', ['like' => '1/' . $rootId . '/%']); //load only from store root
184184
$collection->addAttributeToFilter('include_in_menu', 1);
185185
$collection->addIsActiveFilter();
186+
$collection->addNavigationMaxDepthFilter();
186187
$collection->addUrlRewriteToResult();
187188
$collection->addOrder('level', Collection::SORT_ORDER_ASC);
188189
$collection->addOrder('position', Collection::SORT_ORDER_ASC);

app/code/Magento/ConfigurableProduct/Model/ResourceModel/Attribute/OptionSelectBuilder.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ public function getSelect(AbstractAttribute $superAttribute, int $productId, Sco
9191
]
9292
),
9393
[]
94+
)->joinInner(
95+
['attribute_option' => $this->attributeResource->getTable('eav_attribute_option')],
96+
'attribute_option.option_id = entity_value.value',
97+
[]
98+
)->order(
99+
'attribute_option.sort_order ASC'
94100
)->where(
95101
'super_attribute.product_id = ?',
96102
$productId

app/code/Magento/ConfigurableProduct/Test/Unit/Model/ResourceModel/Attribute/OptionSelectBuilderTest.php

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ protected function setUp()
6666
->disableOriginalConstructor()
6767
->getMockForAbstractClass();
6868
$this->select = $this->getMockBuilder(Select::class)
69-
->setMethods(['from', 'joinInner', 'joinLeft', 'where', 'columns'])
69+
->setMethods(['from', 'joinInner', 'joinLeft', 'where', 'columns', 'order'])
7070
->disableOriginalConstructor()
7171
->getMock();
7272
$this->connectionMock->expects($this->atLeastOnce())
@@ -112,10 +112,28 @@ public function testGetSelect()
112112
{
113113
$this->select->expects($this->exactly(1))->method('from')->willReturnSelf();
114114
$this->select->expects($this->exactly(1))->method('columns')->willReturnSelf();
115-
$this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf();
115+
$this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf();
116116
$this->select->expects($this->exactly(3))->method('joinLeft')->willReturnSelf();
117+
$this->select->expects($this->exactly(1))->method('order')->willReturnSelf();
117118
$this->select->expects($this->exactly(2))->method('where')->willReturnSelf();
118119

120+
$this->attributeResourceMock->expects($this->exactly(9))
121+
->method('getTable')
122+
->will(
123+
$this->returnValueMap(
124+
[
125+
['catalog_product_super_attribute', 'catalog_product_super_attribute value'],
126+
['catalog_product_entity', 'catalog_product_entity value'],
127+
['catalog_product_super_link', 'catalog_product_super_link value'],
128+
['eav_attribute', 'eav_attribute value'],
129+
['catalog_product_entity', 'catalog_product_entity value'],
130+
['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value'],
131+
['eav_attribute_option', 'eav_attribute_option value'],
132+
['eav_attribute_option_value', 'eav_attribute_option_value value']
133+
]
134+
)
135+
);
136+
119137
$this->abstractAttributeMock->expects($this->atLeastOnce())
120138
->method('getAttributeId')
121139
->willReturn('getAttributeId value');
@@ -138,10 +156,27 @@ public function testGetSelectWithBackendModel()
138156
{
139157
$this->select->expects($this->exactly(1))->method('from')->willReturnSelf();
140158
$this->select->expects($this->exactly(0))->method('columns')->willReturnSelf();
141-
$this->select->expects($this->exactly(5))->method('joinInner')->willReturnSelf();
159+
$this->select->expects($this->exactly(6))->method('joinInner')->willReturnSelf();
142160
$this->select->expects($this->exactly(1))->method('joinLeft')->willReturnSelf();
161+
$this->select->expects($this->exactly(1))->method('order')->willReturnSelf();
143162
$this->select->expects($this->exactly(2))->method('where')->willReturnSelf();
144163

164+
$this->attributeResourceMock->expects($this->exactly(7))
165+
->method('getTable')
166+
->will(
167+
$this->returnValueMap(
168+
[
169+
['catalog_product_super_attribute', 'catalog_product_super_attribute value'],
170+
['catalog_product_entity', 'catalog_product_entity value'],
171+
['catalog_product_super_link', 'catalog_product_super_link value'],
172+
['eav_attribute', 'eav_attribute value'],
173+
['catalog_product_entity', 'catalog_product_entity value'],
174+
['catalog_product_super_attribute_label', 'catalog_product_super_attribute_label value'],
175+
['eav_attribute_option', 'eav_attribute_option value']
176+
]
177+
)
178+
);
179+
145180
$this->abstractAttributeMock->expects($this->atLeastOnce())
146181
->method('getAttributeId')
147182
->willReturn('getAttributeId value');

app/code/Magento/GroupedImportExport/Model/Import/Product/Type/Grouped.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function saveData()
8989
foreach ($associatedSkusAndQtyPairs as $associatedSkuAndQty) {
9090
++$position;
9191
$associatedSkuAndQty = explode(self::SKU_QTY_DELIMITER, $associatedSkuAndQty);
92-
$associatedSku = isset($associatedSkuAndQty[0]) ? trim($associatedSkuAndQty[0]) : null;
92+
$associatedSku = isset($associatedSkuAndQty[0]) ? strtolower(trim($associatedSkuAndQty[0])) : null;
9393
if (isset($newSku[$associatedSku])) {
9494
$linkedProductId = $newSku[$associatedSku][$this->getProductEntityIdentifierField()];
9595
} elseif (isset($oldSku[$associatedSku])) {
@@ -99,7 +99,7 @@ public function saveData()
9999
}
100100
$scope = $this->_entityModel->getRowScope($rowData);
101101
if (Product::SCOPE_DEFAULT == $scope) {
102-
$productData = $newSku[$rowData[Product::COL_SKU]];
102+
$productData = $newSku[strtolower($rowData[Product::COL_SKU])];
103103
} else {
104104
$colAttrSet = Product::COL_ATTR_SET;
105105
$rowData[$colAttrSet] = $productData['attr_set_code'];

app/code/Magento/GroupedImportExport/Test/Unit/Model/Import/Product/Type/GroupedTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function saveDataProvider()
192192
'skus' => [
193193
'newSku' => [
194194
'sku_assoc1' => ['entity_id' => 1],
195-
'productSku' => ['entity_id' => 3, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
195+
'productsku' => ['entity_id' => 3, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
196196
],
197197
'oldSku' => ['sku_assoc2' => ['entity_id' => 2]]
198198
],
@@ -205,7 +205,7 @@ public function saveDataProvider()
205205
[
206206
'skus' => [
207207
'newSku' => [
208-
'productSku' => ['entity_id' => 1, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
208+
'productsku' => ['entity_id' => 1, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
209209
],
210210
'oldSku' => []
211211
],
@@ -247,7 +247,7 @@ public function testSaveDataScopeStore()
247247
{
248248
$this->entityModel->expects($this->once())->method('getNewSku')->will($this->returnValue([
249249
'sku_assoc1' => ['entity_id' => 1],
250-
'productSku' => ['entity_id' => 2, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
250+
'productsku' => ['entity_id' => 2, 'attr_set_code' => 'Default', 'type_id' => 'grouped']
251251
]));
252252
$this->entityModel->expects($this->once())->method('getOldSku')->will($this->returnValue([
253253
'sku_assoc2' => ['entity_id' => 3]

0 commit comments

Comments
 (0)