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
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 Apr 28 '17 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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