Skip to content

Instantly share code, notes, and snippets.

@jahvi
Created September 27, 2015 16:23
Show Gist options
  • Save jahvi/ae7264399da9ddb36069 to your computer and use it in GitHub Desktop.
Save jahvi/ae7264399da9ddb36069 to your computer and use it in GitHub Desktop.
Limit Minimum Order observer
<?php
class Jvs_MinTotalQty_Model_Observer
{
public function checkTotalQtyBeforeCheckout(Varien_Event_Observer $observer)
{
$quote = $observer->getDataObject();
$customer = Mage::helper('customer')->getCustomer();
// If the minimun total quantity is not met
// redirect to cart page with error message
if ($minQty = Mage::helper('jvs_mintotalqty')->minimunOrderQty($quote, $customer)) {
Mage::getSingleton('checkout/session')->addUniqueMessages(
Mage::getSingleton('core/message')
->error(
Mage::helper('cataloginventory')
->__(
'The minimum quantity allowed for purchase is %s.',
$minQty
)
)
);
// Check if we are not already on the cart page
if (!Mage::helper('jvs_mintotalqty')->isCartPage()) {
Mage::app()->getFrontController()->getResponse()
->setRedirect(Mage::getUrl('checkout/cart'));
Mage::app()->getRequest()->setDispatched(true);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment