Is there a way to set different maximum quantity limits for B2B and B2C customers in Magento? For example, can B2C customers have a maximum limit of 20 items, while B2B customers have a limit of 100 items? If not, are there any solutions or workarounds to achieve this?
Magento allows you to configure a minimal qty per item and per customer group but surprisingly it is not available for maximum quantity.
I’ll assume that your B2B and B2C customers are in 2 different customer group.
You may take a look at the file vendor/magento/module-catalog-inventory/Model/Stock/Item.php
and at the method getMaxSaleQty
public function getMaxSaleQty()
{
if ($this->getUseConfigMaxSaleQty()) {
$customerGroupId = $this->getCustomerGroupId();
$maxSaleQty = $this->stockConfiguration->getMaxSaleQty($this->getStoreId(), $customerGroupId);
} else {
$maxSaleQty = (float) $this->getData(static::MAX_SALE_QTY);
}
return $maxSaleQty;
}
Based on the customer group id, you can assign different values for $maxSaleQty.
Do not edit the vendor file directly, use a plugin (https://developer.adobe.com/commerce/php/development/components/plugins/ ), you can even add another product attribute or magento configuration instead of hardcoding values.
Loiku is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.