0

I have used the below code. Please suggest me if I am wrong.

<?php

class Fooman_Example_Model_Observer
{

    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();

            $time = time();
            $toDate = date('Y-m-d H:i:s', $time);
            $lastTime = $time - 100000000; 
            $fromDate = date('Y-m-d H:i:s', $lastTime);
            $order = Mage::getModel('sales/order')->getCollection()
            ->addFieldToFilter('customer_id', $customerId)
            ->addAttributeToFilter('created_at', array('from' => $fromDate, 'to' => $toDate))
            ->addFieldToFilter('sku', array('in' => Mage::getSingleton('catalog/product')->getSku()))
            ->load();



        }

       if ((count($order->getItems()) - 1) >= 1) {
    Mage::throwException('You already ordered today');
}
    }
}
2

1 Answer 1

0

This will help you to allow max quantity. Do you want to ban that user from purchasing it again? or in that session?

enter image description here

1
  • I want to ban users from purchasing it again Commented Apr 28, 2017 at 0:24

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.