Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 0a24e12

Browse files
author
Volodymyr Kublytskyi
authored
Merge pull request #2306 from magento-engcom/msi-core-changes-no-history-2
[EngCom] Various fixes in Magento 2 core to support MSI
2 parents 7843add + c3d2df7 commit 0a24e12

File tree

57 files changed

+801
-296
lines changed

Some content is hidden

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

57 files changed

+801
-296
lines changed

app/code/Magento/Backend/view/adminhtml/web/template/dynamic-rows/grid.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
-->
77

8-
<div class="admin__field-complex" if="element.addButton">
8+
<div class="admin__field-complex" if="$data.addButton">
99
<div class="admin__field-complex-title">
1010
<span class="label" translate="'User Agent Rules'"></span>
1111
</div>
@@ -27,10 +27,10 @@
2727
<div class="admin__field admin__field-wide"
2828
visible="visible"
2929
disabled="disabled"
30-
css="element.setClasses(element)"
30+
css="$data.setClasses($data)"
3131
attr="'data-index': index">
32-
<label if="element.label" class="admin__field-label" attr="for: element.uid">
33-
<span translate="element.label"/>
32+
<label if="$data.label" class="admin__field-label" attr="for: $data.uid">
33+
<span translate="$data.label"/>
3434
</label>
3535

3636
<div class="admin__field-control" data-role="grid-wrapper">

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,29 @@ public function getProductsIdsBySkus(array $productSkuList)
505505

506506
$result = [];
507507
foreach ($this->getConnection()->fetchAll($select) as $row) {
508-
$result[$row['sku']] = $row['entity_id'];
508+
$result[$this->getResultKey($row['sku'], $productSkuList)] = $row['entity_id'];
509509
}
510510
return $result;
511511
}
512512

513+
/**
514+
* Return correct key for result array in getProductIdsBySku
515+
* Allows for different case sku to be passed in search array
516+
* with original cased sku to be passed back in result array
517+
*
518+
* @param string $sku
519+
* @param array $productSkuList
520+
* @return string
521+
*/
522+
private function getResultKey(string $sku, array $productSkuList): string
523+
{
524+
$key = array_search(strtolower($sku), array_map('strtolower', $productSkuList));
525+
if ($key !== false) {
526+
$sku = $productSkuList[$key];
527+
}
528+
return $sku;
529+
}
530+
513531
/**
514532
* Retrieve product entities info
515533
*

app/code/Magento/Catalog/Ui/DataProvider/Product/ProductDataProvider.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
namespace Magento\Catalog\Ui\DataProvider\Product;
77

88
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
11+
use Magento\Ui\DataProvider\Modifier\PoolInterface;
912

1013
/**
1114
* Class ProductDataProvider
@@ -33,8 +36,11 @@ class ProductDataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
3336
protected $addFilterStrategies;
3437

3538
/**
36-
* Construct
37-
*
39+
* @var PoolInterface
40+
*/
41+
private $modifiersPool;
42+
43+
/**
3844
* @param string $name
3945
* @param string $primaryFieldName
4046
* @param string $requestFieldName
@@ -43,6 +49,7 @@ class ProductDataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
4349
* @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
4450
* @param array $meta
4551
* @param array $data
52+
* @param PoolInterface|null $modifiersPool
4653
*/
4754
public function __construct(
4855
$name,
@@ -52,12 +59,14 @@ public function __construct(
5259
array $addFieldStrategies = [],
5360
array $addFilterStrategies = [],
5461
array $meta = [],
55-
array $data = []
62+
array $data = [],
63+
PoolInterface $modifiersPool = null
5664
) {
5765
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
5866
$this->collection = $collectionFactory->create();
5967
$this->addFieldStrategies = $addFieldStrategies;
6068
$this->addFilterStrategies = $addFilterStrategies;
69+
$this->modifiersPool = $modifiersPool ?: ObjectManager::getInstance()->get(PoolInterface::class);
6170
}
6271

6372
/**
@@ -72,10 +81,16 @@ public function getData()
7281
}
7382
$items = $this->getCollection()->toArray();
7483

75-
return [
84+
$data = [
7685
'totalRecords' => $this->getCollection()->getSize(),
7786
'items' => array_values($items),
7887
];
88+
89+
/** @var ModifierInterface $modifier */
90+
foreach ($this->modifiersPool->getModifiersInstances() as $modifier) {
91+
$data = $modifier->modifyData($data);
92+
}
93+
return $data;
7994
}
8095

8196
/**
@@ -110,4 +125,19 @@ public function addFilter(\Magento\Framework\Api\Filter $filter)
110125
parent::addFilter($filter);
111126
}
112127
}
128+
129+
/**
130+
* @inheritdoc
131+
*/
132+
public function getMeta()
133+
{
134+
$meta = parent::getMeta();
135+
136+
/** @var ModifierInterface $modifier */
137+
foreach ($this->modifiersPool->getModifiersInstances() as $modifier) {
138+
$meta = $modifier->modifyMeta($meta);
139+
}
140+
141+
return $meta;
142+
}
113143
}

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<item name="store_id" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\AddStoreFieldToCollection</item>
9393
</argument>
9494
<argument name="collectionFactory" xsi:type="object">\Magento\Catalog\Ui\DataProvider\Product\ProductCollectionFactory</argument>
95+
<argument name="modifiersPool" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool</argument>
9596
</arguments>
9697
</type>
9798
<type name="Magento\Catalog\Model\Product\Action">
@@ -165,6 +166,7 @@
165166
<argument name="pool" xsi:type="object">Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Pool</argument>
166167
</arguments>
167168
</type>
169+
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool" type="Magento\Ui\DataProvider\Modifier\Pool"/>
168170
<type name="Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\CustomOptions">
169171
<arguments>
170172
<argument name="scopeName" xsi:type="string">product_form.product_form</argument>

app/code/Magento/CatalogInventory/Helper/Stock.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/**
1818
* Class Stock
1919
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
20+
* @api
2021
*/
2122
class Stock
2223
{

app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
/**
1313
* CatalogInventory Stock Status per website Resource Model
1414
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
15+
* @api
1516
*/
1617
class Status extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1718
{

app/code/Magento/CatalogInventory/Model/StockRegistryStorage.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,16 @@ public function removeStockStatus($productId, $scopeId = null)
130130
unset($this->stockStatuses[$productId][$scopeId]);
131131
}
132132
}
133+
134+
/**
135+
* Clear cached entities
136+
*
137+
* @return void
138+
*/
139+
public function clean()
140+
{
141+
$this->stockItems = [];
142+
$this->stocks = [];
143+
$this->stockStatuses = [];
144+
}
133145
}

app/code/Magento/CatalogInventory/Observer/ProcessInventoryDataObserver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public function execute(EventObserver $observer)
6363
*/
6464
private function processStockData(Product $product)
6565
{
66-
/** @var Item $stockItem */
67-
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId());
68-
6966
$quantityAndStockStatus = $product->getData('quantity_and_stock_status');
7067
if (is_array($quantityAndStockStatus)) {
68+
/** @var Item $stockItem */
69+
$stockItem = $this->stockRegistry->getStockItem($product->getId(), $product->getStore()->getWebsiteId());
70+
7171
$quantityAndStockStatus = $this->prepareQuantityAndStockStatus($stockItem, $quantityAndStockStatus);
7272

7373
if ($quantityAndStockStatus) {

app/code/Magento/CatalogInventory/Ui/DataProvider/Product/Form/Modifier/AdvancedInventory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ private function prepareMeta()
210210
'scopeLabel' => '[GLOBAL]',
211211
]
212212
);
213-
214213
$container['arguments']['data']['config'] = [
215214
'formElement' => 'container',
216215
'componentType' => 'container',
@@ -227,6 +226,7 @@ private function prepareMeta()
227226
];
228227
$qty['arguments']['data']['config'] = [
229228
'component' => 'Magento_CatalogInventory/js/components/qty-validator-changer',
229+
'group' => 'quantity_and_stock_status_qty',
230230
'dataType' => 'number',
231231
'formElement' => 'input',
232232
'componentType' => 'field',

app/code/Magento/CatalogInventory/view/adminhtml/ui_component/product_form.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@
9999
</validation>
100100
<label translate="true">Qty</label>
101101
<dataScope>quantity_and_stock_status.qty</dataScope>
102+
<links>
103+
<link name="value">ns = ${ $.ns }, index = qty, group = quantity_and_stock_status_qty:value</link>
104+
</links>
102105
<imports>
103106
<link name="handleChanges">${$.provider}:data.product.stock_data.is_qty_decimal</link>
104107
<link name="visible">${$.provider}:data.product.stock_data.manage_stock</link>

app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,63 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
76
namespace Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation;
87

98
use Magento\Catalog\Model\Product;
10-
use Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider\QueryBuilder;
11-
use Magento\Customer\Model\Session;
9+
use Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation\DataProvider\SelectBuilderForAttribute;
1210
use Magento\Eav\Model\Config;
11+
use Magento\Framework\App\ObjectManager;
1312
use Magento\Framework\App\ResourceConnection;
1413
use Magento\Framework\App\ScopeResolverInterface;
1514
use Magento\Framework\DB\Adapter\AdapterInterface;
1615
use Magento\Framework\DB\Ddl\Table;
1716
use Magento\Framework\DB\Select;
1817
use Magento\Framework\Search\Adapter\Mysql\Aggregation\DataProviderInterface;
1918
use Magento\Framework\Search\Request\BucketInterface;
20-
use Magento\Framework\App\ObjectManager;
2119

22-
/**
23-
* DataProvider for Catalog search Mysql.
24-
*/
2520
class DataProvider implements DataProviderInterface
2621
{
2722
/**
2823
* @var Config
2924
*/
3025
private $eavConfig;
3126

32-
/**
33-
* @var Resource
34-
*/
35-
private $resource;
36-
3727
/**
3828
* @var ScopeResolverInterface
3929
*/
4030
private $scopeResolver;
4131

42-
/**
43-
* @var Session
44-
*/
45-
private $customerSession;
46-
4732
/**
4833
* @var AdapterInterface
4934
*/
5035
private $connection;
5136

5237
/**
53-
* @var QueryBuilder;
38+
* @var SelectBuilderForAttribute
5439
*/
55-
private $queryBuilder;
40+
private $selectBuilderForAttribute;
5641

5742
/**
5843
* @param Config $eavConfig
5944
* @param ResourceConnection $resource
6045
* @param ScopeResolverInterface $scopeResolver
61-
* @param Session $customerSession
62-
* @param QueryBuilder|null $queryBuilder
46+
* @param null $customerSession @deprecated
47+
* @param SelectBuilderForAttribute|null $selectBuilderForAttribute
48+
*
49+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6350
*/
6451
public function __construct(
6552
Config $eavConfig,
6653
ResourceConnection $resource,
6754
ScopeResolverInterface $scopeResolver,
68-
Session $customerSession,
69-
QueryBuilder $queryBuilder = null
55+
$customerSession,
56+
SelectBuilderForAttribute $selectBuilderForAttribute = null
7057
) {
7158
$this->eavConfig = $eavConfig;
72-
$this->resource = $resource;
7359
$this->connection = $resource->getConnection();
7460
$this->scopeResolver = $scopeResolver;
75-
$this->customerSession = $customerSession;
76-
$this->queryBuilder = $queryBuilder ?: ObjectManager::getInstance()->get(QueryBuilder::class);
61+
$this->selectBuilderForAttribute = $selectBuilderForAttribute
62+
?: ObjectManager::getInstance()->get(SelectBuilderForAttribute::class);
7763
}
7864

7965
/**
@@ -85,15 +71,15 @@ public function getDataSet(
8571
Table $entityIdsTable
8672
) {
8773
$currentScope = $this->scopeResolver->getScope($dimensions['scope']->getValue())->getId();
88-
8974
$attribute = $this->eavConfig->getAttribute(Product::ENTITY, $bucket->getField());
75+
$select = $this->getSelect();
9076

91-
$select = $this->queryBuilder->build(
92-
$attribute,
93-
$entityIdsTable->getName(),
94-
$currentScope,
95-
$this->customerSession->getCustomerGroupId()
77+
$select->joinInner(
78+
['entities' => $entityIdsTable->getName()],
79+
'main_table.entity_id = entities.entity_id',
80+
[]
9681
);
82+
$select = $this->selectBuilderForAttribute->build($select, $attribute, $currentScope);
9783

9884
return $select;
9985
}
@@ -105,4 +91,12 @@ public function execute(Select $select)
10591
{
10692
return $this->connection->fetchAssoc($select);
10793
}
94+
95+
/**
96+
* @return Select
97+
*/
98+
private function getSelect()
99+
{
100+
return $this->connection->select();
101+
}
108102
}

0 commit comments

Comments
 (0)