1

Current product increment for each product is set to 24, I want to allow admin to create a order from backend without any increment,any qty should be added, but right now it gives error "The fewest you may purchase is 24"

enter image description here

I have tried to change function get Config qty increment,to disable the qty increment for admin but not worked, sharing code:

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_QtyIncrement" type="Vendor\Module\Plugin\QtyIncrement" sortOrder="1" disabled="false"/>
</type>

Vendor/Module/Plugin/QtyIncrement.php

<?php

namespace Vendor\Module\Plugin;

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

class QtyIncrement
{

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

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

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

        return $result;
    }
}

any help would be greatly appreciated. Thanks.

1 Answer 1

1

Create a custom plugin and override this file

IsCorrectQtyCondition.php

Folder path:

/vendor/magento/module-inventory-sales/Model/IsProductSalableForRequestedQtyCondition

if($adminSession->isLoggedIn()) { //added to remove the validation for order created from admin

}else{

    if ($this->isMinSaleQuantityCheckFailed($stockItemConfiguration, $requestedQty)) {
        return $this->createErrorResult(
            'is_correct_qty-min_sale_qty',
            __(
                'The fewest you may purchase is %1',
                $stockItemConfiguration->getMinSaleQty()
            )
        );
    } 

    if ($this->isMaxSaleQuantityCheckFailed($stockItemConfiguration, $requestedQty)) {
        return $this->createErrorResult(
            'is_correct_qty-max_sale_qty',
            __('The requested qty exceeds the maximum qty allowed in shopping cart')
        );
    }

    
    if ($this->isQuantityIncrementCheckFailed($stockItemConfiguration, $requestedQty)) {
        return $this->createErrorResult(
            'is_correct_qty-qty_increment',
            __(
                'You acan buy this product only in quantities of %1 at a time.',
                $stockItemConfiguration->getQtyIncrements()
            )
        );
    }
}

I have used admin session check,to remove the validation for order created from backend.

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.