/**
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  */
 public function splitQty(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     $storeId = $order->getStoreId();
     /* get stock ID for the store view */
     $stockId = $this->_manStock->getStockIdByStoreId($storeId);
     /** @var \Magento\Sales\Api\Data\OrderItemInterface[] $items */
     $items = $order->getItems();
     $itemsData = [];
     /** @var \Magento\Sales\Api\Data\OrderItemInterface $item */
     foreach ($items as $item) {
         $prodId = $item->getProductId();
         $itemId = $item->getItemId();
         /* qty of the product can be changed in invoice, but we use ordered only  */
         $qty = $item->getQtyOrdered();
         /* register sale item (fragment total qty by lots) */
         $itemData = $this->_manObj->create(\Praxigento\Warehouse\Service\QtyDistributor\Data\Item::class);
         $itemData->setItemId($itemId);
         $itemData->setProductId($prodId);
         $itemData->setQuantity($qty);
         $itemData->setStockId($stockId);
         $itemsData[] = $itemData;
     }
     $reqSale = $this->_manObj->create(\Praxigento\Warehouse\Service\QtyDistributor\Request\RegisterSale::class);
     $reqSale->setSaleItems($itemsData);
     $this->_callQtyDistributor->registerSale($reqSale);
 }
Exemple #2
0
 public function testGetShippingAddress()
 {
     /** @var AddressAdapterInterface $addressAdapterMock */
     $addressAdapterMock = $this->getMockBuilder('Magento\\Payment\\Gateway\\Data\\AddressAdapterInterface')->getMockForAbstractClass();
     /** @var \Magento\Sales\Api\Data\OrderAddressInterface $orderAddressMock */
     $orderAddressMock = $this->getMockBuilder('Magento\\Sales\\Api\\Data\\OrderAddressInterface')->getMockForAbstractClass();
     $this->addressAdapterFactoryMock->expects($this->once())->method('create')->with(['address' => $orderAddressMock])->willReturn($addressAdapterMock);
     $this->orderMock->expects($this->once())->method('getShippingAddress')->willReturn($orderAddressMock);
     $this->assertSame($addressAdapterMock, $this->model->getShippingAddress());
 }
 /**
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @return \Praxigento\Pv\Service\Sale\Data\Item[]
  */
 public function getServiceItemsForMageSaleOrder(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     $result = [];
     $storeId = $order->getStoreId();
     /* get stock ID for the store view */
     $stockId = $this->_manStock->getStockIdByStoreId($storeId);
     /** @var \Magento\Sales\Api\Data\OrderItemInterface[] $items */
     $items = $order->getItems();
     /** @var \Magento\Sales\Api\Data\OrderItemInterface $item */
     foreach ($items as $item) {
         $itemData = $this->getServiceItemForMageItem($item, $stockId);
         $result[] = $itemData;
     }
     return $result;
 }
 /**
  * Collect orders data and call service method to register order PV.
  *
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  */
 public function savePv(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     $orderId = $order->getId();
     $state = $order->getState();
     $dateCreated = $order->getCreatedAt();
     $itemsData = $this->_subCollector->getServiceItemsForMageSaleOrder($order);
     /* compose request data and request itself */
     /** @var \Praxigento\Pv\Service\Sale\Request\Save $req */
     $req = $this->_manObj->create(\Praxigento\Pv\Service\Sale\Request\Save::class);
     $req->setSaleOrderId($orderId);
     $req->setOrderItems($itemsData);
     if ($state == \Magento\Sales\Model\Order::STATE_PROCESSING) {
         $req->setSaleOrderDatePaid($dateCreated);
     }
     $this->_callSale->save($req);
 }
 /**
  * Run command
  *
  * @param OrderPaymentInterface $payment
  * @param string|float|int $amount
  * @param OrderInterface $order
  * @return string
  */
 public function execute(OrderPaymentInterface $payment, $amount, OrderInterface $order)
 {
     $state = Order::STATE_PROCESSING;
     $status = false;
     $formattedAmount = $order->getBaseCurrency()->formatTxt($amount);
     if ($payment->getIsTransactionPending()) {
         $message = __('The order amount of %1 is pending approval on the payment gateway.', $formattedAmount);
         $state = Order::STATE_PAYMENT_REVIEW;
         if ($payment->getIsFraudDetected()) {
             $status = Order::STATUS_FRAUD;
         }
     } else {
         $message = __('Ordered amount of %1', $formattedAmount);
     }
     $this->setOrderStateAndStatus($order, $status, $state);
     return $message;
 }
 public function testExecuteUpdateAction()
 {
     $orderId = 30;
     $action = 'update';
     $this->requestMock->expects($this->at(0))->method('getParam')->with('order_id')->willReturn($orderId);
     $this->requestMock->expects($this->at(1))->method('getParam')->with('action')->willReturn($action);
     $this->resultRedirectFactoryMock->expects($this->once())->method('create')->willReturn($this->resultRedirectMock);
     $this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)->willReturn($this->orderMock);
     $this->orderMock->expects($this->any())->method('getEntityId')->willReturn($orderId);
     $this->orderMock->expects($this->any())->method('getPayment')->willReturn($this->paymentMock);
     $this->orderRepositoryMock->expects($this->once())->method('save')->with($this->orderMock)->willReturnSelf();
     $this->paymentMock->expects($this->once())->method('update');
     $this->paymentMock->expects($this->any())->method('getIsTransactionApproved')->willReturn(true);
     $this->messageManagerMock->expects($this->once())->method('addSuccess');
     $this->resultRedirectMock->expects($this->once())->method('setPath')->with('sales/order/view')->willReturnSelf();
     $result = $this->reviewPayment->execute();
     $this->assertEquals($this->resultRedirectMock, $result);
 }
 /**
  * Run command
  *
  * @param OrderPaymentInterface $payment
  * @param string|float|int $amount
  * @param OrderInterface $order
  * @return string
  */
 public function execute(OrderPaymentInterface $payment, $amount, OrderInterface $order)
 {
     $state = SalesOrder::STATE_PROCESSING;
     $status = false;
     $formattedAmount = $order->getBaseCurrency()->formatTxt($amount);
     if ($payment->getIsTransactionPending()) {
         $message = __('An amount of %1 will be captured after being approved at the payment gateway.', $formattedAmount);
         $state = SalesOrder::STATE_PAYMENT_REVIEW;
         if ($payment->getIsFraudDetected()) {
             $status = SalesOrder::STATUS_FRAUD;
         }
     } else {
         // normal online capture: invoice is marked as "paid"
         $message = __('Captured amount of %1 online', $formattedAmount);
     }
     $this->setOrderStateAndStatus($order, $status, $state);
     return $message;
 }
 /**
  * Save gift message for items of order
  *
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @return \Magento\Sales\Api\Data\OrderInterface
  */
 protected function saveOrderItemGiftMessage(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     if (null !== $order->getItems()) {
         /** @var \Magento\Sales\Api\Data\OrderItemInterface $orderItem */
         foreach ($order->getItems() as $orderItem) {
             if (null !== $orderItem->getExtensionAttributes() && null !== $orderItem->getExtensionAttributes()->getGiftMessage()) {
                 /* @var \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage */
                 $giftMessage = $orderItem->getExtensionAttributes()->getGiftMessage();
                 try {
                     $this->giftMessageOrderItemRepository->save($order->getEntityId(), $orderItem->getItemId(), $giftMessage);
                 } catch (\Exception $e) {
                     throw new CouldNotSaveException(__('Could not add gift message to order\'s item: "%1"', $e->getMessage()), $e);
                 }
             }
         }
     }
     return $order;
 }
 /**
  * @param QuoteAddressToOrder $subject
  * @param OrderInterface $order
  * @return OrderInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order)
 {
     /** @var \Magento\Sales\Model\Order $order */
     $taxes = $this->quoteAddress->getAppliedTaxes();
     $extensionAttributes = $order->getExtensionAttributes();
     if ($extensionAttributes == null) {
         $extensionAttributes = $this->orderExtensionFactory->create();
     }
     if (!empty($taxes)) {
         $extensionAttributes->setAppliedTaxes($taxes);
         $extensionAttributes->setConvertingFromQuote(true);
     }
     $itemAppliedTaxes = $this->quoteAddress->getItemsAppliedTaxes();
     if (!empty($itemAppliedTaxes)) {
         $extensionAttributes->setItemAppliedTaxes($itemAppliedTaxes);
     }
     $order->setExtensionAttributes($extensionAttributes);
     return $order;
 }
 public function testEmail()
 {
     $orderId = 10000031;
     $this->request->expects($this->once())->method('getParam')->with('order_id')->will($this->returnValue($orderId));
     $this->orderRepositoryMock->expects($this->once())->method('get')->with($orderId)->willReturn($this->orderMock);
     $this->orderMock->expects($this->atLeastOnce())->method('getEntityId')->will($this->returnValue($orderId));
     $this->orderManagementMock->expects($this->once())->method('notify')->with($orderId)->willReturn(true);
     $this->messageManager->expects($this->once())->method('addSuccess')->with('You sent the order email.');
     $this->resultRedirect->expects($this->once())->method('setPath')->with('sales/order/view', ['order_id' => $orderId])->willReturnSelf();
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Redirect', $this->orderEmail->execute());
     $this->assertEquals($this->response, $this->orderEmail->getResponse());
 }
 /**
  * Run command
  *
  * @param OrderPaymentInterface $payment
  * @param string|float|int $amount
  * @param OrderInterface $order
  * @return string
  */
 public function execute(OrderPaymentInterface $payment, $amount, OrderInterface $order)
 {
     /**
      * @var $payment Payment
      */
     $state = Order::STATE_PROCESSING;
     $status = false;
     $formattedAmount = $order->getBaseCurrency()->formatTxt($amount);
     if ($payment->getIsTransactionPending()) {
         $message = __('An amount of %1 will be captured after being approved at the payment gateway.', $formattedAmount);
         $state = Order::STATE_PAYMENT_REVIEW;
     } else {
         $message = __('Registered notification about captured amount of %1.', $formattedAmount);
     }
     if ($payment->getIsFraudDetected()) {
         $state = Order::STATE_PAYMENT_REVIEW;
         $message = __('Order is suspended as its capture amount %1 is suspected to be fraudulent.', $formattedAmount);
         $status = Order::STATUS_FRAUD;
     }
     $this->setOrderStateAndStatus($order, $status, $state);
     return $message;
 }
Exemple #12
0
 /**
  * Get gift message for items of order
  *
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @return \Magento\Sales\Api\Data\OrderInterface
  */
 protected function getOrderItemGiftMessage(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     if (null !== $order->getItems()) {
         /** @var \Magento\Sales\Api\Data\OrderItemInterface $orderItem */
         foreach ($order->getItems() as $orderItem) {
             if ($orderItem->getExtensionAttributes() && $orderItem->getExtensionAttributes()->getGiftMessage()) {
                 continue;
             }
             try {
                 /* @var \Magento\GiftMessage\Api\Data\MessageInterface $giftMessage */
                 $giftMessage = $this->giftMessageOrderItemRepository->get($order->getEntityId(), $orderItem->getItemId());
             } catch (NoSuchEntityException $e) {
                 continue;
             }
             /** @var \Magento\Sales\Api\Data\OrderItemExtension $orderItemExtension */
             $orderItemExtension = $this->orderItemExtensionFactory->create();
             $orderItemExtension->setGiftMessage($giftMessage);
             $orderItem->setExtensionAttributes($orderItemExtension);
         }
     }
     return $order;
 }
 /**
  * @param OrderPaymentInterface $payment
  * @param string|float $amount
  * @param OrderInterface $order
  * @return \Magento\Framework\Phrase
  */
 public function execute(OrderPaymentInterface $payment, $amount, OrderInterface $order)
 {
     $state = Order::STATE_PROCESSING;
     $status = false;
     $formattedAmount = $order->getBaseCurrency()->formatTxt($amount);
     if ($payment->getIsTransactionPending()) {
         $state = Order::STATE_PAYMENT_REVIEW;
         $message = __('We will authorize %1 after the payment is approved at the payment gateway.', $formattedAmount);
     } else {
         if ($payment->getIsFraudDetected()) {
             $state = Order::STATE_PROCESSING;
             $message = __('Order is suspended as its authorizing amount %1 is suspected to be fraudulent.', $formattedAmount);
         } else {
             $message = __('Authorized amount of %1', $formattedAmount);
         }
     }
     if ($payment->getIsFraudDetected()) {
         $status = Order::STATUS_FRAUD;
     }
     $this->setOrderStateAndStatus($order, $status, $state);
     return $message;
 }
 /**
  * @param QuoteAddressToOrder $subject
  * @param OrderInterface $order
  * @return OrderInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order)
 {
     /** @var \Magento\Sales\Model\Order $order */
     $taxes = $this->quoteAddress->getAppliedTaxes();
     if (is_array($taxes)) {
         if (is_array($order->getAppliedTaxes())) {
             $taxes = array_merge($order->getAppliedTaxes(), $taxes);
         }
         $order->setCustomAttribute('applied_taxes', $taxes);
         $order->setCustomAttribute('converting_from_quote', true);
     }
     $itemAppliedTaxes = $this->quoteAddress->getItemsAppliedTaxes();
     if (is_array($itemAppliedTaxes)) {
         if (is_array($order->getItemAppliedTaxes())) {
             $itemAppliedTaxes = array_merge($order->getItemAppliedTaxes(), $itemAppliedTaxes);
         }
         $order->setCustomAttribute('item_applied_taxes', $itemAppliedTaxes);
     }
     return $order;
 }
Exemple #15
0
 /**
  * Links transaction with parent transaction
  *
  * @param TransactionInterface $transaction
  * @return TransactionInterface
  */
 protected function linkWithParentTransaction(TransactionInterface $transaction)
 {
     $parentTransactionId = $this->payment->getParentTransactionId();
     if ($parentTransactionId) {
         $transaction->setParentTxnId($parentTransactionId);
         if ($this->payment->getShouldCloseParentTransaction()) {
             $parentTransaction = $this->transactionRepository->getByTransactionId($parentTransactionId, $this->payment->getid(), $this->order->getId());
             if ($parentTransaction) {
                 if (!$parentTransaction->getIsClosed()) {
                     $parentTransaction->isFailsafe($this->failSafe)->close(false);
                 }
                 $this->order->addRelatedObject($parentTransaction);
             }
         }
     }
     return $transaction;
 }
 /**
  * Get details for GetTaxRequest
  *
  * @param \Magento\Store\Api\Data\StoreInterface $store
  * @param $address \Magento\Quote\Api\Data\AddressInterface|\Magento\Sales\Api\Data\OrderAddressInterface
  * @param \Magento\Quote\Api\Data\CartInterface|\Magento\Sales\Api\Data\OrderInterface $object
  * @return array
  * @throws LocalizedException
  */
 protected function retrieveGetTaxRequestFields(StoreInterface $store, $address, $object)
 {
     $customerId = $object->getCustomerId();
     $customer = $this->getCustomerById($customerId);
     $storeId = $store->getId();
     if ($this->config->getLiveMode() == Config::API_PROFILE_NAME_PROD) {
         $companyCode = $this->config->getCompanyCode($storeId);
     } else {
         $companyCode = $this->config->getDevelopmentCompanyCode($storeId);
     }
     $businessIdentificationNumber = $this->getBusinessIdentificationNumber($store, $address, $customer);
     $locationCode = $this->config->getLocationCode($store);
     return ['BusinessIdentificationNo' => $businessIdentificationNumber, 'CompanyCode' => $companyCode, 'LocationCode' => $locationCode, 'OriginAddress' => $this->address->getAddress($this->config->getOriginAddress($storeId))];
 }
 /**
  * @param \Magento\Sales\Api\Data\OrderInterface $mageOrder
  * @return \Praxigento\Odoo\Data\Odoo\Payment[]
  */
 public function getSaleOrderPayments(\Magento\Sales\Api\Data\OrderInterface $mageOrder)
 {
     $result = [];
     $odooPayment = $this->_manObj->create(\Praxigento\Odoo\Data\Odoo\Payment::class);
     /* collect data */
     $magePayment = $mageOrder->getPayment();
     $code = $this->_manBusinessCodes->getBusCodeForPaymentMethod($magePayment);
     $ordered = $magePayment->getBaseAmountOrdered();
     $amount = $this->_manFormat->toNumber($ordered);
     /* populate Odoo Data Object */
     $odooPayment->setCode($code);
     $odooPayment->setAmount($amount);
     $result[] = $odooPayment;
     return $result;
 }
 /**
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @return \Magento\Sales\Api\Data\OrderInterface
  */
 public function place(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     // transaction will be here
     //begin transaction
     try {
         //            $order = $this->orderRepository->save($order);
         $order->place();
         return $this->orderRepository->save($order);
         //commit
     } catch (\Exception $e) {
         throw $e;
         //rollback;
     }
 }
Exemple #19
0
 /**
  * Returns shipping address
  *
  * @return AddressAdapterInterface
  */
 public function getShippingAddress()
 {
     return $this->addressAdapterFactory->create(['address' => $this->order->getShippingAddress()]);
 }
 /**
  * Gets the remote IP address for the order.
  *
  * @return string|null Remote IP address.
  */
 public function getRemoteIp()
 {
     return $this->order->getRemoteIp();
 }
Exemple #21
0
 /**
  * Returns order id
  *
  * @return int
  */
 public function getId()
 {
     return $this->order->getEntityId();
 }
Exemple #22
0
 /**
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     $extensionAttribute = $order->getExtensionAttributes();
     if (!$extensionAttribute || !$extensionAttribute->getConvertingFromQuote() || $order->getAppliedTaxIsSaved()) {
         return;
     }
     /** @var \Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxInterface[]|null $taxes */
     $taxes = $extensionAttribute->getAppliedTaxes();
     if ($taxes == null) {
         $taxes = [];
     }
     /** @var \Magento\Tax\Api\Data\OrderTaxDetailsItemInterface[]|null $taxesForItems */
     $taxesForItems = $extensionAttribute->getItemAppliedTaxes();
     if ($taxesForItems == null) {
         $taxesForItems = [];
     }
     $ratesIdQuoteItemId = [];
     foreach ($taxesForItems as $taxesArray) {
         foreach ($taxesArray['applied_taxes'] as $rates) {
             if (isset($rates['extension_attributes'])) {
                 /** @var \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $taxRates */
                 $taxRates = $rates['extension_attributes']->getRates();
                 if (is_array($taxRates)) {
                     if (count($taxRates) == 1) {
                         $ratesIdQuoteItemId[$rates['id']][] = ['id' => $taxesArray['item_id'], 'percent' => $rates['percent'], 'code' => $taxRates[0]['code'], 'associated_item_id' => $taxesArray['associated_item_id'], 'item_type' => $taxesArray['type'], 'amount' => $rates['amount'], 'base_amount' => $rates['base_amount'], 'real_amount' => $rates['amount'], 'real_base_amount' => $rates['base_amount']];
                     } else {
                         $percentSum = 0;
                         foreach ($taxRates as $rate) {
                             $realAmount = $rates['amount'] * $rate['percent'] / $rates['percent'];
                             $realBaseAmount = $rates['base_amount'] * $rate['percent'] / $rates['percent'];
                             $ratesIdQuoteItemId[$rates['id']][] = ['id' => $taxesArray['item_id'], 'percent' => $rate['percent'], 'code' => $rate['code'], 'associated_item_id' => $taxesArray['associated_item_id'], 'item_type' => $taxesArray['type'], 'amount' => $rates['amount'], 'base_amount' => $rates['base_amount'], 'real_amount' => $realAmount, 'real_base_amount' => $realBaseAmount];
                             $percentSum += $rate['percent'];
                         }
                     }
                 }
             }
         }
     }
     foreach ($taxes as $row) {
         $id = $row['id'];
         if (isset($row['extension_attributes'])) {
             /** @var \Magento\Tax\Api\Data\AppliedTaxRateInterface[] $taxRates */
             $taxRates = $row['extension_attributes']->getRates();
             if (is_array($taxRates)) {
                 foreach ($taxRates as $tax) {
                     if ($row['percent'] == null) {
                         $baseRealAmount = $row['base_amount'];
                     } else {
                         if ($row['percent'] == 0 || $tax['percent'] == 0) {
                             continue;
                         }
                         $baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
                     }
                     $hidden = isset($row['hidden']) ? $row['hidden'] : 0;
                     $priority = isset($tax['priority']) ? $tax['priority'] : 0;
                     $position = isset($tax['position']) ? $tax['position'] : 0;
                     $process = isset($row['process']) ? $row['process'] : 0;
                     $data = ['order_id' => $order->getEntityId(), 'code' => $tax['code'], 'title' => $tax['title'], 'hidden' => $hidden, 'percent' => $tax['percent'], 'priority' => $priority, 'position' => $position, 'amount' => $row['amount'], 'base_amount' => $row['base_amount'], 'process' => $process, 'base_real_amount' => $baseRealAmount];
                     /** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
                     $orderTax = $this->orderTaxFactory->create();
                     $result = $orderTax->setData($data)->save();
                     if (isset($ratesIdQuoteItemId[$id])) {
                         foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
                             if ($quoteItemId['code'] == $tax['code']) {
                                 $itemId = null;
                                 $associatedItemId = null;
                                 if (isset($quoteItemId['id'])) {
                                     //This is a product item
                                     $item = $order->getItemByQuoteItemId($quoteItemId['id']);
                                     $itemId = $item->getId();
                                 } elseif (isset($quoteItemId['associated_item_id'])) {
                                     //This item is associated with a product item
                                     $item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
                                     $associatedItemId = $item->getId();
                                 }
                                 $data = ['item_id' => $itemId, 'tax_id' => $result->getTaxId(), 'tax_percent' => $quoteItemId['percent'], 'associated_item_id' => $associatedItemId, 'amount' => $quoteItemId['amount'], 'base_amount' => $quoteItemId['base_amount'], 'real_amount' => $quoteItemId['real_amount'], 'real_base_amount' => $quoteItemId['real_base_amount'], 'taxable_item_type' => $quoteItemId['item_type']];
                                 /** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
                                 $taxItem = $this->taxItemFactory->create();
                                 $taxItem->setData($data)->save();
                             }
                         }
                     }
                 }
             }
         }
     }
     $order->setAppliedTaxIsSaved(true);
     return $this;
 }
 /**
  * Return invoice model for transaction
  *
  * @param OrderInterface $order
  * @param string $transactionId
  * @return false|Invoice
  */
 protected function getInvoiceForTransactionId(OrderInterface $order, $transactionId)
 {
     foreach ($order->getInvoiceCollection() as $invoice) {
         if ($invoice->getTransactionId() == $transactionId) {
             $invoice->load($invoice->getId());
             // to make sure all data will properly load (maybe not required)
             return $invoice;
         }
     }
     foreach ($order->getInvoiceCollection() as $invoice) {
         if ($invoice->getState() == \Magento\Sales\Model\Order\Invoice::STATE_OPEN && $invoice->load($invoice->getId())) {
             $invoice->setTransactionId($transactionId);
             return $invoice;
         }
     }
     return false;
 }
Exemple #24
0
 /**
  * Returns order grand total amount
  *
  * @return float|null
  */
 public function getGrandTotalAmount()
 {
     return $this->order->getBaseGrandTotal();
 }
 /**
  * Order state setter.
  *
  * If status is specified, will add order status history with specified comment
  * the setData() cannot be overridden because of compatibility issues with resource model
  * By default allows to set any state. Can also update status to default or specified value
  * Complete and closed states are encapsulated intentionally
  *
  * @param \Magento\Sales\Api\Data\OrderInterface $order
  * @param string $state
  * @param string|bool $status
  * @param string $comment
  * @param bool $isCustomerNotified
  * @param bool $shouldProtectState
  * @return \Magento\Sales\Model\Order
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function setState(\Magento\Sales\Api\Data\OrderInterface $order, $state, $status = false, $comment = '', $isCustomerNotified = null, $shouldProtectState = true)
 {
     // attempt to set the specified state
     if ($shouldProtectState) {
         if ($order->isStateProtected($state)) {
             throw new \Magento\Framework\Exception\LocalizedException(__('The Order State "%1" must not be set manually.', $state));
         }
     }
     $transport = new \Magento\Framework\Object(['state' => $state, 'status' => $status, 'comment' => $comment, 'is_customer_notified' => $isCustomerNotified]);
     $this->eventManager->dispatch('sales_order_state_change_before', ['order' => $this, 'transport' => $transport]);
     $status = $transport->getStatus();
     $order->setData('state', $transport->getState());
     // add status history
     if ($status) {
         if ($status === true) {
             $status = $order->getConfig()->getStateDefaultStatus($transport->getState());
         }
         $order->setStatus($status);
         $history = $order->addStatusHistoryComment($transport->getComment(), false);
         // no sense to set $status again
         $history->setIsCustomerNotified($transport->getIsCustomerNotified());
     }
     return $this;
 }
 /**
  * @param OrderInterface $order
  * @return void
  */
 private function setShippingAssignments(OrderInterface $order)
 {
     /** @var OrderExtensionInterface $extensionAttributes */
     $extensionAttributes = $order->getExtensionAttributes();
     if ($extensionAttributes === null) {
         $extensionAttributes = $this->getOrderExtensionDependency();
     } elseif ($extensionAttributes->getShippingAssignments() !== null) {
         return;
     }
     /** @var ShippingAssignmentInterface $shippingAssignment */
     $shippingAssignments = $this->getShippingAssignmentBuilderDependency();
     $shippingAssignments->setOrderId($order->getEntityId());
     $extensionAttributes->setShippingAssignments($shippingAssignments->create());
     $order->setExtensionAttributes($extensionAttributes);
 }
 /** @inheritdoc */
 public function getBusCodeForShippingMethod(\Magento\Sales\Api\Data\OrderInterface $order)
 {
     $result = null;
     $mage = $order->getShippingMethod();
     if ($mage == self::M_SHIP_FLAT_RATE) {
         $result = self::B_SHIP_FLAT_RATE;
     }
     return $result;
 }
 /**
  * @param QuoteAddressToOrder $subject
  * @param OrderInterface $order
  * @return OrderInterface
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order)
 {
     /** @var \Magento\Sales\Model\Order $order */
     $taxes = $this->quoteAddress->getAppliedTaxes();
     $extensionAttributes = $order->getExtensionAttributes();
     if ($extensionAttributes == null) {
         $extensionAttributes = $this->orderExtensionFactory->create();
     }
     if (!empty($taxes)) {
         foreach ($taxes as $key => $tax) {
             $tax['extension_attributes']['rates'] = $tax['rates'];
             unset($tax['rates']);
             $taxes[$key] = $tax;
         }
         $extensionAttributes->setAppliedTaxes($taxes);
         $extensionAttributes->setConvertingFromQuote(true);
     }
     $itemAppliedTaxes = $this->quoteAddress->getItemsAppliedTaxes();
     $itemAppliedTaxesModified = [];
     if (!empty($itemAppliedTaxes)) {
         foreach ($itemAppliedTaxes as $key => $itemAppliedTaxItem) {
             if (is_array($itemAppliedTaxItem) && !empty($itemAppliedTaxItem)) {
                 foreach ($itemAppliedTaxItem as $itemAppliedTax) {
                     $itemAppliedTaxesModified[$key]['type'] = $itemAppliedTax['item_type'];
                     $itemAppliedTaxesModified[$key]['item_id'] = $itemAppliedTax['item_id'];
                     $itemAppliedTaxesModified[$key]['associated_item_id'] = $itemAppliedTax['associated_item_id'];
                     $itemAppliedTax['extension_attributes']['rates'] = $itemAppliedTax['rates'];
                     unset($itemAppliedTax['rates']);
                     $itemAppliedTaxesModified[$key]['applied_taxes'][] = $itemAppliedTax;
                 }
             }
         }
         $extensionAttributes->setItemAppliedTaxes($itemAppliedTaxesModified);
     }
     $order->setExtensionAttributes($extensionAttributes);
     return $order;
 }