Exemplo n.º 1
0
 /**
  * Creates an instance of an entity.
  *
  * This method must return always an empty instance for related entity
  *
  * @return Order New Order instance
  */
 public function create()
 {
     /**
      * @var Order $order
      */
     $classNamespace = $this->getEntityNamespace();
     $order = new $classNamespace();
     $order->setQuantity(0)->setWidth(0)->setHeight(0)->setWidth(0)->setWeight(0)->setCreatedAt($this->now())->setPurchasableAmount($this->createZeroAmountMoney())->setAmount($this->createZeroAmountMoney())->setCouponAmount($this->createZeroAmountMoney())->setShippingAmount($this->createZeroAmountMoney());
     $paymentStateLineStack = $this->paymentMachineManager->initialize($order, StateLineStack::create(new ArrayCollection(), null), 'Order not paid');
     $order->setPaymentStateLineStack($paymentStateLineStack);
     $shippingStateLineStack = $this->shippingMachineManager->initialize($order, StateLineStack::create(new ArrayCollection(), null), 'Preparing Order');
     $order->setShippingStateLineStack($shippingStateLineStack);
     return $order;
 }
Exemplo n.º 2
0
 /**
  * Test make transition with an initialized object
  */
 public function testReachStateInitialized()
 {
     $machineManager = $this->getMachineManager(5);
     $order = new Order();
     $stateLineStack = StateLineStack::create(new ArrayCollection(), null);
     $order->setStateLineStack($stateLineStack);
     $stateLineStack = $machineManager->initialize($order, $stateLineStack, '');
     $order->setStateLineStack($stateLineStack);
     $stateLineStack = $machineManager->reachState($order, $stateLineStack, 'paid', '');
     $this->assertEquals('paid', $stateLineStack->getLastStateLine()->getName());
     $this->assertEquals('paid', $stateLineStack->getStateLines()->last()->getName());
 }
Exemplo n.º 3
0
 /**
  * Sets StateLineStack.
  *
  * @param StateLineStack $stateLineStack StateLineStack
  *
  * @return $this Self object
  */
 public function setStateLineStack(StateLineStack $stateLineStack)
 {
     $this->stateLines = $stateLineStack->getStateLines();
     $this->lastStateLine = $stateLineStack->getLastStateLine();
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Applies a transition action given a object and the kind of transition is
  * needed.
  *
  * @param stdClass       $object           Object
  * @param StateLineStack $stateLineStack   StateLine Stack
  * @param string         $transitionName   Transition name
  * @param string         $description      Description
  * @param string         $transitionAction Transition Action
  *
  * @return StateLineStack StateLine stack given
  *
  * @throws StateNotReachableException    State is not reachable
  * @throws ObjectNotInitializedException Object needs to be initialized in machine
  */
 private function applyTransitionAction($object, StateLineStack $stateLineStack, $transitionName, $description, $transitionAction)
 {
     $startState = $stateLineStack->getLastStateLine();
     if (!$startState instanceof StateLineInterface) {
         throw new ObjectNotInitializedException();
     }
     /**
      * @var Transition $transition
      */
     $transition = $this->machine->{$transitionAction}($startState->getName(), $transitionName);
     $stateLine = $this->createStateLine($transition->getFinal()->getName(), $description);
     $stateLineStack->addStateLine($stateLine);
     $this->machineEventDispatcher->dispatchTransitionEvents($this->machine, $object, $stateLineStack, $transition);
     return $stateLineStack;
 }
Exemplo n.º 5
0
 /**
  * Sets ShippingStateLineStack
  *
  * @param StateLineStack $shippingStateLineStack ShippingStateLineStack
  *
  * @return $this Self object
  */
 public function setShippingStateLineStack(StateLineStack $shippingStateLineStack)
 {
     $this->shippingStateLines = $shippingStateLineStack->getStateLines();
     $this->shippingLastStateLine = $shippingStateLineStack->getLastStateLine();
     return $this;
 }