/** * Convert quote payment to order payment * * @param \Magento\Sales\Model\Quote\Payment $payment * @return \Magento\Sales\Model\Quote\Payment */ public function paymentToOrderPayment(\Magento\Sales\Model\Quote\Payment $payment) { /** @var \Magento\Sales\Model\Order\Payment $orderPayment */ $orderPayment = $this->_orderPaymentFactory->create()->setStoreId($payment->getStoreId()); $orderPayment->setCustomerPaymentId($payment->getCustomerPaymentId()); $this->_objectCopyService->copyFieldsetToTarget('sales_convert_quote_payment', 'to_order_payment', $payment, $orderPayment); $orderPayment->setAdditionalInformation(\Magento\Payment\Model\Method\Substitution::INFO_KEY_TITLE, $payment->getMethodInstance()->getTitle()); return $orderPayment; }
/** * Order Payment instance getter * Will attempt to load by payment_id if it is set in data * * @param bool $shouldLoad * @return \Magento\Sales\Model\Order\Payment */ public function getOrderPaymentObject($shouldLoad = true) { $this->_verifyThisTransactionExists(); if (null === $this->_paymentObject && $shouldLoad) { $payment = $this->_paymentFactory->create()->load($this->getPaymentId()); if ($payment->getId()) { $this->setOrderPaymentObject($payment); } } return $this->_paymentObject; }
/** * Order Payment instance getter * Will attempt to load by payment_id if it is set in data * * @param bool $shouldLoad * @return \Magento\Sales\Model\Order\Payment */ public function getOrderPaymentObject($shouldLoad = true) { $this->_verifyThisTransactionExists(); if (null === $this->_paymentObject && $shouldLoad) { /** @var \Magento\Sales\Model\Order\Payment $payment */ $payment = $this->_paymentFactory->create()->load($this->getPaymentId()); if ($payment->getId()) { if (!$payment->getOrder()) { $payment->setOrder($this->getOrder()); } $this->setOrderPaymentObject($payment); } } return $this->_paymentObject; }
/** * Initialize new order based on payment data * * Takes arbitrary number of \Magento\Framework\Object instances to be treated as items for new order * * @return \Magento\Sales\Model\Order * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function createOrder() { $items = array(); $itemInfoObjects = func_get_args(); $billingAmount = 0; $shippingAmount = 0; $taxAmount = 0; $isVirtual = 1; $weight = 0; foreach ($itemInfoObjects as $itemInfo) { $item = $this->_getItem($itemInfo); $billingAmount += $item->getPrice(); $shippingAmount += $item->getShippingAmount(); $taxAmount += $item->getTaxAmount(); $weight += $item->getWeight(); if (!$item->getIsVirtual()) { $isVirtual = 0; } $items[] = $item; } $grandTotal = $billingAmount + $shippingAmount + $taxAmount; $order = $this->_orderFactory->create(); $billingAddress = $this->_addressFactory->create()->setData($this->getBillingAddressInfo())->setId(null); $shippingInfo = $this->getShippingAddressInfo(); $shippingAddress = $this->_addressFactory->create()->setData($shippingInfo)->setId(null); $payment = $this->_paymentFactory->create()->setMethod($this->getMethodCode()); $transferDataKeys = array('store_id', 'store_name', 'customer_id', 'customer_email', 'customer_firstname', 'customer_lastname', 'customer_middlename', 'customer_prefix', 'customer_suffix', 'customer_taxvat', 'customer_gender', 'customer_is_guest', 'customer_note_notify', 'customer_group_id', 'customer_note', 'shipping_method', 'shipping_description', 'base_currency_code', 'global_currency_code', 'order_currency_code', 'store_currency_code', 'base_to_global_rate', 'base_to_order_rate', 'store_to_base_rate', 'store_to_order_rate'); $orderInfo = $this->getOrderInfo(); foreach ($transferDataKeys as $key) { if (isset($orderInfo[$key])) { $order->setData($key, $orderInfo[$key]); } elseif (isset($shippingInfo[$key])) { $order->setData($key, $shippingInfo[$key]); } } $order->setStoreId($this->getStoreId())->setState(\Magento\Sales\Model\Order::STATE_NEW)->setBaseToOrderRate($this->getInfoValue('order_info', 'base_to_quote_rate'))->setStoreToOrderRate($this->getInfoValue('order_info', 'store_to_quote_rate'))->setOrderCurrencyCode($this->getInfoValue('order_info', 'quote_currency_code'))->setBaseSubtotal($billingAmount)->setSubtotal($billingAmount)->setBaseShippingAmount($shippingAmount)->setShippingAmount($shippingAmount)->setBaseTaxAmount($taxAmount)->setTaxAmount($taxAmount)->setBaseGrandTotal($grandTotal)->setGrandTotal($grandTotal)->setIsVirtual($isVirtual)->setWeight($weight)->setTotalQtyOrdered($this->getInfoValue('order_info', 'items_qty'))->setBillingAddress($billingAddress)->setShippingAddress($shippingAddress)->setPayment($payment); foreach ($items as $item) { $order->addItem($item); } return $order; }