0

There's a way to make orderable "Quantity per source" and "Salable quantity" coloumns on backend product list?

enter image description here

0

You've got some coding to do if you want to achieve this.

Salable Quantity

This setting is configured in vendor/magento/module-inventory-sales-admin-ui/view/adminhtml/ui_component/product_listing.xml:

<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="salable_quantity"
                class="Magento\InventorySalesAdminUi\Ui\Component\Listing\Column\SalableQuantity"
                component="Magento_InventorySalesAdminUi/js/product/grid/cell/salable-quantity"
                sortOrder="77">
            <settings>
                <filter>false</filter>
                <sortable>false</sortable>
                <label translate="true">Salable Quantity</label>
            </settings>
        </column>
    </columns>
</listing>

To change this, you'll need to create or extend a custom module to override the sortable setting. You may also need to create your own class to replace \Magento\InventorySalesAdminUi\Ui\Component\Listing\Column\SalableQuantity, as this user suggested here.

Quantity per Source

This one's a bit trickier since the column appears to be configured in classes, not xml.

First, this value is set in the private function getQuantityPerSourceMeta of Magento\InventoryCatalogAdminUi\Ui\DataProvider\Product\Listing\Modifier\QuantityPerSource:

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',
                    ]
                ],
            ],
        ];
    }

This function is called from the same class's modifyMeta function, the simplest solution would be to create a plugin for this class with an afterModifyMeta function in which you can modify the sortable value as you desire.

The other location you might need to handle is the (also private) function getQuantityPerSourceMeta in \Magento\InventoryGroupedProductAdminUi\Plugin\Ui\DataProvider\Product\Form\AddColumnQuantityPerSource`:

private function getQuantityPerSourceMeta(): array
    {
        $jsComponent = 'Magento_InventoryGroupedProductAdminUi/js/form/element/grid-column-quantity-per-source';

        return [
            'arguments' => [
                'data' => [
                    'config' => [
                        'filter' => false,
                        'sortable' => false,
                        'label' => __('Quantity per Source'),
                        'dataType' => Text::NAME,
                        'componentType' => Column::NAME,
                        'component' => $jsComponent,
                    ]
                ],
            ],
        ];
    }

This is called in this plugin class's afterGetMeta function. You may need either to create your own plugin with your own afterGetMeta function and ensure it runs after this core plugin, or else override this plugin so you can modify the meta directly.

3
  • Thanks for the post, this code works correctly on default stock. However i use a custom stock and i would to make ordinable my custom stock. Is it possible? – mariobros Apr 9 at 7:52
  • Maybe! Can you provide any more information? Are you using a third-party extension for your custom stock? Can you provide any more information on your use case? The more detail the better. – kookaburra Apr 9 at 13:29
  • I don't use any extensions for my custom stock – mariobros Apr 9 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.