0

How can I add new stock labels to magento 2 so they appear in the product stock status select box ?

enter image description here

Thanks.

3

You should create a custom module to solve your problem. And then you can create a plugin to add more stock option by do following steps:

  1. app/code/YourVendor/YourModule/etc/di.xml

<type name="Magento\CatalogInventory\Model\Source\Stock"> <plugin name="training_source_stock" type="YourVendor\YourModule\Plugin\CatalogInventory\Model\Source\Stock"/> </type>

  1. app/code/YourVendor/YourModule/Plugin/CatalogInventory/Model/Source/Stock.php
class Stock
{
    const NEW_STOCK = 2;

    public function afterGetAllOptions(\Magento\CatalogInventory\Model\Source\Stock $subject, $result)
    {
        $newStock = [
            [
                'value' => self::NEW_STOCK,
                'label' => __('New Stock')
            ]
        ];
        return array_merge($result, $newStock);
    }
}
  1. Stock status will be show like this:

enter image description here

If this solves your issue, please give me a vote

Thanks

  • Thanks Lee, I will give it a go, that looks spot on :) – garyconstable Dec 20 '18 at 12:55
  • The code is good except that it does not save - on page reload the new stock option is either in or out of stock. - is stock status supposed to be boolean, in or out of stock ? – garyconstable Dec 31 '18 at 16:38

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.