In magento 2 admin product-catalog page how to add a additional option in back orders select field under advance Inventory

magento.stackexchange https://magento.stackexchange.com/questions/273782

  •  28-02-2021
  •  | 
  •  

Question

In magento 2 admin product-catalog page how to add a additional option in back orders select field under advance Inventory

e

Was it helpful?

Solution

Pluginize toOptionArray method of following class, add your custom option.

vendor/magento/module-catalog-inventory/Model/Source/Backorders.php

Try the following way:

app/code/SR/MagentoCommunity/etc/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\CatalogInventory\Model\Source\Backorders">
        <plugin name="sr_add_option_to_backorder"
                type="SR\MagentoCommunity\Plugin\CatalogInventory\Model\Source\Backorders" sortOrder="1"/>
    </type>
</config>

app/code/SR/MagentoCommunity/Plugin/CatalogInventory/Model/Source/Backorders.php

<?php
namespace SR\MagentoCommunity\Plugin\CatalogInventory\Model\Source;


class Backorders
{
    public function afterToOptionArray(
        \Magento\CatalogInventory\Model\Source\Backorders $subject,
        $result
    ) {

        $result = array_merge($result, [
            ['value' => '10', 'label' => __('Custom')]
        ]);

        return $result;
    }
}

Output:

enter image description here

OTHER TIPS

Download this module with Plugin, edit it like you want.

http://www.filedropper.com/webmeridianbackorderextra

after install please run :

bin/magento setup:upgrade && bin/magento setup:di:compile && bin/magento c:c
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top