forked from magento/magento2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request magento#148 from magento-engcom/msi-inventory-mapp…
…ing-ui MSI: Contains ui element for stock editor mask
- Loading branch information
Showing
9 changed files
with
220 additions
and
15 deletions.
There are no files selected for viewing
14 changes: 0 additions & 14 deletions
14
app/code/Magento/InventoryCatalog/view/adminhtml/ui_component/inventory_stock_form.xml
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
app/code/Magento/InventorySales/Model/OptionSource/WebsiteSource.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventorySales\Model\OptionSource; | ||
|
||
use Magento\Framework\Data\OptionSourceInterface; | ||
use Magento\Store\Api\Data\WebsiteInterface; | ||
use Magento\Store\Api\WebsiteRepositoryInterface; | ||
|
||
/** | ||
* @api | ||
*/ | ||
class WebsiteSource implements OptionSourceInterface | ||
{ | ||
/** | ||
* @var WebsiteRepositoryInterface | ||
*/ | ||
private $websiteRepository; | ||
|
||
/** | ||
* @param WebsiteRepositoryInterface $websiteRepository | ||
*/ | ||
public function __construct( | ||
WebsiteRepositoryInterface $websiteRepository | ||
) { | ||
$this->websiteRepository = $websiteRepository; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function toOptionArray(): array | ||
{ | ||
$websites = []; | ||
foreach ($this->websiteRepository->getList() as $website) { | ||
if ($website->getCode() === WebsiteInterface::ADMIN_CODE) { | ||
continue; | ||
} | ||
$websites[] = [ | ||
'value' => $website->getCode(), | ||
'label' => $website->getName() | ||
]; | ||
} | ||
return $websites; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/code/Magento/InventorySales/Plugin/Inventory/Ui/StockDataProvider/SalesChannels.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventorySales\Plugin\Inventory\Ui\StockDataProvider; | ||
|
||
use Magento\Inventory\Ui\DataProvider\StockDataProvider; | ||
|
||
/** | ||
* Customize stock form. Add sales channels data | ||
*/ | ||
class SalesChannels | ||
{ | ||
/** | ||
* @param StockDataProvider $subject | ||
* @param array $data | ||
* @return array | ||
*/ | ||
public function afterGetData(StockDataProvider $subject, array $data): array | ||
{ | ||
if ('inventory_stock_form_data_source' === $subject->getName()) { | ||
foreach ($data as &$stockData) { | ||
$stockData['sales_channels'] = $this->getSalesChannelsDataForStock(); | ||
} | ||
unset($stockData); | ||
} elseif ($data['totalRecords'] > 0) { | ||
foreach ($data['items'] as &$stockData) { | ||
$stockData['sales_channels'] = $this->getSalesChannelsDataForStock(); | ||
} | ||
unset($stockData); | ||
} | ||
return $data; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getSalesChannelsDataForStock(): array | ||
{ | ||
// @todo: replace on real data | ||
return [ | ||
'websites' => ['base'], | ||
]; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
app/code/Magento/InventorySales/Ui/Component/Listing/Column/SalesChannels.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\InventorySales\Ui\Component\Listing\Column; | ||
|
||
use Magento\Ui\Component\Listing\Columns\Column; | ||
|
||
/** | ||
* Add grid column for sales channels | ||
*/ | ||
class SalesChannels extends Column | ||
{ | ||
/** | ||
* Prepare column value | ||
* | ||
* @param array $salesChannelData | ||
* @return string | ||
*/ | ||
private function prepareStockChannelData(array $salesChannelData) | ||
{ | ||
$websiteData = ''; | ||
foreach ($salesChannelData as $key => $channelData) { | ||
$websiteData .= $key . ': ' . implode(',', $channelData); | ||
} | ||
return $websiteData; | ||
} | ||
|
||
/** | ||
* Prepare data source | ||
* | ||
* @param array $dataSource | ||
* @return array | ||
*/ | ||
public function prepareDataSource(array $dataSource) | ||
{ | ||
if ($dataSource['data']['totalRecords'] > 0) { | ||
foreach ($dataSource['data']['items'] as &$row) { | ||
$row['sales_channels'] = $this->prepareStockChannelData($row['sales_channels']); | ||
} | ||
} | ||
unset($row); | ||
|
||
return $dataSource; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Inventory\Ui\DataProvider\StockDataProvider"> | ||
<plugin name="sales_channel_data" type="Magento\InventorySales\Plugin\Inventory\Ui\StockDataProvider\SalesChannels" /> | ||
</type> | ||
</config> |
38 changes: 38 additions & 0 deletions
38
app/code/Magento/InventorySales/view/adminhtml/ui_component/inventory_stock_form.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> | ||
<settings> | ||
<buttons> | ||
<button name="delete" class="Magento\InventoryCatalog\Ui\Component\Control\Stock\DeleteButton"/> | ||
</buttons> | ||
</settings> | ||
<fieldset name="sales_channels" sortOrder="30"> | ||
<settings> | ||
<label translate="true">Sales Channels</label> | ||
<collapsible>true</collapsible> | ||
<opened>true</opened> | ||
<dataScope>sales_channels</dataScope> | ||
</settings> | ||
<field name="websites" formElement="multiselect" sortOrder="20"> | ||
<settings> | ||
<dataType>text</dataType> | ||
<label translate="true">Websites</label> | ||
<validation> | ||
<rule name="required-entry" xsi:type="boolean">true</rule> | ||
</validation> | ||
</settings> | ||
<formElements> | ||
<multiselect> | ||
<settings> | ||
<options class="Magento\InventorySales\Model\OptionSource\WebsiteSource"/> | ||
</settings> | ||
</multiselect> | ||
</formElements> | ||
</field> | ||
</fieldset> | ||
</form> |
16 changes: 16 additions & 0 deletions
16
app/code/Magento/InventorySales/view/adminhtml/ui_component/inventory_stock_listing.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd"> | ||
<columns name="inventory_stock_listing_columns"> | ||
<column name="sales_channels" class="Magento\InventorySales\Ui\Component\Listing\Column\SalesChannels" sortOrder="30"> | ||
<settings> | ||
<label translate="true">Sales Channels</label> | ||
</settings> | ||
</column> | ||
</columns> | ||
</listing> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters