Skip to content

Commit af4a7d3

Browse files
author
Valeriy Nayda
authored
Merge pull request #148 from magento-engcom/msi-inventory-mapping-ui
MSI: Contains ui element for stock editor mask
2 parents b27cd31 + 9034ba4 commit af4a7d3

File tree

9 files changed

+220
-15
lines changed

9 files changed

+220
-15
lines changed

app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/inventory_stock_form.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventorySales\Model\OptionSource;
9+
10+
use Magento\Framework\Data\OptionSourceInterface;
11+
use Magento\Store\Api\Data\WebsiteInterface;
12+
use Magento\Store\Api\WebsiteRepositoryInterface;
13+
14+
/**
15+
* @api
16+
*/
17+
class WebsiteSource implements OptionSourceInterface
18+
{
19+
/**
20+
* @var WebsiteRepositoryInterface
21+
*/
22+
private $websiteRepository;
23+
24+
/**
25+
* @param WebsiteRepositoryInterface $websiteRepository
26+
*/
27+
public function __construct(
28+
WebsiteRepositoryInterface $websiteRepository
29+
) {
30+
$this->websiteRepository = $websiteRepository;
31+
}
32+
33+
/**
34+
* @inheritdoc
35+
*/
36+
public function toOptionArray(): array
37+
{
38+
$websites = [];
39+
foreach ($this->websiteRepository->getList() as $website) {
40+
if ($website->getCode() === WebsiteInterface::ADMIN_CODE) {
41+
continue;
42+
}
43+
$websites[] = [
44+
'value' => $website->getCode(),
45+
'label' => $website->getName()
46+
];
47+
}
48+
return $websites;
49+
}
50+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventorySales\Plugin\Inventory\Ui\StockDataProvider;
9+
10+
use Magento\Inventory\Ui\DataProvider\StockDataProvider;
11+
12+
/**
13+
* Customize stock form. Add sales channels data
14+
*/
15+
class SalesChannels
16+
{
17+
/**
18+
* @param StockDataProvider $subject
19+
* @param array $data
20+
* @return array
21+
*/
22+
public function afterGetData(StockDataProvider $subject, array $data): array
23+
{
24+
if ('inventory_stock_form_data_source' === $subject->getName()) {
25+
foreach ($data as &$stockData) {
26+
$stockData['sales_channels'] = $this->getSalesChannelsDataForStock();
27+
}
28+
unset($stockData);
29+
} elseif ($data['totalRecords'] > 0) {
30+
foreach ($data['items'] as &$stockData) {
31+
$stockData['sales_channels'] = $this->getSalesChannelsDataForStock();
32+
}
33+
unset($stockData);
34+
}
35+
return $data;
36+
}
37+
38+
/**
39+
* @return array
40+
*/
41+
private function getSalesChannelsDataForStock(): array
42+
{
43+
// @todo: replace on real data
44+
return [
45+
'websites' => ['base'],
46+
];
47+
}
48+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\InventorySales\Ui\Component\Listing\Column;
9+
10+
use Magento\Ui\Component\Listing\Columns\Column;
11+
12+
/**
13+
* Add grid column for sales channels
14+
*/
15+
class SalesChannels extends Column
16+
{
17+
/**
18+
* Prepare column value
19+
*
20+
* @param array $salesChannelData
21+
* @return string
22+
*/
23+
private function prepareStockChannelData(array $salesChannelData)
24+
{
25+
$websiteData = '';
26+
foreach ($salesChannelData as $key => $channelData) {
27+
$websiteData .= $key . ': ' . implode(',', $channelData);
28+
}
29+
return $websiteData;
30+
}
31+
32+
/**
33+
* Prepare data source
34+
*
35+
* @param array $dataSource
36+
* @return array
37+
*/
38+
public function prepareDataSource(array $dataSource)
39+
{
40+
if ($dataSource['data']['totalRecords'] > 0) {
41+
foreach ($dataSource['data']['items'] as &$row) {
42+
$row['sales_channels'] = $this->prepareStockChannelData($row['sales_channels']);
43+
}
44+
}
45+
unset($row);
46+
47+
return $dataSource;
48+
}
49+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
9+
<type name="Magento\Inventory\Ui\DataProvider\StockDataProvider">
10+
<plugin name="sales_channel_data" type="Magento\InventorySales\Plugin\Inventory\Ui\StockDataProvider\SalesChannels" />
11+
</type>
12+
</config>
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
9+
<settings>
10+
<buttons>
11+
<button name="delete" class="Magento\InventoryCatalog\Ui\Component\Control\Stock\DeleteButton"/>
12+
</buttons>
13+
</settings>
14+
<fieldset name="sales_channels" sortOrder="30">
15+
<settings>
16+
<label translate="true">Sales Channels</label>
17+
<collapsible>true</collapsible>
18+
<opened>true</opened>
19+
<dataScope>sales_channels</dataScope>
20+
</settings>
21+
<field name="websites" formElement="multiselect" sortOrder="20">
22+
<settings>
23+
<dataType>text</dataType>
24+
<label translate="true">Websites</label>
25+
<validation>
26+
<rule name="required-entry" xsi:type="boolean">true</rule>
27+
</validation>
28+
</settings>
29+
<formElements>
30+
<multiselect>
31+
<settings>
32+
<options class="Magento\InventorySales\Model\OptionSource\WebsiteSource"/>
33+
</settings>
34+
</multiselect>
35+
</formElements>
36+
</field>
37+
</fieldset>
38+
</form>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
9+
<columns name="inventory_stock_listing_columns">
10+
<column name="sales_channels" class="Magento\InventorySales\Ui\Component\Listing\Column\SalesChannels" sortOrder="30">
11+
<settings>
12+
<label translate="true">Sales Channels</label>
13+
</settings>
14+
</column>
15+
</columns>
16+
</listing>

app/code/Magento/Store/Api/Data/WebsiteInterface.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@
1313
*/
1414
interface WebsiteInterface extends \Magento\Framework\Api\ExtensibleDataInterface
1515
{
16+
/**
17+
* contains code of admin website
18+
*/
19+
const ADMIN_CODE = 'admin';
20+
1621
/**
1722
* @return int
1823
*/

app/code/Magento/Store/Setup/InstallSchema.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Magento\Framework\Setup\InstallSchemaInterface;
1212
use Magento\Framework\Setup\ModuleContextInterface;
1313
use Magento\Framework\Setup\SchemaSetupInterface;
14+
use Magento\Store\Api\Data\WebsiteInterface;
1415

1516
/**
1617
* @codeCoverageIgnore
@@ -246,7 +247,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
246247
$installer->getTable('store_website'),
247248
[
248249
'website_id' => 0,
249-
'code' => 'admin',
250+
'code' => WebsiteInterface::ADMIN_CODE,
250251
'name' => 'Admin',
251252
'sort_order' => 0,
252253
'default_group_id' => 0,

0 commit comments

Comments
 (0)