Example #1
0
 /**
  * Creates an instance of an entity.
  *
  * This method must return always an empty instance for related entity
  *
  * @return OrderLine New OrderLine instance
  */
 public function create()
 {
     /**
      * @var OrderLine $orderLine
      */
     $classNamespace = $this->getEntityNamespace();
     $orderLine = new $classNamespace();
     $orderLine->setOrderLineHistories(new ArrayCollection());
     $orderLineHistory = $this->orderLineHistoryFactory->create();
     $orderLineHistory->setOrderLine($orderLine)->setState($this->initialOrderHistoryState);
     $orderLine->addOrderLineHistory($orderLineHistory)->setLastOrderLineHistory($orderLineHistory);
     return $orderLine;
 }
Example #2
0
 /**
  * Given an existing OrderLine, changes its state and creates a new HistoryState.
  * 'PreChange' and 'PostChange' events are fired, which by default are observed by
  * OrderManager and OrderLineManager to enforce the validity of the state transitions.
  *
  * @param OrderInterface     $order     Order
  * @param OrderLineInterface $orderLine Orderline object
  * @param String             $newState  New state to append
  *
  * @return $this self Object
  */
 public function addStateToOrderLine(OrderInterface $order, OrderLineInterface $orderLine, $newState)
 {
     $lastOrderLineHistory = $orderLine->getOrderLineHistories()->last();
     $this->orderLineStateEventDispatcher->dispatchOrderLineStatePreChangeEvent($order, $orderLine, $lastOrderLineHistory, $newState);
     /**
      * @var OrderLineHistoryInterface $orderLineHistory
      */
     $orderLineHistory = $this->orderLineHistoryFactory->create();
     $orderLineHistory->setState($newState)->setOrderLine($orderLine);
     $orderLine->addOrderLineHistory($orderLineHistory)->setLastOrderLineHistory($orderLineHistory);
     $this->orderLineStateEventDispatcher->dispatchOrderLineStateOnChangeEvent($order, $orderLine, $lastOrderLineHistory, $orderLineHistory, $newState);
     return $this;
 }