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?
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?
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;
}
}