public function processStock($productID)
 {
     $this->_product = $this->get('product.loader')->getByID($productID);
     $locationCollection = $this->get('stock.locations');
     $this->_units = $this->_product->getAllUnits();
     $form = $this->_getStockForm($locationCollection->all());
     $stockManager = $this->get('stock.manager');
     if ($form->isValid() && ($data = $form->getFilteredData())) {
         $note = $data['note'];
         $reason = $this->get('stock.movement.reasons')->get($data['reason']);
         if ($note) {
             $stockManager->setNote($note);
         }
         $stockManager->setReason($reason);
         $stockManager->setAutomated(false);
         foreach ($data['units'] as $unitID => $locationArray) {
             foreach ($locationArray as $location => $stock) {
                 // remove all spaces and tabs and cast stock to int
                 $stock = (int) preg_replace('/\\s+/', '', $stock);
                 if ($stock > 0) {
                     $stockManager->increment($this->_units[$unitID], $locationCollection->get($location), $stock);
                 } else {
                     if ($stock < 0) {
                         $stockManager->decrement($this->_units[$unitID], $locationCollection->get($location), $stock * -1);
                     }
                 }
             }
         }
         if ($stockManager->commit()) {
             $this->addFlash('success', 'Successfully adjusted stock levels');
         }
     }
     return $this->redirectToRoute('ms.commerce.product.edit.stock', array('productID' => $this->_product->id));
 }
 public function getAllUnits()
 {
     if (!in_array('units', $this->_loaded)) {
         $this->_loadUnits();
     }
     return parent::getAllUnits();
 }