コード例 #1
0
 /**
  * Update the status of the returned item if there is one to whatever the
  * status was before it was returned.
  *
  * Currently this just chooses the status before the current one, but it
  * could be more robust.
  *
  * @todo Look into making this more robust, by knowing how many steps to
  *       take back in the status history to get to just before the return
  *       started.
  *
  * @param  OrderTransaction\Event\TransactionalEvent $event
  */
 public function revertReturnedItemStatus(OrderTransaction\Event\TransactionalEvent $event)
 {
     $transaction = $event->getTransaction();
     // Skip if the transaction is not a return transaction
     if (Types::ORDER_RETURN !== $transaction->type) {
         return false;
     }
     $itemEdit = $this->get('order.item.edit');
     $itemEdit->setTransaction($event->getDbTransaction());
     foreach ($transaction->records->getByType(OrderReturn::RECORD_TYPE) as $return) {
         // Skip if the return was not for an order (i.e. it was a standalone return)
         if (!$return->item->order) {
             return false;
         }
         $item = $return->item->orderItem;
         $history = $this->get('order.item.status.loader')->getHistory($item);
         // Skip if there was not more than 2 statuses on the item
         if (count($history) < 2) {
             continue;
         }
         // Get the status before the current one
         $previousStatus = array_shift($history);
         $previousStatus = array_shift($history);
         $itemEdit->updateStatus($item, $previousStatus->code);
     }
 }
コード例 #2
0
 /**
  * Create a stock movement to put all items in a transaction that is being
  * voided back into stock in the stock location they were purchased from.
  *
  * @param Transaction\Event\TransactionalEvent $event
  */
 public function returnItemsToStock(Transaction\Event\TransactionalEvent $event)
 {
     $transaction = $event->getTransaction();
     $stockManager = $this->get('stock.manager');
     $stockManager->setTransaction($event->getDbTransaction());
     $stockManager->createWithRawNote(true);
     $stockManager->setReason($this->get('stock.movement.reasons')->get('void_transaction'));
     $event->getDbTransaction()->add("\n\t\t\tSET @STOCK_NOTE = CONCAT('Void transaction #', ?i)\n\t\t", $transaction->id);
     $stockManager->setNote('@STOCK_NOTE');
     $stockManager->setAutomated(true);
     foreach ($transaction->records->getByType(Item\Item::RECORD_TYPE) as $item) {
         $stockManager->increment($item->getUnit(), $item->stockLocation);
     }
 }