Skip to content

Instantly share code, notes, and snippets.

@jahvi
Created September 27, 2015 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jahvi/df55979d4756a7b0fb2f to your computer and use it in GitHub Desktop.
Save jahvi/df55979d4756a7b0fb2f to your computer and use it in GitHub Desktop.
Limit Minimum Order Helper
<?php
class Jvs_MinTotalQty_Helper_Data extends Mage_CatalogInventory_Helper_Minsaleqty
{
const XML_PATH_MIN_TOTAL_QTY = 'cataloginventory/options/min_total_qty';
/**
* Retrieve min_total_qty value from config
*
* @param int $customerGroupId
* @param mixed $store
* @return float|null
*/
public function getConfigValue($customerGroupId, $store = null)
{
$value = Mage::getStoreConfig(self::XML_PATH_MIN_TOTAL_QTY, $store);
$value = $this->_unserializeValue($value);
if ($this->_isEncodedArrayFieldValue($value)) {
$value = $this->_decodeArrayFieldValue($value);
}
$result = null;
foreach ($value as $groupId => $qty) {
if ($groupId == $customerGroupId) {
$result = $qty;
break;
} else if ($groupId == Mage_Customer_Model_Group::CUST_GROUP_ALL) {
$result = $qty;
}
}
return $this->_fixQty($result);
}
/**
* Check if quote meets the minimun quantity
* of total items for a specific customer
*
* @todo Change to more meaningful name
*
* @param Mage_Sales_Model_Quote $quote
* @param Mage_Customer_Model_Customer $customer
* @return int|false
*/
public function minimunOrderQty(Mage_Sales_Model_Quote $quote, Mage_Customer_Model_Customer $customer)
{
$minQtyForCustomer = $this->getConfigValue($customer->getGroupId());
if ($quote->getItemsQty() < $minQtyForCustomer && $quote->getItemsQty() !== 0) {
return $minQtyForCustomer;
}
return false;
}
/**
* Check if current page is shopping cart
*
* @return boolean
*/
public function isCartPage()
{
$frontController = Mage::app()->getFrontController();
return ($frontController->getAction()->getFullActionName() === 'checkout_cart_index');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment