/** * 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; }
/** * Completes the payment process when the payment.order.success event is raised. * * This means that we can change the order state to ACCEPTED * * @param AbstractPaymentEvent $event */ public function setOrderToPaid(AbstractPaymentEvent $event) { $order = $event->getPaymentBridge()->getOrder(); if (!$order instanceof OrderInterface) { throw new \LogicException('Cannot retrieve Order from PaymentBridge'); } /** * We create the new entry in the payment state machine */ $stateLineStack = $this->paymentMachineManager->transition($order, $order->getPaymentStateLineStack(), 'pay', 'Order paid using ' . $event->getPaymentMethod()->getPaymentName()); $order->setPaymentStateLineStack($stateLineStack); /** * We save all the data */ $this->stateLineObjectManager->persist($stateLineStack->getLastStateLine()); $this->stateLineObjectManager->flush($stateLineStack->getLastStateLine()); $this->stateLineObjectManager->flush($order); }