/** * Get RSS feed items * * @return array */ protected function getEntries() { /** @var $resourceModel \Magento\Sales\Model\Resource\Order\Rss\OrderStatus */ $resourceModel = $this->orderResourceFactory->create(); $results = $resourceModel->getAllCommentCollection($this->order->getId()); $entries = []; if ($results) { foreach ($results as $result) { $urlAppend = 'view'; $type = $result['entity_type_code']; if ($type && $type != 'order') { $urlAppend = $type; } $type = __(ucwords($type)); $title = __('Details for %1 #%2', $type, $result['increment_id']); $description = '<p>' . __('Notified Date: %1', $this->localeDate->formatDate($result['created_at'])) . '<br/>' . __('Comment: %1<br/>', $result['comment']) . '</p>'; $url = $this->urlBuilder->getUrl('sales/order/' . $urlAppend, ['order_id' => $this->order->getId()]); $entries[] = ['title' => $title, 'link' => $url, 'description' => $description]; } } $title = __('Order #%1 created at %2', $this->order->getIncrementId(), $this->localeDate->formatDate($this->order->getCreatedAt())); $url = $this->urlBuilder->getUrl('sales/order/view', ['order_id' => $this->order->getId()]); $description = '<p>' . __('Current Status: %1<br/>', $this->order->getStatusLabel()) . __('Total: %1<br/>', $this->order->formatPrice($this->order->getGrandTotal())) . '</p>'; $entries[] = ['title' => $title, 'link' => $url, 'description' => $description]; return ['entries' => $entries]; }
/** * @param $order Order * @return Purchase */ protected function makePurchase(Order $order) { // Get all of the purchased products $items = $order->getAllItems(); $purchase = SignifydModel::Make("\\Signifyd\\Models\\Purchase"); $purchase->orderChannel = "WEB"; $purchase->products = array(); foreach ($items as $item) { $purchase->products[] = $this->makeProduct($item); } $purchase->totalPrice = $order->getGrandTotal(); $purchase->currency = $order->getOrderCurrencyCode(); $purchase->orderId = $order->getIncrementId(); $purchase->paymentGateway = $order->getPayment()->getMethod(); $purchase->shippingPrice = floatval($order->getShippingAmount()); $purchase->avsResponseCode = $order->getPayment()->getCcAvsStatus(); $purchase->cvvResponseCode = $order->getPayment()->getCcSecureVerify(); $purchase->createdAt = date('c', strtotime($order->getCreatedAt())); $purchase->browserIpAddress = $this->getIPAddress($order); return $purchase; }
/** * 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; }
/** * 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; }