如何通过国家或大陆限制最多订单项?
我知道我们可以在配置中设置限制,就像这个答案says。
但是我只是想按国家或大陆来限制它?
例如,我只想允许每个产品的最大项 120 运往法国,然后 60 项仅用于在法国境外运送。
我的商店位于法国。
答案 0 :(得分:1)
这里有详细介绍:
1.copy app>code>core>Mage>CatalogInventory>Model>Observer.php
至app>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);
编辑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。