How to allow only one product in a cart?

I want to limit number of order by customer on our Sale Day

How can i use both Features at the same time

I have given the answer, I want only a magento developer to check if its correct?

1 Answer 1



<?xml version="1.0"?>


class Fooman_Example_Model_Observer {
public function catalogProductTypePrepare($observer)
$quote = Mage::getSingleton('checkout/session')->getQuote();
    Mage::throwException('You can only buy one product at a time.');

public function AddProductSaveBefore($observer){
$quote = Mage::getSingleton('checkout/session')->getQuote();
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
    $customerData = Mage::getSingleton('customer/session')->getCustomer();
    $customerId = $customerData->getId();

    $fromDate = date('2016-09-10 00:00:00');
    $toDate = date('2016-09-10 23:59:59');
    $order = Mage::getModel('sales/order')->getCollection()
        ->addFieldToFilter('customer_id', $customerId)
        ->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate));

    Mage::throwException('You can only Buy one product at a time. Please Change your Cart Items.');
if (count($order)>=1) {
    Mage::throwException('You already ordered today');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.