I want to limit the product max qty per customer to only 1.
Example: If you buy the product my_product_per_customer
as a registered customer you can not buy again with the same account.
Does anyone know a way to achieve this?
My config.xml is
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Inchoo_MaxOrderAmount>
<version>0.0.2</version>
</Inchoo_MaxOrderAmount>
</modules>
<frontend>
<events>
<sales_quote_save_before>
<observers>
<inchoo_maxorderamount_enforceSingleOrderLimit>
<class>inchoo_maxorderamount/observer</class>
<method>enforceSingleOrderLimit</method>
</inchoo_maxorderamount_enforceSingleOrderLimit>
</observers>
</sales_quote_save_before>
</events>
</frontend>
</config>
My observer.php is
<?php
class Inchoo_MaxOrderAmount_Model_Observer
{
private $_helper;
public function __construct()
{
$this->_helper = Mage::helper('inchoo_maxorderamount');
}
/**
* No single order can be placed over the amount of X
*/
public function enforceSingleOrderLimit($observer)
{
if (!$this->_helper->isModuleEnabled()) {
return;
}
echo 1; die;
//todo - look up customer info and check if they already purchase this item
$quote = $observer->getEvent()->getQuote();
if ($quote->getCart()->getItemsCount() == 1) {
Mage::getSingleton('checkout/session')->addError('limit only one product per order');
Mage::app()->getFrontController()->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
Mage::app()->getResponse()->sendResponse();
exit;
}
}
}