Magento check if customer registered in checkout page
If you want to check if the customer is guest, registered or just register to the site when they place the order, below script will help you identify that in success.phtml file.
You can find success / order confirmation phtml file at:
app/design/frontend/[package]/[theme]/template/checkout/success.phtml
Just at the end of this file put below lines of code:
1 2 3 4 5 6 7 8 9 10 11 12 | <?php $order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$quoteId = $order->getQuoteId();
$quote = Mage::getModel('sales/quote')->load($quoteId);
$method = $quote->getCheckoutMethod(true);
$customer_email = $order->getCustomerEmail();
if ($method == 'register'){ ?>
//code to handle if customer just registered to your site
<?php } elseif($method == 'guest') {?>
//code to handle if customer is guest
<?php } else { ?>
//code to handle for logged in customer
<?php } ?> |
In the same file, success.phtml, you can request for order number, customer email, customer id, subtotal, grandtotal, order ID just created etc. like this:
1 2 3 4 5 6 7 8 | $_customerId = Mage::getSingleton('customer/session')->getCustomerId();
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$_totalData =$order->getData();
$_sub = $_totalData['subtotal'];
$_orderEmail = $_totalData['customer_email'];
$_orderNumber = $_totalData['increment_id']; |
Magento disable guest checkout / enable guest checkout
By default the guest checkout in Magento is enabled and visitors can place an order without registering to the website. Some websites require mandatory login for placing orders, and this default feature should be turned off to disallow guest checkout.
To disable guest checkout, navigate to:
System > Configuration > Sales section > Checkout > Checkout Options
Set Allow Guest Checkout to No
This will now disable any guest checkout in your site.
To enable guest checkout, simply set the above dropdown option to Yes.
Buy: Pinterest Auto Pin images right from your website!
Pinterest has yet not released their API which can help developers to integrate to the system and autopin images directly from their website/blog. Yet, I have created an Pinterest API in PHP which will post your image to Pinterest with message, link and price.
Just after entering correct email and password of your pinterest account, and providing Image URL, Message and link URL, you will be shown the list of boards you have, so that you can select any one and pin the image on it right from your website! Sounds interesting!? Here is the image that will help you understand how it works:
Continue reading »
Magento: Register guest user to website if email provided
If your Magento website have feature where guest user can place an order without registering themself in your site, you can add them as a customer in your database. It helps in grouping the orders w.r.t email address in backend sales order. The only condition is that he should provide his email address while placing an order, which is quite obvious.
So here is a snippet of code you can insert where you are asking user to enter his email address. Just check if the user is already not registered in your site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | $e = $email; //provided by guest user
$store = Mage::app()->getStore();
$websiteId = Mage::app()->getWebsite()->getId();
$customerObj = Mage::getModel('customer/customer');
$customerObj->website_id = $websiteId;
$customerObj->setStore($store);
$prefix = "mag";
$pwd = uniqid($prefix);
$session = Mage::getSingleton('checkout/session');
$fname = $session->getFirstname();
$lname = $session->getLastname();
$customerObj->setEmail($e);
$customerObj->setFirstname('Guest');
$customerObj->setLastname('Guest');
$customerObj->setPassword($pwd);
$customerObj->save();
$customerObj->sendNewAccountEmail('confirmed'); //auto confirmed |
UPDATE: It depends where you want to keep this functionality on your site. I have put it in saveShippingMethodAction() function of Mage/Checkout/controllers/OnepageController.php file after extending. Don’t forget, this code should only be run if customer is guest.
Magento: Getting back shopping cart items after order fails
It’s very awkward if users place an order in your website and by chance the order fails, from end user side or some technical glitch, shopping cart becomes empty. User have to again add items in cart and go through the process which becomes tedious and may be changing their mind to shop.
So here’s a code that does the trick and preserves shopping cart content even if order gets failed.
Open your file where you’re handling your order failure action in frontend. (generally Mage/Checkout/controllers/OnepageController.php)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | public function failureAction()
{
$lastQuoteId = $this->getOnepage()->getCheckout()->getLastQuoteId();
$lastOrderId = $this->getOnepage()->getCheckout()->getLastOrderId();
if ($lastQuoteId && $lastOrderId) {
$orderModel = Mage::getModel('sales/order')->load($lastOrderId);
if($orderModel->canCancel()) {
$quote = Mage::getModel('sales/quote')->load($lastQuoteId);
$quote->setIsActive(true)->save();
$orderModel->cancel();
$orderModel->setStatus('canceled');
$orderModel->save();
Mage::getSingleton('core/session')->setFailureMsg('order_failed');
Mage::getSingleton('checkout/session')->setFirstTimeChk('0');
$this->_redirect('kcheckout/index/payment', array("_forced_secure" => true));
return;
}
}
if (!$lastQuoteId || !$lastOrderId) {
$this->_redirect('checkout/cart', array("_forced_secure" => true));
return;
}
$this->loadLayout();
$this->renderLayout();
} |
Be noted here that we don’t have here onepage checkout so we’re redirecting user to payment page after restoring the cart. You can redirect user to any page as per your need after the cart is restored and previous order is cancelled.
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)