如何限制Magento中按国家/地区划分的最大订单数量?

时间:2014-07-05 10:36:28

标签: magento magento-1.8

如何通过国家大陆限制最多订单项?

我知道我们可以在配置中设置限制,就像这个答案says

但是我只是想按国家或大陆来限制它?

例如,我只想允许每个产品的最大 120 运往法国,然后 60 项仅用于在法国境外运送。

我的商店位于法国。

1 个答案:

答案 0 :(得分:1)

tealuo,我找到了这项工作的临时解决方案

这里有详细介绍:

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

goto函数checkQuoteItemQty()在下面添加

$county=null; $country=$quoteItem->getQuote()->getShippingAddress()->getData('country_id'); 之后

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

然后在此功能更改

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

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

和 从

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

 $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
  2. 编辑checkQuoteItemQty功能:

    编辑以下代码

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

    要:

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

    参见代码

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

    并查看条件if ($this->getMaxSaleQty() && $qty > 2) change 2 to 60 并根据您的参考 Magento: limit product max quantity to 1 per order. quantity 2 = 2 orders

    制作Maximum Allow Qty in Shopping cart to 120

    Importnote:this-> getProductId()被赋予产品ID。