Browsing articles tagged with "checkout Archives - Kalpesh Mehta"
Aug 21, 2014
kalpesh

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:

<?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:

$_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'];
May 26, 2013
kalpesh

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.

Nov 2, 2012
kalpesh

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:

Pinterest Auto Post image API


Continue reading »

Dec 31, 2011
kalpesh

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.

$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.

Dec 31, 2011
kalpesh

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)

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.

Pages:12»

Welcome to my Blog

Kalpesh MehtaHelping Magento developers in their day-to-day development problems since 2011. Most of the problems and solutions here are my own experiences while working on different projects. Enjoy the blog and don't forget to throw comments and likes/+1's/tweets on posts you like. Thanks for visiting!

Certifications

Honor

Recognition

Magento top 50 contributors

Magento top 50 contributors

Contributions