0

I want only admin side to allow back orders when quantity is below zero. I also appplied this solution but this didn't work.

Allow Backorder for Admins only Magento 2

Any Idea?

2

1 Answer 1

0

app/code/Pyaray/RestrictCustomerOrder/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\Stock\Item">
        <plugin name="custom_get_backorders" type="Pyaray\RestrictCustomerBackOrders\Plugin\CustomBackorders" sortOrder="1" disabled="false"/>
    </type>
</config>

\Pyaray\RestrictCustomerOrder\Plugin\CustomBackorders.php

<?php

namespace Pyaray\RestrictCustomerOrder\Plugin;

use Magento\Backend\Model\Auth\Session as BackendSession;
use Magento\CatalogInventory\Model\Stock\Item;

class CustomBackorders
{
    /**
     * @var BackendSession
     */
    protected BackendSession $backendSession;

    /**
     * @param BackendSession $backendSession
     */
    public function __construct(
        BackendSession $backendSession
    )
    {
        $this->backendSession = $backendSession;
    }

    /**
     * @param Item $subject
     * @param $result
     * @return int
     */
    public function afterGetBackorders(Item $subject, $result): int
    {
        if ($this->backendSession->isLoggedIn()) {
            $result = 1;
        }
        else
        {
            $result = 3;
        }
        return $result;
    }
}
1
  • This did not work for us as regardless of backorder configuration once a products is set top "Out of Stock" M2.4 will not allow the product to be backordered.
    – Flipmedia
    Commented Aug 21, 2023 at 20:01

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.