2
votes

I have an e-commerce site developed in magento, an I am using paypal as payment method. When user adds 2 items for a product "Dress" in cart, and goes to checkout page and click place order button then I am redirecting user to paypal site for payment. But there are some users who abandons payment and leave the paypal page.

When they click on place order, magento generates an order in backend and keep its status as Pendin, once paypal payment done and user redirected back to our site, that order's status updated to Processing because payment is done. But if user leaves from pyapal payment page without making payment then my product stocks are decreased and other users can't place the order until I cancel the junk orders.

Is there any way with which I can automate this process, if user do not pay on paypal then stocks/inventory should back to normal?

Please help, thanks!

2

2 Answers

3
votes

Here is the cron that we are using since past few months. This code checks for pending orders for more than 7 minutes age to 30 minutes and cancels them. For me this restores the inventory.

       public function cancelPending()
        {


        $orderCollection = Mage::getResourceModel('sales/order_collection');
        $orderCollection
            ->addFieldToFilter('status', 'pending')
            ->addFieldToFilter('created_at', array('lt' =>  new Zend_Db_Expr("DATE_ADD('".now()."', INTERVAL -'0:07' HOUR_MINUTE)"),
                                            'gt' => new Zend_Db_Expr("DATE_ADD('".now()."', INTERAL -'0:30' HOUR_MINUTE)")));

        foreach($orderCollection->getItems() as $order)
        {
            $orderModel = Mage::getModel('sales/order');
            $orderModel->load($order['entity_id']);

            if(!$orderModel->canCancel())
                continue;

            $orderModel->cancel();
            $orderModel->setStatus('canceled');
            $orderModel->save();

}

My default status for an order pending payment is "pending". you may have to change that.

1
votes

I guess you'll need to set up a magento cron job, which takes the orders which are in pending state for more than 20 minutes, and reverting those, therefore enabling your stock again.

I tried to google it, but couldn't find anything. I'm pretty sure something like this exists

'cron' is a way to schedule things periodically (like, every 10 minutes) on UNIX systems, Magento inherited this terminology, here you can find some details: http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/how_to_setup_a_cron_job

So, algorithm plan:

  • for every 10 minutes
    • check for orders which are in Pending state and are older than (current_time -20 minutes)
    • revert these orders automatically

(perhaps you could send a mail to the people who have orders older than 10 minutes that heeey, don't you wanna pay?)