Skip to content

Commit

Permalink
Merge pull request magento#973 from magento-engcom/851-fix-for-assosi…
Browse files Browse the repository at this point in the history
…ated-product-grid

MSI-851: Remove 'quantity_per_source' declaration from product_listin…
  • Loading branch information
Valeriy Nayda authored Apr 20, 2018
2 parents 3f06722 + 31db831 commit f355146
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 175 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
namespace Magento\InventoryCatalogAdminUi\Ui\DataProvider\Product\Listing\Modifier;

use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Inventory\Model\SourceItem\Command\GetSourceItemsBySkuInterface;
use Magento\InventoryApi\Api\SourceRepositoryInterface;
use Magento\InventoryCatalog\Model\IsSingleSourceModeInterface;
use Magento\InventoryConfiguration\Model\IsSourceItemsAllowedForProductTypeInterface;
use Magento\Ui\Component\Form\Element\DataType\Text;
use Magento\Ui\Component\Listing\Columns\Column;

/**
* Quantity Per Source modifier on CatalogInventory Product Grid
Expand All @@ -20,31 +26,121 @@ class QuantityPerSource extends AbstractModifier
*/
private $isSingleSourceMode;

/**
* @var IsSourceItemsAllowedForProductTypeInterface
*/
private $isSourceItemsAllowedForProductType;

/**
* @var SourceRepositoryInterface
*/
private $sourceRepository;

/**
* @var GetSourceItemsBySkuInterface
*/
private $getSourceItemsBySku;

/**
* @param IsSingleSourceModeInterface $isSingleSourceMode
* @param IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType
* @param SourceRepositoryInterface $sourceRepository
* @param GetSourceItemsBySkuInterface $getSourceItemsBySku
*/
public function __construct(
IsSingleSourceModeInterface $isSingleSourceMode
IsSingleSourceModeInterface $isSingleSourceMode,
IsSourceItemsAllowedForProductTypeInterface $isSourceItemsAllowedForProductType,
SourceRepositoryInterface $sourceRepository,
GetSourceItemsBySkuInterface $getSourceItemsBySku
) {
$this->isSingleSourceMode = $isSingleSourceMode;
$this->isSourceItemsAllowedForProductType = $isSourceItemsAllowedForProductType;
$this->sourceRepository = $sourceRepository;
$this->getSourceItemsBySku = $getSourceItemsBySku;
}

/**
* @inheritdoc
*/
public function modifyData(array $data)
{
if (0 === $data['totalRecords'] || true === $this->isSingleSourceMode->execute()) {
return $data;
}

foreach ($data['items'] as &$item) {
$item['quantity_per_source'] = $this->isSourceItemsAllowedForProductType->execute($item['type_id']) === true
? $this->getSourceItemsData($item['sku'])
: [];
}
unset($item);

return $data;
}

/**
* @param string $sku
* @return array
* @throws NoSuchEntityException
*/
private function getSourceItemsData(string $sku): array
{
$sourceItems = $this->getSourceItemsBySku->execute($sku)->getItems();

$sourceItemsData = [];
foreach ($sourceItems as $sourceItem) {
$source = $this->sourceRepository->get($sourceItem->getSourceCode());
$qty = (float)$sourceItem->getQuantity();

$sourceItemsData[] = [
'source_name' => $source->getName(),
'qty' => $qty,
];
}
return $sourceItemsData;
}

/**
* @inheritdoc
*/
public function modifyMeta(array $meta)
{
if (true === $this->isSingleSourceMode->execute()) {
$meta['product_columns']['children']['quantity_per_source']['arguments'] = null;
return $meta;
}

$meta = array_replace_recursive($meta, [
'product_columns' => [
'children' => [
'quantity_per_source' => $this->getQuantityPerSourceMeta(),
'qty' => [
'arguments' => null,
],
],
],
]);
return $meta;
}

/**
* @return array
*/
private function getQuantityPerSourceMeta(): array
{
return [
'arguments' => [
'data' => [
'config' => [
'sortOrder' => 76,
'filter' => false,
'sortable' => false,
'label' => __('Quantity per Source'),
'dataType' => Text::NAME,
'componentType' => Column::NAME,
'component' => 'Magento_InventoryCatalogAdminUi/js/product/grid/cell/quantity-per-source',
]
],
],
];
}
}
4 changes: 0 additions & 4 deletions app/code/Magento/InventoryCatalogAdminUi/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool">
<arguments>
<argument name="modifiers" xsi:type="array">
<item name="quantity" xsi:type="array">
<item name="class" xsi:type="string">Magento\InventoryCatalogAdminUi\Ui\DataProvider\Product\Listing\Modifier\Quantity</item>
<item name="sortOrder" xsi:type="number">100</item>
</item>
<item name="quantity_per_source" xsi:type="array">
<item name="class" xsi:type="string">Magento\InventoryCatalogAdminUi\Ui\DataProvider\Product\Listing\Modifier\QuantityPerSource</item>
<item name="sortOrder" xsi:type="number">300</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<fieldset name="sources" sortOrder="5" component="Magento_InventoryCatalogAdminUi/js/product/form/components/source-items">
<fieldset name="sources" sortOrder="5" component="Magento_InventoryCatalogAdminUi/js/product/form/source-items">
<settings>
<label translate="true">Sources</label>
<collapsible>true</collapsible>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@
-->
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="product_columns">
<column name="quantity_per_source"
class="Magento\InventoryCatalogAdminUi\Ui\Component\Listing\Column\SourceItems"
component="Magento_InventoryCatalogAdminUi/js/product/grid/cell/source-items"
sortOrder="76">
<settings>
<filter>false</filter>
<sortable>false</sortable>
<label translate="true">Quantity per Source</label>
</settings>
</column>
<column name="salable_quantity"
class="Magento\InventoryCatalogAdminUi\Ui\Component\Listing\Column\SalableQuantity"
component="Magento_InventoryCatalogAdminUi/js/product/grid/cell/salable-quantity"
Expand Down

0 comments on commit f355146

Please sign in to comment.