public function subtractQuoteInventory(Varien_Event_Observer $observer)
 {
     if (!Mage::helper('udmulti')->isActive()) {
         return parent::subtractQuoteInventory($observer);
     }
     $quote = $observer->getEvent()->getQuote();
     // Maybe we've already processed this quote in some event during order placement
     // e.g. call in event 'sales_model_service_quote_submit_before' and later in 'checkout_submit_all_after'
     if ($quote->getInventoryProcessed()) {
         return;
     }
     $update = array();
     $allPids = array();
     foreach ($quote->getAllItems() as $item) {
         if (!$item->getChildren()) {
             $pId = $item->getProductId();
             $vId = $item->getUdropshipVendor();
             $v = Mage::helper('udropship')->getVendor($vId);
             if (!$v->getId() && $v->getStockcheckMethod()) {
                 continue;
             }
             $allPids[$pId] = $pId;
             if (isset($update[$vId][$pId])) {
                 $update[$vId][$pId]['stock_qty_add'] -= $item->getTotalQty();
             } else {
                 $update[$vId][$pId] = array('stock_qty_add' => -$item->getTotalQty());
             }
         }
     }
     if (empty($allPids)) {
         return $this;
     }
     $siData = Mage::getResourceSingleton('udropship/helper')->loadDbColumnsForUpdate(Mage::getModel('cataloginventory/stock_item'), array('product_id' => $allPids), array('backorders', 'use_config_backorders'));
     $hlpm = Mage::helper('udmulti');
     $rHlp = Mage::getResourceSingleton('udropship/helper');
     $conn = $rHlp->getReadConnection();
     foreach ($update as $vId => $_update) {
         $mvData = $rHlp->loadDbColumnsForUpdate(Mage::getModel('udropship/vendor_product'), array('product_id' => array_keys($_update)), array('backorders', 'stock_qty', 'product_id', 'avail_state', 'avail_date', 'status'), $conn->quoteInto('{{table}}.vendor_id=?', $vId));
         foreach ($_update as $pId => $_prod) {
             $qtyCheck = abs($_prod['stock_qty_add']);
             if (!array_key_exists($pId, $mvData)) {
                 if (Mage::app()->getStore()->isAdmin()) {
                     continue;
                 }
                 Mage::throwException(Mage::helper('cataloginventory')->__('Stock configuration problem'));
             }
             $_mv = $mvData[$pId];
             if (!$hlpm->isQtySalableByVendorData($qtyCheck, (array) @$siData[$pId], $vId, $_mv)) {
                 if (Mage::app()->getStore()->isAdmin()) {
                     continue;
                 }
                 Mage::throwException(Mage::helper('cataloginventory')->__('Not all products are available in the requested quantity'));
             }
         }
     }
     foreach ($update as $vId => $_update) {
         Mage::helper('udmulti')->setReindexFlag(false);
         Mage::helper('udmulti')->saveThisVendorProductsPidKeys($_update, $vId);
         Mage::helper('udmulti')->setReindexFlag(true);
     }
     $quote->setInventoryProcessed(true);
     return $this;
 }