Exemplo n.º 1
0
 /**
  * Given existent Order, returns if go to new state is permitted.
  *
  * @param OrderInterface $order Order
  * @param string         $state New state
  *
  * @return boolean Order can change to desired state
  */
 public function checkOrderCanChangeToState(OrderInterface $order, $state)
 {
     $lastOrderHistoryState = $order->getLastOrderHistory();
     if (!$this->orderStateManager->isOrderStateChangePermitted($lastOrderHistoryState->getState(), $state)) {
         return false;
     }
     return $order->getOrderLines()->forAll(function ($_, OrderLineInterface $orderLine) use($state) {
         return $this->orderLineManager->checkOrderLineCanChangeToState($orderLine, $state);
     });
 }
Exemplo n.º 2
0
 /**
  * Test valid state changes.
  *
  * @dataProvider dataPassCheckChangeToState
  * @group orderstate
  */
 public function testPassCheckChangeToState($fromState, $toState, $result)
 {
     $orderStateManager = new OrderStateManager(['A' => ['B'], 'B' => ['C', 'E'], 'C' => ['B', 'D'], 'D' => ['E'], 'E' => []]);
     $this->assertEquals($result, $orderStateManager->isOrderStateChangePermitted($fromState, $toState));
 }
Exemplo n.º 3
0
 /**
  * Given existent OrderLine, checks if new state is reachable
  *
  * @param OrderLineInterface $orderLine Orderline object
  * @param String             $newState  New state to append
  *
  * @return boolean OrderLine can change to desired state
  */
 public function checkOrderLineCanChangeToState(OrderLineInterface $orderLine, $newState)
 {
     $lastState = $orderLine->getLastOrderLineHistory()->getState();
     return $this->orderStateManager->isOrderStateChangePermitted($lastState, $newState);
 }