6

Does anyone know how we can setup to allow backorders to happen only for orders placed in the backend admin?

So customers on the frontend store would not be able to place an order for an out of stock item.

Our sales reps need to be able to place orders for products that are out of stock, but not our frontend customers.

Is there an extension that would do this or any help would be greatly appreciated.

4
  • Please let us know, What you have tried so far ?
    – Pawan
    Commented May 18, 2019 at 2:45
  • Admin don’t care stock. Did try ever?
    – Sohel Rana
    Commented May 18, 2019 at 4:50
  • @pawan When I try to add a product that is out of stock to a new order in the admin. I received 2 messages: 1. We don't have as many "Product Name" as you requested. 2. This product is out of stock. Store configuration is set to: No Backorders. My understanding of this setting is that it applies to frontend customers. But it seems it is applying to backend as well. If I set the Backorder setting to: Allow below Zero. I get the message: This product is out of stock. when trying to add the product to a new order in the backend.
    – Lucein
    Commented May 21, 2019 at 22:09
  • @pawan Although it will allow me to add the product to an order with out of stock. The stock number is not showing as negative. Which is a problem because we dont know what has backorders then.
    – Lucein
    Commented May 21, 2019 at 22:36

1 Answer 1

3

My solution: change function get Config backorders

1- Create di.xml file in your module Vendor/Module/etc/di.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">

<type name="Magento\CatalogInventory\Model\Configuration">
    <plugin name="custom_get_backorders" type="Vendor\Module\Plugin\CustomBackorders" sortOrder="1" disabled="false"/>
</type>

2- Create CustomBackorders.php file

Vendor/Module/Plugin/CustomBackorders.php

<?php

namespace Vendor\Module\Plugin;

use Magento\Backend\Model\Auth\Session as BackendSession;

class CustomBackorders
{

    /**
     * @var BackendSession
     */
    protected $_backendSession;

    public function __construct(
        BackendSession $backendSession
    )
    {
        $this->_backendSession = $backendSession;
    }

    public function afterGetBackorders(\Magento\CatalogInventory\Model\Configuration $subject, $result)
    {
        if ($this->_backendSession->isLoggedIn()) {
            $result = (int)1;
        }

        return $result;
    }
}
4
  • Perfect Solution, Thanks Commented Jan 14, 2022 at 7:12
  • This backendSession is initated on frontend too ? There can be some PHP session issues there ? Commented Jul 20, 2022 at 12:35
  • with class Magento\Backend\Model\Auth\Session as BackendSession; it only get end check user in backend, not on frontend
    – alan.D
    Commented Jul 22, 2022 at 3:27
  • 1
    Casting 1 to int is redundant. Would you mind changing 1 to a constant (en.wikipedia.org/wiki/Magic_number_(programming))? Moreover, you can return the result directly from if clause body. The di.xml config can be placed in etc/adminhtml scope which will remove this plugin from other scopes. Also protected field could be a private because plugins must not be extended (and you should avoid inheritance for cleaner code)
    – MTP
    Commented Oct 5, 2022 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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