A new approach to web development.

If you have a high rate of orders, or customers that take their time finalizing checkout, then you might have noticed an odd problem with your Sales > Orders.  If a customer adds product XYZ into their cart and proceeds to Google Checkout, then a product is deactivated from the magento system, we have no way of stopping the order flow for that customer - At least not a reliable one.  What happens is an order created in the magento system with no products and $0 due.  The order looks totally find for the customer however you'll never be able to cancel the order based on the canCancel() method in Mage_Sales_Model_Order.  

The solution is to watch the <checkout_submit_all_after> event and immediately cancel orders as they are created.  You could override the Mage_GoogleCheckout_Model_Api_Xml_Callback::_responseNewOrderNotification() method, however I tried to be as non-obtrusive as I can with magento core code.  















And in your Model/Observer.php class:

class FoxConnect_GoogleCheckout_Model_Observer


    public function observeForEmptyOrders($observer) {

        $order = $observer->getEvent()->getOrder();

        if ($order->getPayment()->getMethod() != 'googlecheckout')  return;

        if (count($order->getAllItems()) == 0) {

            $order->getPayment()->getMethodInstance()->cancel( $order->getPayment());

            $order->setStatus( Mage_Sales_Model_Order::STATE_CANCELED );