0

How can I limit maximum items of order by country or by continent?

I know we can set the limit in the config just as this answer says.

But what about I just want to limit it by country or by continent?

For instance, I just want to allow max items of 120 per product that are shipped to France and then 60 items only for the shipping outside France.

My store is set in France.

Community
  • 1
  • 1
Run
  • 54,938
  • 169
  • 450
  • 748

1 Answers1

1

tealuo, i have find a temporary solution for this works

Here step on details:

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

And goto function checkQuoteItemQty() add below

$county=null; $country=$quoteItem->getQuote()->getShippingAddress()->getData('country_id'); 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,$country);

And from

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

to

 $result = $stockItem->checkQuoteItemQty($optionQty, $qtyForCheck, $optionValue,$country);
  1. 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) && $county_id=='IN'){
    if ($this->getMaxSaleQty() && $qty > 2) {
    $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;
     }


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

}

See code

if(!is_null($county_id) && $county_id=='IN'){
means IN=India country code of India,Just change country IN to FR France country code

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

make Maximum Allow Qty in Shopping cart to 120

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

Community
  • 1
  • 1
Amit Bera
  • 7,581
  • 7
  • 31
  • 57
  • thanks Amit. But where in the code can I set 120 for France and 60 for any country outside France? Thanks. – Run Jul 05 '14 at 17:01