@param OrderInterface $order

@return Invoice
493697
public function createForOrder(OrderInterface $order, $type = Invoice::TYPE_DEBIT)
    {
        $invoice = new Invoice();
        $number = $this->codeGenerator::generate($invoice);

        $data = [
            'order'        => $order,
            'number'       => $number,
            'date'         => date('d/m/Y'),
            'base_dir'     => $this->rootDir . '/../web',
            'invoice_type' => $type,
        ];

        $html = $this->templating->render($this->template, $data);
        $pdf = $this->pdfGenerator->getOutputFromHtml($html);

        $total = $type === Invoice::TYPE_DEBIT ?
            $order->getTotal() :
            $order->getTotal() * -1
        ;

        $order->addInvoice($invoice);
        $invoice->setOrder($order);
        $invoice->setNumber($number);
        $invoice->setMimeType('application/pdf');
        $invoice->setFile($pdf);
        $invoice->setType($type);
        $invoice->setTotal($total);

        return $invoice;
    }
109740
private function getOrderUserDefaultAddress(OrderInterface $order)
    {
        if (null === $user = $order->getUser()) {
            throw new OrderException('User is not set.');
        }
        if (null === $address = $user->getAddresses()->first()) { // TODO Default address
            throw new OrderException('Unable to find the user default address.');
        }
        return $address;
    }
550946
public function accountPv(\Magento\Sales\Api\Data\OrderInterface $order)
    {
        /* sale state validation should be performed before */
        $orderId = $order->getEntityId();
        /* update record state in the registry */
        $this->updateDatePaid($orderId);
        /* ... then transfer PV to the customer account */
        $req = new \Praxigento\Pv\Api\Service\Sale\Account\Pv\Request();
        $req->setSaleOrderId($orderId);
        $this->srvPvAccount->exec($req);
    }
95631
private function handleAddresses(OrderInterface $order)
    {
        // If invoice address is no set : use the user's default one.
        if (null === $order->getInvoiceAddress()) {
            $order->setInvoiceAddress(
                $this->getOrderUserDefaultAddress($order)
            );
        }

        // If delivery address is no set and not "same delivery address" : use the user's default one.
        if ((null === $order->getDeliveryAddress()) && !$order->getSameAddress()) {
            $order->setDeliveryAddress(
                $this->getOrderUserDefaultAddress($order)
            );
        }
        // Else if delivery address is set and "same delivery address"
        elseif ((null !== $deliveryAddress = $order->getDeliveryAddress()) && $order->getSameAddress()) {
            // Unset delivery address
            $order->setDeliveryAddress(null);
            // If the address is a clone (do not belong to a user)
            if (null === $deliveryAddress->getUser()) {
                // Delete the address
                $this->addressOperator->delete($deliveryAddress);
            }
        }

        // If type is order or quote, clone the addresses.
        if (in_array($order->getType(), [OrderTypes::TYPE_ORDER, OrderTypes::TYPE_QUOTE])) {
            // Clone invoice address if needed
            $invoiceAddress = $order->getInvoiceAddress();
            if (null !== $user = $invoiceAddress->getUser()) {
                $invoiceAddress = clone $invoiceAddress;
                $this->handleAddressIdentity($invoiceAddress, $user);
                $invoiceAddress->setUser(null);
                $order->setInvoiceAddress($invoiceAddress);
            }
            // Clone delivery address if needed
            if (!$order->getSameAddress()) {
                $deliveryAddress = $order->getDeliveryAddress();
                if (null !== $user = $deliveryAddress->getUser()) {
                    $deliveryAddress = clone $deliveryAddress;
                    $this->handleAddressIdentity($deliveryAddress, $user);
                    $deliveryAddress->setUser(null);
                    $order->setDeliveryAddress($deliveryAddress);
                }
            }
        }
    }
1160882
private function addShippingOptions(Order $order, FormInterface $form)
    {
        if ($order->getShippingMethod() instanceof ShippingMethod) {
            $provider = $this->getOptionsProvider($order->getShippingMethod());
            if ($provider instanceof ShippingMethodOptionsProviderInterface) {
                $form->addChild($this->getElement('select', [
                    'name'    => 'shippingMethodOption',
                    'label'   => 'order.label.shipping_method',
                    'options' => $provider->getShippingOptions(),
                ]));
            }
        }
    }
495384
public function sortable($order = null)
    {
        if (null === $order) {
            return $this->sortable;
        }

        $this->sortable = $order;
        return $this;
    }
760862
public function invoice($orderId, $invoiceKey)
    {
        /** @var OrderHandler $handler */
        $handler = $this->requestHandler();
        return $handler->invoice($orderId, $invoiceKey);
    }
500917
public function setOrder(\HarvestCloud\CoreBundle\Entity\Order $order = null)
    {
        $this->order = $order;

        return $this;
    }
478780
public function setOrder(\Librinfo\EcommerceBundle\Entity\Order $order = null)
    {
        $this->order = $order;

        return $this;
    }
614246
public function addOrderLine(OrderLineInterface $orderLine): OrderInterface
    {
        if (!$this->hasOrderLine($orderLine)) {
            $this->orderLines->add($orderLine);
            $orderLine->setOrder($this);
        }

        return $this;
    }
801149
public function dispatchOrderLineOnCreatedEvent(
        OrderInterface $order,
        CartLineInterface $cartLine,
        OrderLineInterface $orderLine
    ) {
        $orderLineOnCreatedEvent = new OrderLineOnCreatedEvent(
            $order,
            $cartLine,
            $orderLine
        );

        $this->eventDispatcher->dispatch(
            ElcodiCartEvents::ORDERLINE_ONCREATED,
            $orderLineOnCreatedEvent
        );

        return $this;
    }
1148044
public final function setOrderData(Order $order)
    {
        if (get_called_class() != self::class) {
            throw new \InvalidArgumentException("Method can be call only by OrderFinalized entity");
        }
        $this->id = $order->id;
        $this->setProperties($order);
    }
686291
public function acceptAction(Order $order)
    {
        $order->acceptBySeller();

        $em = $this->getDoctrine()->getEntityManager();
        $em->persist($order);
        $em->flush();

#        $this->get('notifier')->notify(new OrderAcceptedBySellerEvent($order), $this->getUser());

        return $this->redirect($this->generateUrl('Order_show', array(
            'id' => $order->getNumberForPath()
        )));
    }
130669
public function processCallback(OrderInterface $order, $action)
    {
        $params = [
            'bank' => $this->getCode(),
            'reference' => $order->getReference(),
            'check' => $this->generateUrlCheck($order),
            'action' => $action,
        ];

        $url = $this->router->generate($this->getOption('url_callback'), $params, UrlGeneratorInterface::ABSOLUTE_URL);

        $response = $this->browser->get($url);

        $routeName = 'ok' === $response->getContent() ? 'url_return_ok' : 'url_return_ko';

        $response = new RedirectResponse($this->router->generate($this->getOption($routeName), $params, true), 302, [
            'Content-Type' => 'text/plain',
        ]);
        $response->setPrivate();

        return $response;
    }
1149839
protected function addDelivery(InvoiceInterface $invoice, OrderInterface $order)
    {
        /** @var InvoiceElementInterface $invoiceElement */
        $invoiceElement = $this->invoiceElementManager->create();

        $invoiceElement->setQuantity(1);
        $invoiceElement->setPrice($order->getDeliveryCost());
        $invoiceElement->setUnitPriceExcl($order->getDeliveryCost());
        $invoiceElement->setUnitPriceInc($order->getDeliveryCost());
        $invoiceElement->setTotal($order->getDeliveryCost());
        $invoiceElement->setVatRate(0);

        $invoiceElement->setDesignation($this->deliveryPool->getMethod($order->getDeliveryMethod())->getName());
        $invoiceElement->setDescription($this->deliveryPool->getMethod($order->getDeliveryMethod())->getName());

        $invoiceElement->setInvoice($invoice);
        $invoice->addInvoiceElement($invoiceElement);
    }
1339746
private function createOrderInvoice($order, $transactionId, $amount)
    {
        if ($order->getTotalInvoiced() + $amount == $order->getGrandTotal()) {
            $invoice = $this->invoiceService->prepareInvoice($order);
        } else {
            $invoice = $this->invoiceService->prepareInvoiceWithoutItems($order, $amount);
        }

        $invoice->setRequestedCaptureCase(Invoice::CAPTURE_OFFLINE);
        $invoice->setTransactionId($transactionId);
        $invoice->setBaseGrandTotal($amount);
        $invoice->setGrandTotal($amount);
        $invoice->register();
        $invoice->save();

        $order->addRelatedObject($invoice);

        if (!$invoice->getEmailSent()) {
            $this->invoiceSender->send($invoice);
        }

        //Add notification comment to order
        $order->addStatusHistoryComment(
            __('Invoice #%1 is created. Notification email is sent to customer.', $invoice->getId())
        )->setIsCustomerNotified(true)->save();

        return $invoice;
    }
291227
public function setSortByColumnOrder($order)
    {
        switch ($order) {
            case 'desc':
                $this->sortByColumnOrder = self::SORT_ORDER_DESC;
                break;
            case 'asc':
                $this->sortByColumnOrder = self:: SORT_ORDER_ASC;
                break;
        }

        return $this;
    }