Skip to content

Commit

Permalink
Merge pull request magento#148 from magento-engcom/msi-inventory-mapp…
Browse files Browse the repository at this point in the history
…ing-ui

MSI: Contains ui element for stock editor mask
  • Loading branch information
Valeriy Nayda authored Oct 27, 2017
2 parents b27cd31 + 9034ba4 commit af4a7d3
Show file tree
Hide file tree
Showing 9 changed files with 220 additions and 15 deletions.

This file was deleted.

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;
}
}
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'],
];
}
}
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;
}
}
12 changes: 12 additions & 0 deletions app/code/Magento/InventorySales/etc/di.xml
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>
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>
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>
5 changes: 5 additions & 0 deletions app/code/Magento/Store/Api/Data/WebsiteInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
*/
interface WebsiteInterface extends \Magento\Framework\Api\ExtensibleDataInterface
{
/**
* contains code of admin website
*/
const ADMIN_CODE = 'admin';

/**
* @return int
*/
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Store/Setup/InstallSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Store\Api\Data\WebsiteInterface;

/**
* @codeCoverageIgnore
Expand Down Expand Up @@ -246,7 +247,7 @@ public function install(SchemaSetupInterface $setup, ModuleContextInterface $con
$installer->getTable('store_website'),
[
'website_id' => 0,
'code' => 'admin',
'code' => WebsiteInterface::ADMIN_CODE,
'name' => 'Admin',
'sort_order' => 0,
'default_group_id' => 0,
Expand Down

0 comments on commit af4a7d3

Please sign in to comment.