当前位置: 首页>>代码示例>>PHP>>正文


PHP Order::getItemsCollection方法代码示例

本文整理汇总了PHP中Magento\Sales\Model\Order::getItemsCollection方法的典型用法代码示例。如果您正苦于以下问题:PHP Order::getItemsCollection方法的具体用法?PHP Order::getItemsCollection怎么用?PHP Order::getItemsCollection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Magento\Sales\Model\Order的用法示例。


在下文中一共展示了Order::getItemsCollection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getItems

 /**
  * Returns array of items
  *
  * @param \Magento\Sales\Model\Order $object
  * @return OrderItem[]
  */
 protected function getItems(\Magento\Sales\Model\Order $object)
 {
     $items = [];
     foreach ($object->getItemsCollection() as $item) {
         $items[] = $this->orderItemMapper->extractDto($item);
     }
     return $items;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:OrderMapper.php

示例2: initFromOrder

 /**
  * 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;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:81,代码来源:Create.php

示例3: getOrderItemForTransaction

 /**
  * @param \Magento\Sales\Model\Order $order
  * @return mixed
  */
 protected function getOrderItemForTransaction(\Magento\Sales\Model\Order $order)
 {
     $order->getItemByQuoteItemId($order->getQuoteId());
     foreach ($order->getItemsCollection() as $item) {
         if (!$item->isDeleted() && !$item->getParentItemId()) {
             return $item;
         }
     }
     return null;
 }
开发者ID:vinai-drive-by-commits,项目名称:magento2-sample-data,代码行数:14,代码来源:Processor.php

示例4: _getReceiptOrderLines

 /**
  * @param \Magento\Sales\Model\Order $order
  * @return string
  */
 protected function _getReceiptOrderLines(\Magento\Sales\Model\Order $order)
 {
     $myReceiptOrderLines = "";
     $currency = $order->getOrderCurrencyCode();
     $formattedAmountValue = $this->_currencyFactory->create()->format($order->getGrandTotal(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
     $taxAmount = $order->getTaxAmount();
     $formattedTaxAmount = $this->_currencyFactory->create()->format($taxAmount, ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
     $myReceiptOrderLines .= "---||C\n" . "====== YOUR ORDER DETAILS ======||CB\n" . "---||C\n" . " No. Description |Piece  Subtotal|\n";
     foreach ($order->getItemsCollection() as $item) {
         //skip dummies
         if ($item->isDummy()) {
             continue;
         }
         $singlePriceFormat = $this->_currencyFactory->create()->format($item->getPriceInclTax(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
         $itemAmount = $item->getPriceInclTax() * (int) $item->getQtyOrdered();
         $itemAmountFormat = $this->_currencyFactory->create()->format($itemAmount, ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
         $myReceiptOrderLines .= "  " . (int) $item->getQtyOrdered() . "  " . trim(substr($item->getName(), 0, 25)) . "| " . $currency . " " . $singlePriceFormat . "  " . $currency . " " . $itemAmountFormat . "|\n";
     }
     //discount cost
     if ($order->getDiscountAmount() > 0 || $order->getDiscountAmount() < 0) {
         $discountAmountFormat = $this->_currencyFactory->create()->format($order->getDiscountAmount(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
         $myReceiptOrderLines .= "  " . 1 . " " . $this->__('Total Discount') . "| " . $currency . " " . $discountAmountFormat . "|\n";
     }
     //shipping cost
     if ($order->getShippingAmount() > 0 || $order->getShippingTaxAmount() > 0) {
         $shippingAmountFormat = $this->_currencyFactory->create()->format($order->getShippingAmount(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
         $myReceiptOrderLines .= "  " . 1 . " " . $order->getShippingDescription() . "| " . $currency . " " . $shippingAmountFormat . "|\n";
     }
     if ($order->getPaymentFeeAmount() > 0) {
         $paymentFeeAmount = $this->_currencyFactory->create()->format($order->getPaymentFeeAmount(), ['display' => \Magento\Framework\Currency::NO_SYMBOL], false);
         $myReceiptOrderLines .= "  " . 1 . " " . $this->__('Payment Fee') . "| " . $currency . " " . $paymentFeeAmount . "|\n";
     }
     $myReceiptOrderLines .= "|--------|\n" . "|Order Total:  " . $currency . " " . $formattedAmountValue . "|B\n" . "|Tax:  " . $currency . " " . $formattedTaxAmount . "|B\n" . "||C\n";
     /*
      * New header for card details section!
      * Default location is After Header so simply add to Order Details as separator
      */
     $myReceiptOrderLines .= "---||C\n" . "====== YOUR PAYMENT DETAILS ======||CB\n" . "---||C\n";
     return $myReceiptOrderLines;
 }
开发者ID:Adyen,项目名称:adyen-magento2,代码行数:44,代码来源:Pos.php


注:本文中的Magento\Sales\Model\Order::getItemsCollection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。