2

How to check whether the customer is already registered user or new user.

If they are a new user the product add to cart logic should be different, If they are a registered user the product add to cart logic should be different.

How to differentiate, and where to edit the login in code?

  • whats your logic for new user , first order ?? – Murtuza Zabuawala Nov 17 '16 at 6:45
  • actually my product is drinking water can. if they are a new user, they have to buy 3 empty water can, 3 filled water can at the same time in same brand. i completed the process of adding 3empty and filled can. Now , again the same user buy the same product it should add only filled water not empty water can. If they are a registered user, having the possibilities to add only 3 filled water can in which brand they brought before.. for both the user, if they choose another different brand they have to order along with empty can and filled can. – Saranya Nov 17 '16 at 6:58
1

For orders where the user was a guest the field customer_is_guest on the table sales_flat_order will be 1. Whereas for registered user this will have a value of 0.

For the guest orders it's easy.

$order->Mage::getModel('sales/order')->load($id);
$isGuest = $order->getCustomerIsGuest();
//or
//$isGuest = $order->getCustomerId() == 0;

But to check if the customer registered or it was already logged in is not that easy. You cannot get the information from the order object. You need to check the quote object associated to the order. But that may not exist. You can try something like this:

$order->Mage::getModel('sales/order')->load($id);
if ($order->getCustomerIsGuest()) { 
    //customer is guest
}
else {
    $quote = Mage::getModel('sales/quote')->load($order->getQuoteId());
    if ($quote->getId()) {
         $method = $quote->getCheckoutMethod();
         if ($method == 'register'){
              //customer registered when placing the order
         }
         else {
              //customer was already logged in when placing the order
         }
    }
    else {
        // there is no way of knowing if the customer registered or was already logged in but for sure an account exists.
    }
}
| improve this answer | |
1

you can check current users order for new user . if current user has order thats mean he is not new user, otherwise he/she is new user

$customer = Mage::getSingleton('customer/session')->getCustomer();
$email = $customer->getEmail();  
$orderCollection = Mage::getModel(‘sales/order’)->getCollection();
$orderCollection->addFieldToFilter(‘customer_email’, $email);
$newUser =false; 
if(empty(orderCollection->getData()) ){
   $newUser =true; 
}
| improve this answer | |
  • where to add or edit these code.? Kindly tell me – Saranya Nov 17 '16 at 7:00
  • create an observer and write this code in observer – Murtuza Zabuawala Nov 17 '16 at 7:24
  • I,m totally new to this concept. how to create obersver and where the observer to create? Kindly explain me clearly – Saranya Nov 17 '16 at 7:27
  • actually my product is drinking water can. if they are a new user, they have to buy 3 empty water can, 3 filled water can at the same time in same brand. i completed the process of adding 3empty and filled can. Now , again the same user buy the same product it should add only filled water not empty water can. If they are a registered user, having the possibilities to add only 3 filled water can in which brand they brought before.. for both the user, if they choose another different brand they have to order along with empty can and filled can. – Saranya Nov 17 '16 at 7:27
  • you need to observe checkout_cart_save_before this event – Murtuza Zabuawala Nov 17 '16 at 7:30

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.