2

I want to apply some rule for customer group for example if general user can buy only single quantity of any product and wholesaler can buy limitless product quantity and retail can buy specific quantity and so on for different customer groups. For maximum quantity means particular group cannot buy more than its allowed limit.

1

Step1: copy app>code>core>Mage>CatalogInventory>Model>Observer.php to app>code>local>Mage>CatalogInventory>Model>Observer.php

And goto function checkQuoteItemQty() add below

 $groupId=null; 


$groupId = =$quoteItem->getQuote()->getQuote()->getCustomerGroupId();
    if (!$groupId) {
        $groupId =  Mage::getSingleton('customer/session')
        ->getCustomerGroupId();;
    }

after

if (!$quoteItem || !$quoteItem->getProductId() || !$quoteItem->getQuote()
            || $quoteItem->getQuote()->getIsSuperMode()) {
            return $this;
        }

Then in this function change

$result = $stockItem->checkQuoteItemQty($rowQty, $qtyForCheck, $qty);

to

 $result = $stockItem->checkQuoteItemQty($rowQty, $qtyForCheck, $qty,$groupId);

And from

 $result = $stockItem->checkQuoteItemQty($optionQty, $qtyForCheck, $optionValue);

to

 $result = $stockItem->checkQuoteItemQty($optionQty, $qtyForCheck, $optionValue,$groupId);

Step2:

`copy app>code>core>Mage>CatalogInventory>Model>Stock>Item.php` to 


   app>code>local>Mage>CatalogInventory>Model>Stock>Item.php

edit checkQuoteItemQty function:

edit below code

      if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) {
$result->setHasError(true)
    ->setMessage(
        Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s. %s', $this->getMaxSaleQty() * 1,$county_id)
    )
    ->setErrorCode('qty_max')
    ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))
    ->setQuoteMessageIndex('qty');
return $result;
 }

to

if(!is_null($county_id) && $groupid==youmatchgroupid'){
    if ($this->getMaxSaleQty() && $qty > 2) {
    $result->setHasError(true)
        ->setMessage(
            Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s. %s', $this->getMaxSaleQty() * 1,$groupid)
        )
        ->setErrorCode('qty_max')
        ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))
        ->setQuoteMessageIndex('qty');
    return $result;
     }


}
else{
      if ($this->getMaxSaleQty() && $qty > $this->getMaxSaleQty()) {
    $result->setHasError(true)
        ->setMessage(
            Mage::helper('cataloginventory')->__('The maximum quantity allowed for purchase is %s. %s', $this->getMaxSaleQty() * 1,$county_id)
        )
        ->setErrorCode('qty_max')
        ->setQuoteMessage(Mage::helper('cataloginventory')->__('Some of the products cannot be ordered in requested quantity.'))
        ->setQuoteMessageIndex('qty');
    return $result;
     }

}

NOte:

See code

if(!is_null($groupId) && $groupId==$yourgoupid){

means yougrouopid ,Just change customer group id

And see condition if ($this->getMaxSaleQty() && $qty > 2) change 2 to 60 And According to your reference Magento: limit product max quantity to 1 per order. quantity 2 = 2 orders

Importnote: this->getProductId() is given product id.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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