Example #1
0
 /**
  * Get url for reorder action
  *
  * @param \Magento\Sales\Model\Order $order
  * @return string
  */
 public function getReorderUrl($order)
 {
     if (!$this->httpContext->getValue(Context::CONTEXT_AUTH)) {
         return $this->getUrl('sales/guest/reorder', ['order_id' => $order->getId()]);
     }
     return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]);
 }
 /**
  * {@inheritdoc}
  */
 public function canView(\Magento\Sales\Model\Order $order)
 {
     $currentOrder = $this->registry->registry('current_order');
     if ($order->getId() && $order->getId() === $currentOrder->getId()) {
         return true;
     }
     return false;
 }
Example #3
0
 /**
  * Process addresses saving
  *
  * @param Order $order
  * @return $this
  * @throws \Exception
  */
 public function process(Order $order)
 {
     if (null !== $order->getAddresses()) {
         /** @var \Magento\Sales\Model\Order\Address $address */
         foreach ($order->getAddresses() as $address) {
             $address->setParentId($order->getId());
             $address->setOrder($order);
             $address->save();
         }
         $billingAddress = $order->getBillingAddress();
         $attributesForSave = [];
         if ($billingAddress && $order->getBillingAddressId() != $billingAddress->getId()) {
             $order->setBillingAddressId($billingAddress->getId());
             $attributesForSave[] = 'billing_address_id';
         }
         $shippingAddress = $order->getShippingAddress();
         if ($shippingAddress && $order->getShippigAddressId() != $shippingAddress->getId()) {
             $order->setShippingAddressId($shippingAddress->getId());
             $attributesForSave[] = 'shipping_address_id';
         }
         if (!empty($attributesForSave)) {
             $this->attribute->saveAttribute($order, $attributesForSave);
         }
     }
     return $this;
 }
 protected function _getOrder($vendorOrderId)
 {
     $this->_order = $this->_orderFactory->create()->loadByIncrementId($vendorOrderId);
     if (!$this->_order->getId()) {
         throw new Exception(sprintf('Wrong order ID: "%s".', $vendorOrderId));
     }
     return $this->_order;
 }
Example #5
0
 /**
  * Load order
  *
  * @return \Magento\Sales\Model\Order
  * @throws Exception
  */
 protected function _getOrder()
 {
     $incrementId = $this->getRequestData('invoice');
     $this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);
     if (!$this->_order->getId()) {
         throw new Exception(sprintf('Wrong order ID: "%s".', $incrementId));
     }
     return $this->_order;
 }
 /**
  * {@inheritdoc}
  */
 public function canView(\Magento\Sales\Model\Order $order)
 {
     $customerId = $this->customerSession->getCustomerId();
     $availableStatuses = $this->orderConfig->getVisibleOnFrontStatuses();
     if ($order->getId() && $order->getCustomerId() && $order->getCustomerId() == $customerId && in_array($order->getStatus(), $availableStatuses, true)) {
         return true;
     }
     return false;
 }
 /**
  * Initializes the Order Object from the transaction in the Reconcile response object
  * @param $responseObject
  * @throws \Exception
  */
 private function setOrderByReconcile($responseObject)
 {
     $transaction_id = $responseObject->transaction_id;
     list($incrementId, $hash) = explode('_', $transaction_id);
     $this->_order = $this->getOrderFactory()->create()->loadByIncrementId(intval($incrementId));
     if (!$this->_order->getId()) {
         throw new \Exception(sprintf('Wrong order ID: "%s".', $incrementId));
     }
 }
Example #8
0
 /**
  * Saves new order transaction incrementing "try".
  *
  * @param \Magento\Sales\Model\Order $order
  * @param string $payuplOrderId
  * @param string $payuplExternalOrderId
  * @param string $status
  */
 public function addNewOrderTransaction(\Magento\Sales\Model\Order $order, $payuplOrderId, $payuplExternalOrderId, $status)
 {
     $orderId = $order->getId();
     $payment = $order->getPayment();
     $payment->setTransactionId($payuplOrderId);
     $payment->setTransactionAdditionalInfo(\Magento\Sales\Model\Order\Payment\Transaction::RAW_DETAILS, ['order_id' => $payuplExternalOrderId, 'try' => $this->transactionResource->getLastTryByOrderId($orderId) + 1, 'status' => $status]);
     $payment->setIsTransactionClosed(0);
     $transaction = $payment->addTransaction('order');
     $transaction->save();
     $payment->save();
 }
Example #9
0
 /**
  * Check order status before save
  *
  * @param Order $order
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function check(Order $order)
 {
     if (!$order->getId()) {
         return $order;
     }
     if (!$order->isCanceled() && !$order->canUnhold() && !$order->canInvoice() && !$order->canShip()) {
         if (0 == $order->getBaseGrandTotal() || $order->canCreditmemo()) {
             if ($order->getState() !== Order::STATE_COMPLETE) {
                 $order->setState(Order::STATE_COMPLETE)->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_COMPLETE));
             }
         } elseif (floatval($order->getTotalRefunded()) || !$order->getTotalRefunded() && $order->hasForcedCanCreditmemo()) {
             if ($order->getState() !== Order::STATE_CLOSED) {
                 $order->setState(Order::STATE_CLOSED)->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_CLOSED));
             }
         }
     }
     if ($order->getState() == Order::STATE_NEW && $order->getIsInProcess()) {
         $order->setState(Order::STATE_PROCESSING)->setStatus($order->getConfig()->getStateDefaultStatus(Order::STATE_PROCESSING));
     }
     return $this;
 }
Example #10
0
 /**
  * Instantiate
  *
  * @return void
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _initCheckout()
 {
     $pre = __METHOD__ . " : ";
     $this->_logger->debug($pre . 'bof');
     $this->_order = $this->_checkoutSession->getLastRealOrder();
     if (!$this->_order->getId()) {
         $this->getResponse()->setStatusHeader(404, '1.1', 'Not found');
         throw new \Magento\Framework\Exception\LocalizedException(__('We could not find "Order" for processing'));
     }
     if ($this->_order->getState() != \Magento\Sales\Model\Order::STATE_PENDING_PAYMENT) {
         $this->_order->setState(\Magento\Sales\Model\Order::STATE_PENDING_PAYMENT)->save();
     }
     if ($this->_order->getQuoteId()) {
         $this->_checkoutSession->setPayfastQuoteId($this->_checkoutSession->getQuoteId());
         $this->_checkoutSession->setPayfastSuccessQuoteId($this->_checkoutSession->getLastSuccessQuoteId());
         $this->_checkoutSession->setPayfastRealOrderId($this->_checkoutSession->getLastRealOrderId());
         $this->_checkoutSession->getQuote()->setIsActive(false)->save();
         //$this->_checkoutSession->clear();
     }
     $this->_logger->debug($pre . 'eof');
     //$this->_checkout = $this->_checkoutTypes[$this->_checkoutType];
 }
Example #11
0
 /**
  * Check order status before save
  *
  * @param Order $order
  * @return $this
  */
 public function check(Order $order)
 {
     if (!$order->getId()) {
         return $order;
     }
     $userNotification = $order->hasCustomerNoteNotify() ? $order->getCustomerNoteNotify() : null;
     if (!$order->isCanceled() && !$order->canUnhold() && !$order->canInvoice() && !$order->canShip()) {
         if (0 == $order->getBaseGrandTotal() || $order->canCreditmemo()) {
             if ($order->getState() !== Order::STATE_COMPLETE) {
                 $order->setState(Order::STATE_COMPLETE, true, '', $userNotification, false);
             }
         } elseif (floatval($order->getTotalRefunded()) || !$order->getTotalRefunded() && $order->hasForcedCanCreditmemo()) {
             if ($order->getState() !== Order::STATE_CLOSED) {
                 $order->setState(Order::STATE_CLOSED, true, '', $userNotification, false);
             }
         }
     }
     if ($order->getState() == Order::STATE_NEW && $order->getIsInProcess()) {
         $order->setState(Order::STATE_PROCESSING, true, '', $userNotification);
     }
     return $this;
 }
Example #12
0
 /**
  * Initialize creation data from existing order
  *
  * @param \Magento\Sales\Model\Order $order
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function initFromOrder(\Magento\Sales\Model\Order $order)
 {
     $session = $this->getSession();
     $session->setData($order->getReordered() ? 'reordered' : 'order_id', $order->getId());
     $session->setCurrencyId($order->getOrderCurrencyCode());
     /* Check if we edit guest order */
     $session->setCustomerId($order->getCustomerId() ?: false);
     $session->setStoreId($order->getStoreId());
     /* Initialize catalog rule data with new session values */
     $this->initRuleData();
     foreach ($order->getItemsCollection($this->_salesConfig->getAvailableProductTypes(), true) as $orderItem) {
         /* @var $orderItem \Magento\Sales\Model\Order\Item */
         if (!$orderItem->getParentItem()) {
             $qty = $orderItem->getQtyOrdered();
             if (!$order->getReordered()) {
                 $qty -= max($orderItem->getQtyShipped(), $orderItem->getQtyInvoiced());
             }
             if ($qty > 0) {
                 $item = $this->initFromOrderItem($orderItem, $qty);
                 if (is_string($item)) {
                     throw new \Magento\Framework\Exception\LocalizedException(__($item));
                 }
             }
         }
     }
     $shippingAddress = $order->getShippingAddress();
     if ($shippingAddress) {
         $addressDiff = array_diff_assoc($shippingAddress->getData(), $order->getBillingAddress()->getData());
         unset($addressDiff['address_type'], $addressDiff['entity_id']);
         $shippingAddress->setSameAsBilling(empty($addressDiff));
     }
     $this->_initBillingAddressFromOrder($order);
     $this->_initShippingAddressFromOrder($order);
     $quote = $this->getQuote();
     if (!$quote->isVirtual() && $this->getShippingAddress()->getSameAsBilling()) {
         $this->setShippingAsBilling(1);
     }
     $this->setShippingMethod($order->getShippingMethod());
     $quote->getShippingAddress()->setShippingDescription($order->getShippingDescription());
     $paymentData = $order->getPayment()->getData();
     unset($paymentData['cc_type'], $paymentData['cc_last_4']);
     unset($paymentData['cc_exp_month'], $paymentData['cc_exp_year']);
     $quote->getPayment()->addData($paymentData);
     $orderCouponCode = $order->getCouponCode();
     if ($orderCouponCode) {
         $quote->setCouponCode($orderCouponCode);
     }
     if ($quote->getCouponCode()) {
         $quote->collectTotals();
     }
     $this->_objectCopyService->copyFieldsetToTarget('sales_copy_order', 'to_edit', $order, $quote);
     $this->_eventManager->dispatch('sales_convert_order_to_quote', ['order' => $order, 'quote' => $quote]);
     if (!$order->getCustomerId()) {
         $quote->setCustomerIsGuest(true);
     }
     if ($session->getUseOldShippingMethod(true)) {
         /*
          * if we are making reorder or editing old order
          * we need to show old shipping as preselected
          * so for this we need to collect shipping rates
          */
         $this->collectShippingRates();
     } else {
         /*
          * if we are creating new order then we don't need to collect
          * shipping rates before customer hit appropriate button
          */
         $this->collectRates();
     }
     $this->quoteRepository->save($quote);
     return $this;
 }
Example #13
0
 /**
  * Process items dependency for new order, returns qty of affected items;
  *
  * @param \Magento\Sales\Model\Order $object
  * @return int
  */
 protected function calculateItems(\Magento\Sales\Model\Order $object)
 {
     $itemsCount = 0;
     if (!$object->getId()) {
         foreach ($object->getAllItems() as $item) {
             /** @var  \Magento\Sales\Model\Order\Item $item */
             $parent = $item->getQuoteParentItemId();
             if ($parent && !$item->getParentItem()) {
                 $item->setParentItem($object->getItemByQuoteItemId($parent));
             }
             $childItems = $item->getChildrenItems();
             if (empty($childItems)) {
                 $itemsCount++;
             }
         }
     }
     return $itemsCount;
 }
Example #14
0
 /**
  * Declare order for invoice
  *
  * @param \Magento\Sales\Model\Order $order
  * @return $this
  */
 public function setOrder(\Magento\Sales\Model\Order $order)
 {
     $this->_order = $order;
     $this->setOrderId($order->getId())->setStoreId($order->getStoreId());
     return $this;
 }
Example #15
0
 /**
  * Set order instance for transaction depends on transaction behavior
  * If $order equals to true, method isn't loading new order instance.
  *
  * @param \Magento\Sales\Model\Order|null|boolean $order
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function setOrder($order = null)
 {
     if (null === $order || $order === true) {
         if (null !== $this->_paymentObject && $this->_paymentObject->getOrder()) {
             $this->_order = $this->_paymentObject->getOrder();
         } elseif ($this->getOrderId() && $order === null) {
             $this->_order = $this->_orderFactory->create()->load($this->getOrderId());
         } else {
             $this->_order = false;
         }
     } elseif (!$this->getId() || $this->getOrderId() == $order->getId()) {
         $this->_order = $order;
     } else {
         throw new \Magento\Framework\Exception\LocalizedException(__('Set order for existing transactions not allowed'));
     }
     return $this;
 }
Example #16
0
 /**
  * Retrieve the Url for a specified sales order row.
  *
  * @param \Magento\Sales\Model\Order|\Magento\Framework\Object $row
  * @return string
  */
 public function getRowUrl($row)
 {
     return $this->getUrl('sales/order/view', array('order_id' => $row->getId()));
 }
Example #17
0
 /**
  * Update all child and parent order's edit increment numbers.
  * Needed for Admin area.
  *
  * @param \Magento\Sales\Model\Order $order
  * @return void
  */
 public function updateOrderEditIncrements(\Magento\Sales\Model\Order $order)
 {
     if ($order->getId() && $order->getOriginalIncrementId()) {
         $collection = $order->getCollection();
         $quotedIncrId = $collection->getConnection()->quote($order->getOriginalIncrementId());
         $collection->getSelect()->where("original_increment_id = {$quotedIncrId} OR increment_id = {$quotedIncrId}");
         foreach ($collection as $orderToUpdate) {
             $orderToUpdate->setEditIncrement($order->getEditIncrement());
             $orderToUpdate->save();
         }
     }
 }
Example #18
0
 /**
  * Get calculated taxes for each tax class
  *
  * This method returns array with format:
  * array(
  *  $index => array(
  *      'tax_amount'        => $taxAmount,
  *      'base_tax_amount'   => $baseTaxAmount,
  *      'hidden_tax_amount' => $hiddenTaxAmount,
  *      'title'             => $title,
  *      'percent'           => $percent
  *  )
  * )
  *
  * @param \Magento\Sales\Model\Order $source
  * @return array
  */
 public function getCalculatedTaxes($source)
 {
     if ($this->_coreRegistry->registry('current_invoice')) {
         $current = $this->_coreRegistry->registry('current_invoice');
     } elseif ($this->_coreRegistry->registry('current_creditmemo')) {
         $current = $this->_coreRegistry->registry('current_creditmemo');
     } else {
         $current = $source;
     }
     $taxClassAmount = array();
     if ($current && $source) {
         if ($current == $source) {
             $orderTaxDetails = $this->orderTaxService->getOrderTaxDetails($current->getId());
             $appliedTaxes = $orderTaxDetails->getAppliedTaxes();
             foreach ($appliedTaxes as $appliedTax) {
                 $taxCode = $appliedTax->getCode();
                 $taxClassAmount[$taxCode]['tax_amount'] = $appliedTax->getAmount();
                 $taxClassAmount[$taxCode]['base_tax_amount'] = $appliedTax->getBaseAmount();
                 $taxClassAmount[$taxCode]['title'] = $appliedTax->getTitle();
                 $taxClassAmount[$taxCode]['percent'] = $appliedTax->getPercent();
             }
         } else {
             $orderTaxDetails = $this->orderTaxService->getOrderTaxDetails($source->getId());
             // Calculate taxes for shipping
             $shippingTaxAmount = $current->getShippingTaxAmount();
             if ($shippingTaxAmount) {
                 $shippingTax = $this->getShippingTax($current);
                 $taxClassAmount = array_merge($taxClassAmount, $shippingTax);
             }
             /** @var $item \Magento\Sales\Model\Order\Invoice\Item|\Magento\Sales\Model\Order\Creditmemo\Item */
             foreach ($current->getItemsCollection() as $item) {
                 $orderItem = $item->getOrderItem();
                 $orderItemId = $orderItem->getId();
                 $orderItemTax = $orderItem->getTaxAmount();
                 $itemTax = $item->getTaxAmount();
                 if (!$itemTax || !$orderItemTax) {
                     continue;
                 }
                 //In the case that invoiced item or creditmemo item qty is different from order item qty
                 $ratio = $itemTax / $orderItemTax;
                 $itemTaxDetails = $orderTaxDetails->getItems();
                 foreach ($itemTaxDetails as $itemTaxDetail) {
                     //Aggregate taxable items associated with an item
                     if ($itemTaxDetail->getItemId() == $orderItemId || $itemTaxDetail->getAssociatedItemId() == $orderItemId) {
                         $itemAppliedTaxes = $itemTaxDetail->getAppliedTaxes();
                         foreach ($itemAppliedTaxes as $itemAppliedTax) {
                             $taxCode = $itemAppliedTax->getCode();
                             if (!isset($taxClassAmount[$taxCode])) {
                                 $taxClassAmount[$taxCode]['title'] = $itemAppliedTax->getTitle();
                                 $taxClassAmount[$taxCode]['percent'] = $itemAppliedTax->getPercent();
                                 $taxClassAmount[$taxCode]['tax_amount'] = $itemAppliedTax->getAmount() * $ratio;
                                 $taxClassAmount[$taxCode]['base_tax_amount'] = $itemAppliedTax->getBaseAmount() * $ratio;
                             } else {
                                 $taxClassAmount[$taxCode]['tax_amount'] += $itemAppliedTax->getAmount() * $ratio;
                                 $taxClassAmount[$taxCode]['base_tax_amount'] += $itemAppliedTax->getBaseAmount() * $ratio;
                             }
                         }
                     }
                 }
             }
         }
         foreach ($taxClassAmount as $key => $tax) {
             if ($tax['tax_amount'] == 0 && $tax['base_tax_amount'] == 0) {
                 unset($taxClassAmount[$key]);
             } else {
                 $taxClassAmount[$key]['tax_amount'] = $source->getStore()->roundPrice($tax['tax_amount']);
                 $taxClassAmount[$key]['base_tax_amount'] = $source->getStore()->roundPrice($tax['base_tax_amount']);
             }
         }
         $taxClassAmount = array_values($taxClassAmount);
     }
     return $taxClassAmount;
 }
Example #19
0
 /**
  * Get calculated taxes for each tax class
  *
  * This method returns array with format:
  * array(
  *  $index => array(
  *      'tax_amount'        => $taxAmount,
  *      'base_tax_amount'   => $baseTaxAmount,
  *      'title'             => $title,
  *      'percent'           => $percent
  *  )
  * )
  *
  * @param \Magento\Sales\Model\Order $source
  * @return array
  */
 public function getCalculatedTaxes($source)
 {
     if ($this->_coreRegistry->registry('current_invoice')) {
         $current = $this->_coreRegistry->registry('current_invoice');
     } elseif ($this->_coreRegistry->registry('current_creditmemo')) {
         $current = $this->_coreRegistry->registry('current_creditmemo');
     } else {
         $current = $source;
     }
     $taxClassAmount = array();
     if ($current && $source) {
         if ($current == $source) {
             $orderTaxDetails = $this->orderTaxService->getOrderTaxDetails($current->getId());
             $appliedTaxes = $orderTaxDetails->getAppliedTaxes();
             foreach ($appliedTaxes as $appliedTax) {
                 $taxCode = $appliedTax->getCode();
                 $taxClassAmount[$taxCode]['tax_amount'] = $appliedTax->getAmount();
                 $taxClassAmount[$taxCode]['base_tax_amount'] = $appliedTax->getBaseAmount();
                 $taxClassAmount[$taxCode]['title'] = $appliedTax->getTitle();
                 $taxClassAmount[$taxCode]['percent'] = $appliedTax->getPercent();
             }
         } else {
             $orderTaxDetails = $this->orderTaxService->getOrderTaxDetails($source->getId());
             // Apply any taxes for shipping
             $shippingTaxAmount = $current->getShippingTaxAmount();
             $originalShippingTaxAmount = $source->getShippingTaxAmount();
             if ($shippingTaxAmount && $originalShippingTaxAmount && $shippingTaxAmount != 0 && $originalShippingTaxAmount != 0) {
                 //An invoice or credit memo can have a different qty than its order
                 $shippingRatio = $shippingTaxAmount / $originalShippingTaxAmount;
                 $itemTaxDetails = $orderTaxDetails->getItems();
                 foreach ($itemTaxDetails as $itemTaxDetail) {
                     //Aggregate taxable items associated with shipping
                     if ($itemTaxDetail->getType() == \Magento\Sales\Model\Quote\Address::TYPE_SHIPPING) {
                         $taxClassAmount = $this->_aggregateTaxes($taxClassAmount, $itemTaxDetail, $shippingRatio);
                     }
                 }
             }
             // Apply any taxes for the items
             /** @var $item \Magento\Sales\Model\Order\Invoice\Item|\Magento\Sales\Model\Order\Creditmemo\Item */
             foreach ($current->getItemsCollection() as $item) {
                 $orderItem = $item->getOrderItem();
                 $orderItemId = $orderItem->getId();
                 $orderItemTax = $orderItem->getTaxAmount();
                 $itemTax = $item->getTaxAmount();
                 if (!$itemTax || !$orderItemTax) {
                     continue;
                 }
                 //An invoiced item or credit memo item can have a different qty than its order item qty
                 $itemRatio = $itemTax / $orderItemTax;
                 $itemTaxDetails = $orderTaxDetails->getItems();
                 foreach ($itemTaxDetails as $itemTaxDetail) {
                     //Aggregate taxable items associated with an item
                     if ($itemTaxDetail->getItemId() == $orderItemId || $itemTaxDetail->getAssociatedItemId() == $orderItemId) {
                         $taxClassAmount = $this->_aggregateTaxes($taxClassAmount, $itemTaxDetail, $itemRatio);
                     }
                 }
             }
         }
         // Finish
         foreach ($taxClassAmount as $key => $tax) {
             if ($tax['tax_amount'] == 0 && $tax['base_tax_amount'] == 0) {
                 unset($taxClassAmount[$key]);
             } else {
                 $taxClassAmount[$key]['tax_amount'] = $this->priceCurrency->round($tax['tax_amount']);
                 $taxClassAmount[$key]['base_tax_amount'] = $this->priceCurrency->round($tax['base_tax_amount']);
             }
         }
         $taxClassAmount = array_values($taxClassAmount);
     }
     return $taxClassAmount;
 }
Example #20
0
 /**
  * Loads the order info from a Magento order model.
  *
  * @param Order $order the order model.
  * @return \NostoOrder
  */
 public function build(Order $order)
 {
     $nostoOrder = new \NostoOrder();
     try {
         $nostoCurrency = new NostoCurrencyCode($order->getOrderCurrencyCode());
         $nostoOrder->setOrderNumber($order->getId());
         $nostoOrder->setExternalRef($order->getRealOrderId());
         $nostoOrder->setCreatedDate(new NostoDate(strtotime($order->getCreatedAt())));
         $nostoOrder->setPaymentProvider(new NostoOrderPaymentProvider($order->getPayment()->getMethod()));
         if ($order->getStatus()) {
             $nostoStatus = new NostoOrderStatus();
             $nostoStatus->setCode($order->getStatus());
             $nostoStatus->setLabel($order->getStatusLabel());
             $nostoOrder->setStatus($nostoStatus);
         }
         foreach ($order->getAllStatusHistory() as $item) {
             if ($item->getStatus()) {
                 $nostoStatus = new NostoOrderStatus();
                 $nostoStatus->setCode($item->getStatus());
                 $nostoStatus->setLabel($item->getStatusLabel());
                 $nostoStatus->setCreatedAt(new NostoDate(strtotime($item->getCreatedAt())));
                 $nostoOrder->addHistoryStatus($nostoStatus);
             }
         }
         // Set the buyer information
         $nostoBuyer = new NostoOrderBuyer();
         $nostoBuyer->setFirstName($order->getCustomerFirstname());
         $nostoBuyer->setLastName($order->getCustomerLastname());
         $nostoBuyer->setEmail($order->getCustomerEmail());
         $nostoOrder->setBuyer($nostoBuyer);
         // Add each ordered item as a line item
         /** @var Item $item */
         foreach ($order->getAllVisibleItems() as $item) {
             $nostoItem = new NostoOrderItem();
             $nostoItem->setItemId((int) $this->buildItemProductId($item));
             $nostoItem->setQuantity((int) $item->getQtyOrdered());
             $nostoItem->setName($this->buildItemName($item));
             try {
                 $nostoItem->setUnitPrice(new NostoPrice($this->_priceHelper->getItemFinalPriceInclTax($item)));
             } catch (\NostoInvalidArgumentException $E) {
                 $nostoItem->setUnitPrice(new NostoPrice(0));
             }
             $nostoItem->setCurrency($nostoCurrency);
             $nostoOrder->addItem($nostoItem);
         }
         // Add discounts as a pseudo line item
         if (($discount = $order->getDiscountAmount()) < 0) {
             $nostoItem = new NostoOrderItem();
             $nostoItem->setItemId(-1);
             $nostoItem->setQuantity(1);
             $nostoItem->setName($this->buildDiscountRuleDescription($order));
             $nostoItem->setUnitPrice(new NostoPrice($discount));
             $nostoItem->setCurrency($nostoCurrency);
             $nostoOrder->addItem($nostoItem);
         }
         // Add shipping and handling as a pseudo line item
         if (($shippingInclTax = $order->getShippingInclTax()) > 0) {
             $nostoItem = new NostoOrderItem();
             $nostoItem->setItemId(-1);
             $nostoItem->setQuantity(1);
             $nostoItem->setName('Shipping and handling');
             $nostoItem->setUnitPrice(new NostoPrice($shippingInclTax));
             $nostoItem->setCurrency($nostoCurrency);
             $nostoOrder->addItem($nostoItem);
         }
     } catch (Exception $e) {
         $this->_logger->error($e, ['exception' => $e]);
     }
     return $nostoOrder;
 }
Example #21
0
 /**
  * Converting order object to quote object
  *
  * @param \Magento\Sales\Model\Order $order
  * @param null|\Magento\Sales\Model\Quote $quote
  * @return \Magento\Sales\Model\Quote
  */
 public function toQuote(\Magento\Sales\Model\Order $order, $quote = null)
 {
     if (!$quote instanceof \Magento\Sales\Model\Quote) {
         $quote = $this->_quoteFactory->create();
     }
     $quote->setStoreId($order->getStoreId())->setOrderId($order->getId());
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_order', 'to_quote', $order, $quote);
     $this->_eventManager->dispatch('sales_convert_order_to_quote', array('order' => $order, 'quote' => $quote));
     return $quote;
 }
Example #22
0
 /**
  * Retrieve order item value by key
  *
  * @param \Magento\Sales\Model\Order $order
  * @param string $key
  * @return string
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 public function getOrderItemValue(\Magento\Sales\Model\Order $order, $key)
 {
     $escape = true;
     switch ($key) {
         case 'order_increment_id':
             $value = $order->getIncrementId();
             break;
         case 'created_at':
             $value = $this->formatDate($order->getCreatedAt(), \IntlDateFormatter::SHORT, true);
             break;
         case 'shipping_address':
             $value = $order->getShippingAddress() ? $this->escapeHtml($order->getShippingAddress()->getName()) : __('N/A');
             break;
         case 'order_total':
             $value = $order->formatPrice($order->getGrandTotal());
             $escape = false;
             break;
         case 'status_label':
             $value = $order->getStatusLabel();
             break;
         case 'view_url':
             $value = $this->getUrl('sales/order/view', ['order_id' => $order->getId()]);
             break;
         default:
             $value = $order->getData($key) ? $order->getData($key) : __('N/A');
             break;
     }
     return $escape ? $this->escapeHtml($value) : $value;
 }
 /**
  * Load by order
  *
  * @param \Magento\Sales\Model\Order $order
  * @return $this
  */
 public function loadByOrder($order)
 {
     $orderId = $order->getId();
     $this->getSelect()->where('main_table.order_id = ?', $orderId)->order('process');
     return $this->load();
 }
Example #24
0
 /**
  * @param \Magento\Sales\Model\Order $order
  * @return bool
  */
 public function validateNoTransactions(\Magento\Sales\Model\Order $order)
 {
     return $this->transactionResource->getLastPayuplOrderIdByOrderId($order->getId()) === false;
 }
Example #25
0
 /**
  * Add order details to payment request
  * @param DataObject $request
  * @param Order $order
  * @return void
  */
 public function addRequestOrderInfo(DataObject $request, Order $order)
 {
     $id = $order->getId();
     // for auth request order id is not exists yet
     if (!empty($id)) {
         $request->setPonum($id);
     }
     $orderIncrementId = $order->getIncrementId();
     $request->setCustref($orderIncrementId)->setInvnum($orderIncrementId)->setComment1($orderIncrementId);
 }
Example #26
0
 /**
  * Set order instance for transaction depends on transaction behavior
  * If $order equals to true, method isn't loading new order instance.
  *
  * @param \Magento\Sales\Model\Order|null|boolean $order
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function setOrder($order = null)
 {
     if (null === $order || $order === true) {
         if ($this->getOrderId()) {
             $this->_order = $this->orderRepository->get($this->getOrderId());
         } else {
             $this->_order = false;
         }
     } elseif (!$this->getId() || $this->getOrderId() == $order->getId()) {
         $this->_order = $order;
     } else {
         throw new \Magento\Framework\Exception\LocalizedException(__('Set order for existing transactions not allowed'));
     }
     return $this;
 }
Example #27
0
 /**
  * Get data for Header esction of RSS feed
  *
  * @return array
  */
 protected function getHeader()
 {
     $title = __('Order # %1 Notification(s)', $this->order->getIncrementId());
     $newUrl = $this->urlBuilder->getUrl('sales/order/view', ['order_id' => $this->order->getId()]);
     return ['title' => $title, 'description' => $title, 'link' => $newUrl, 'charset' => 'UTF-8'];
 }
Example #28
0
 /**
  * Get url for reorder action
  *
  * @param \Magento\Sales\Model\Order $order
  * @return string
  */
 public function getReorderUrl($order)
 {
     if (!$this->httpContext->getValue(\Magento\Customer\Helper\Data::CONTEXT_AUTH)) {
         return $this->getUrl('sales/guest/reorder', array('order_id' => $order->getId()));
     }
     return $this->getUrl('sales/order/reorder', array('order_id' => $order->getId()));
 }
 /**
  * Check if creditmeno can be created for order
  * @param \Magento\Sales\Model\Order $order
  * @return bool
  */
 protected function _canCreditmemo($order)
 {
     /**
      * Check order existing
      */
     if (!$order->getId()) {
         $this->messageManager->addError(__('The order no longer exists.'));
         return false;
     }
     /**
      * Check creditmemo create availability
      */
     if (!$order->canCreditmemo()) {
         $this->messageManager->addError(__('We can\'t create credit memo for the order.'));
         return false;
     }
     return true;
 }
Example #30
0
 /**
  * @param \Magento\Sales\Model\Order $order
  * @return array
  */
 protected function getNonEditableTypes($order)
 {
     return array_keys($this->getOrder()->getResource()->aggregateProductsByTypes($order->getId(), $this->_salesConfig->getAvailableProductTypes(), false));
 }