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


PHP Invoice::getOrder方法代码示例

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


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

示例1: collect

 /**
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $invoice->setShippingAmount(0);
     $invoice->setBaseShippingAmount(0);
     $orderShippingAmount = $invoice->getOrder()->getShippingAmount();
     $baseOrderShippingAmount = $invoice->getOrder()->getBaseShippingAmount();
     $shippingInclTax = $invoice->getOrder()->getShippingInclTax();
     $baseShippingInclTax = $invoice->getOrder()->getBaseShippingInclTax();
     if ($orderShippingAmount) {
         /**
          * Check shipping amount in previous invoices
          */
         foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
             if ((double) $previousInvoice->getShippingAmount() && !$previousInvoice->isCanceled()) {
                 return $this;
             }
         }
         $invoice->setShippingAmount($orderShippingAmount);
         $invoice->setBaseShippingAmount($baseOrderShippingAmount);
         $invoice->setShippingInclTax($shippingInclTax);
         $invoice->setBaseShippingInclTax($baseShippingInclTax);
         $invoice->setGrandTotal($invoice->getGrandTotal() + $orderShippingAmount);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseOrderShippingAmount);
     }
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:30,代码来源:Shipping.php

示例2: testGetOrder

 public function testGetOrder()
 {
     $orderId = 100000041;
     $this->model->setOrderId($orderId);
     $entityName = 'invoice';
     $this->orderMock->expects($this->atLeastOnce())->method('setHistoryEntityName')->with($entityName)->will($this->returnSelf());
     $this->assertEquals($this->orderMock, $this->model->getOrder());
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:8,代码来源:InvoiceTest.php

示例3: collect

 /**
  * Collect invoice subtotal
  *
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $subtotal = 0;
     $baseSubtotal = 0;
     $subtotalInclTax = 0;
     $baseSubtotalInclTax = 0;
     $order = $invoice->getOrder();
     foreach ($invoice->getAllItems() as $item) {
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $item->calcRowTotal();
         $subtotal += $item->getRowTotal();
         $baseSubtotal += $item->getBaseRowTotal();
         $subtotalInclTax += $item->getRowTotalInclTax();
         $baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
     }
     $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced();
     $baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced();
     $allowedSubtotalInclTax = $allowedSubtotal + $order->getHiddenTaxAmount() + $order->getTaxAmount() - $order->getTaxInvoiced() - $order->getHiddenTaxInvoiced();
     $baseAllowedSubtotalInclTax = $baseAllowedSubtotal + $order->getBaseHiddenTaxAmount() + $order->getBaseTaxAmount() - $order->getBaseTaxInvoiced() - $order->getBaseHiddenTaxInvoiced();
     /**
      * Check if shipping tax calculation is included to current invoice.
      */
     $includeShippingTax = true;
     foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
         if ($previousInvoice->getShippingAmount() && !$previousInvoice->isCanceled()) {
             $includeShippingTax = false;
             break;
         }
     }
     if ($includeShippingTax) {
         $allowedSubtotalInclTax -= $order->getShippingTaxAmount();
         $baseAllowedSubtotalInclTax -= $order->getBaseShippingTaxAmount();
     } else {
         $allowedSubtotalInclTax += $order->getShippingHiddenTaxAmount();
         $baseAllowedSubtotalInclTax += $order->getBaseShippingHiddenTaxAmount();
     }
     if ($invoice->isLast()) {
         $subtotal = $allowedSubtotal;
         $baseSubtotal = $baseAllowedSubtotal;
         $subtotalInclTax = $allowedSubtotalInclTax;
         $baseSubtotalInclTax = $baseAllowedSubtotalInclTax;
     } else {
         $subtotal = min($allowedSubtotal, $subtotal);
         $baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
         $subtotalInclTax = min($allowedSubtotalInclTax, $subtotalInclTax);
         $baseSubtotalInclTax = min($baseAllowedSubtotalInclTax, $baseSubtotalInclTax);
     }
     $invoice->setSubtotal($subtotal);
     $invoice->setBaseSubtotal($baseSubtotal);
     $invoice->setSubtotalInclTax($subtotalInclTax);
     $invoice->setBaseSubtotalInclTax($baseSubtotalInclTax);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $subtotal);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseSubtotal);
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:63,代码来源:Subtotal.php

示例4: collect

 /**
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $invoice->setDiscountAmount(0);
     $invoice->setBaseDiscountAmount(0);
     $totalDiscountAmount = 0;
     $baseTotalDiscountAmount = 0;
     /**
      * Checking if shipping discount was added in previous invoices.
      * So basically if we have invoice with positive discount and it
      * was not canceled we don't add shipping discount to this one.
      */
     $addShippingDiscount = true;
     foreach ($invoice->getOrder()->getInvoiceCollection() as $previousInvoice) {
         if ($previousInvoice->getDiscountAmount()) {
             $addShippingDiscount = false;
         }
     }
     if ($addShippingDiscount) {
         $totalDiscountAmount = $totalDiscountAmount + $invoice->getOrder()->getShippingDiscountAmount();
         $baseTotalDiscountAmount = $baseTotalDiscountAmount + $invoice->getOrder()->getBaseShippingDiscountAmount();
     }
     /** @var $item \Magento\Sales\Model\Order\Invoice\Item */
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         if ($orderItem->isDummy()) {
             continue;
         }
         $orderItemDiscount = (double) $orderItem->getDiscountAmount();
         $baseOrderItemDiscount = (double) $orderItem->getBaseDiscountAmount();
         $orderItemQty = $orderItem->getQtyOrdered();
         if ($orderItemDiscount && $orderItemQty) {
             /**
              * Resolve rounding problems
              */
             $discount = $orderItemDiscount - $orderItem->getDiscountInvoiced();
             $baseDiscount = $baseOrderItemDiscount - $orderItem->getBaseDiscountInvoiced();
             if (!$item->isLast()) {
                 $activeQty = $orderItemQty - $orderItem->getQtyInvoiced();
                 $discount = $invoice->roundPrice($discount / $activeQty * $item->getQty(), 'regular', true);
                 $baseDiscount = $invoice->roundPrice($baseDiscount / $activeQty * $item->getQty(), 'base', true);
             }
             $item->setDiscountAmount($discount);
             $item->setBaseDiscountAmount($baseDiscount);
             $totalDiscountAmount += $discount;
             $baseTotalDiscountAmount += $baseDiscount;
         }
     }
     $invoice->setDiscountAmount(-$totalDiscountAmount);
     $invoice->setBaseDiscountAmount(-$baseTotalDiscountAmount);
     $invoice->setGrandTotal($invoice->getGrandTotal() - $totalDiscountAmount);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() - $baseTotalDiscountAmount);
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:57,代码来源:Discount.php

示例5: collect

 /**
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $invoice->setFee(0);
     $invoice->setBaseFee(0);
     $amount = $invoice->getOrder()->getFee();
     $invoice->setFee($amount);
     $amount = $invoice->getOrder()->getBaseFee();
     $invoice->setBaseFee($amount);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $invoice->getFee());
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $invoice->getFee());
     return $this;
 }
开发者ID:sivajik34,项目名称:Custom-Fee-Magento2,代码行数:16,代码来源:Fee.php

示例6: send

 /**
  * Send email to customer
  *
  * @param Invoice $invoice
  * @param bool $notify
  * @param string $comment
  * @return bool
  */
 public function send(Invoice $invoice, $notify = true, $comment = '')
 {
     $order = $invoice->getOrder();
     $transport = ['order' => $order, 'invoice' => $invoice, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order)];
     $this->eventManager->dispatch('email_invoice_comment_set_template_vars_before', ['sender' => $this, 'transport' => $transport]);
     $this->templateContainer->setTemplateVars($transport);
     return $this->checkAndSend($order, $notify);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:InvoiceCommentSender.php

示例7: _prepareShipment

 /**
  * Prepare shipment
  *
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return \Magento\Sales\Model\Order\Shipment|false
  */
 protected function _prepareShipment($invoice)
 {
     $invoiceData = $this->getRequest()->getParam('invoice');
     $shipment = $this->shipmentFactory->create($invoice->getOrder(), isset($invoiceData['items']) ? $invoiceData['items'] : [], $this->getRequest()->getPost('tracking'));
     if (!$shipment->getTotalQty()) {
         return false;
     }
     return $shipment->register();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Save.php

示例8: send

 /**
  * Send email to customer
  *
  * @param Invoice $invoice
  * @param bool $notify
  * @param string $comment
  * @return bool
  */
 public function send(Invoice $invoice, $notify = true, $comment = '')
 {
     $order = $invoice->getOrder();
     $this->templateContainer->setTemplateVars(['order' => $order, 'invoice' => $invoice, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore()]);
     $result = $this->checkAndSend($order, $notify);
     if ($result) {
         $invoice->setEmailSent(true);
         $this->invoiceResource->saveAttribute($invoice, 'email_sent');
     }
     return $result;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:19,代码来源:InvoiceSender.php

示例9: collect

 /**
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  *
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $order = $invoice->getOrder();
     $amount = $order->getFinanceCostAmount();
     $baseAmount = $order->getBaseFinanceCostAmount();
     if ($amount) {
         $invoice->setFinanceCostAmount($amount);
         $invoice->setBaseFinanceCostAmount($baseAmount);
         $invoice->setGrandTotal($invoice->getGrandTotal() + $amount);
         $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseAmount);
     }
     return $this;
 }
开发者ID:SummaSolutions,项目名称:cart-magento2,代码行数:18,代码来源:FinanceCost.php

示例10: testSetOrder

 public function testSetOrder()
 {
     $orderId = 1111;
     $storeId = 2221;
     $this->orderMock->setId($orderId);
     $this->orderMock->setStoreId($storeId);
     $this->assertNull($this->model->getOrderId());
     $this->assertNull($this->model->getStoreId());
     $this->assertEquals($this->model, $this->model->setOrder($this->orderMock));
     $this->assertEquals($this->orderMock, $this->model->getOrder());
     $this->assertEquals($orderId, $this->model->getOrderId());
     $this->assertEquals($storeId, $this->model->getStoreId());
 }
开发者ID:tingyeeh,项目名称:magento2,代码行数:13,代码来源:InvoiceTest.php

示例11: send

 /**
  * Send email to customer
  *
  * @param Invoice $invoice
  * @param bool $notify
  * @param string $comment
  * @return bool
  */
 public function send(Invoice $invoice, $notify = true, $comment = '')
 {
     $order = $invoice->getOrder();
     if ($order->getShippingAddress()) {
         $formattedShippingAddress = $this->addressRenderer->format($order->getShippingAddress(), 'html');
     } else {
         $formattedShippingAddress = '';
     }
     $formattedBillingAddress = $this->addressRenderer->format($order->getBillingAddress(), 'html');
     $transport = new \Magento\Framework\Object(['template_vars' => ['order' => $order, 'invoice' => $invoice, 'comment' => $comment, 'billing' => $order->getBillingAddress(), 'store' => $order->getStore(), 'formattedShippingAddress' => $formattedShippingAddress, 'formattedBillingAddress' => $formattedBillingAddress]]);
     $this->eventManager->dispatch('email_invoice_comment_set_template_vars_before', ['sender' => $this, 'transport' => $transport]);
     $this->templateContainer->setTemplateVars($transport->getTemplateVars());
     return $this->checkAndSend($order, $notify);
 }
开发者ID:opexsw,项目名称:magento2,代码行数:22,代码来源:InvoiceCommentSender.php

示例12: _prepareShipment

 /**
  * Prepare shipment
  *
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return \Magento\Sales\Model\Order\Shipment|false
  */
 protected function _prepareShipment($invoice)
 {
     $savedQtys = [];
     $data = $this->getRequest()->getParam('invoice');
     if (isset($data['items'])) {
         $savedQtys = $data['items'];
     }
     $shipment = $this->_objectManager->create('Magento\\Sales\\Model\\Service\\Order', ['order' => $invoice->getOrder()])->prepareShipment($savedQtys);
     if (!$shipment->getTotalQty()) {
         return false;
     }
     $shipment->register();
     $tracks = $this->getRequest()->getPost('tracking');
     if ($tracks) {
         foreach ($tracks as $data) {
             $track = $this->_objectManager->create('Magento\\Sales\\Model\\Order\\Shipment\\Track')->addData($data);
             $shipment->addTrack($track);
         }
     }
     return $shipment;
 }
开发者ID:opexsw,项目名称:magento2,代码行数:27,代码来源:Save.php

示例13: collect

 /**
  * Collect invoice subtotal
  *
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $subtotal = 0;
     $baseSubtotal = 0;
     $subtotalInclTax = 0;
     $baseSubtotalInclTax = 0;
     $order = $invoice->getOrder();
     foreach ($invoice->getAllItems() as $item) {
         if ($item->getOrderItem()->isDummy()) {
             continue;
         }
         $item->calcRowTotal();
         $subtotal += $item->getRowTotal();
         $baseSubtotal += $item->getBaseRowTotal();
         $subtotalInclTax += $item->getRowTotalInclTax();
         $baseSubtotalInclTax += $item->getBaseRowTotalInclTax();
     }
     $allowedSubtotal = $order->getSubtotal() - $order->getSubtotalInvoiced();
     $baseAllowedSubtotal = $order->getBaseSubtotal() - $order->getBaseSubtotalInvoiced();
     //Note: The $subtotalInclTax and $baseSubtotalInclTax are not adjusted from those provide by the line items
     //because the "InclTax" is displayed before any tax adjustments based on discounts, shipping, etc.
     if ($invoice->isLast()) {
         $subtotal = $allowedSubtotal;
         $baseSubtotal = $baseAllowedSubtotal;
     } else {
         $subtotal = min($allowedSubtotal, $subtotal);
         $baseSubtotal = min($baseAllowedSubtotal, $baseSubtotal);
     }
     $invoice->setSubtotal($subtotal);
     $invoice->setBaseSubtotal($baseSubtotal);
     $invoice->setSubtotalInclTax($subtotalInclTax);
     $invoice->setBaseSubtotalInclTax($baseSubtotalInclTax);
     $invoice->setGrandTotal($invoice->getGrandTotal() + $subtotal);
     $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseSubtotal);
     return $this;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:42,代码来源:Subtotal.php

示例14: collect

 /**
  * Collect Weee amounts for the invoice
  *
  * @param  \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $store = $invoice->getStore();
     $order = $invoice->getOrder();
     $totalWeeeAmount = 0;
     $baseTotalWeeeAmount = 0;
     $totalWeeeAmountInclTax = 0;
     $baseTotalWeeeAmountInclTax = 0;
     $totalWeeeTaxAmount = 0;
     $baseTotalWeeeTaxAmount = 0;
     /** @var \Magento\Sales\Model\Order\Invoice\Item $item */
     foreach ($invoice->getAllItems() as $item) {
         $orderItem = $item->getOrderItem();
         $orderItemQty = $orderItem->getQtyOrdered();
         if (!$orderItemQty || $orderItem->isDummy() || $item->getQty() <= 0) {
             continue;
         }
         $ratio = $item->getQty() / $orderItemQty;
         $orderItemWeeeAmount = $orderItem->getWeeeTaxAppliedRowAmount();
         $orderItemBaseWeeeAmount = $orderItem->getBaseWeeeTaxAppliedRowAmnt();
         $weeeAmount = $invoice->roundPrice($orderItemWeeeAmount * $ratio);
         $baseWeeeAmount = $invoice->roundPrice($orderItemBaseWeeeAmount * $ratio, 'base');
         $orderItemWeeeInclTax = $this->_weeeData->getRowWeeeTaxInclTax($orderItem);
         $orderItemBaseWeeeInclTax = $this->_weeeData->getBaseRowWeeeTaxInclTax($orderItem);
         $weeeAmountInclTax = $invoice->roundPrice($orderItemWeeeInclTax * $ratio);
         $baseWeeeAmountInclTax = $invoice->roundPrice($orderItemBaseWeeeInclTax * $ratio, 'base');
         $orderItemWeeeTax = $orderItemWeeeInclTax - $orderItemWeeeAmount;
         $itemWeeeTax = $weeeAmountInclTax - $weeeAmount;
         $itemBaseWeeeTax = $baseWeeeAmountInclTax - $baseWeeeAmount;
         if ($item->isLast()) {
             $weeeAmount = $orderItemWeeeAmount - $this->_weeeData->getWeeeAmountInvoiced($orderItem);
             $baseWeeeAmount = $orderItemBaseWeeeAmount - $this->_weeeData->getBaseWeeeAmountInvoiced($orderItem);
             $itemWeeeTax = $orderItemWeeeTax - $this->_weeeData->getWeeeTaxAmountInvoiced($orderItem);
             $itemBaseWeeeTax = $orderItemWeeeTax - $this->_weeeData->getBaseWeeeTaxAmountInvoiced($orderItem);
         }
         $totalWeeeTaxAmount += $itemWeeeTax;
         $baseTotalWeeeTaxAmount += $itemBaseWeeeTax;
         //Set the ratio of the tax amount in invoice item compared to tax amount in order item
         //This information is needed to calculate tax per tax rate later
         if ($orderItemWeeeTax != 0) {
             $taxRatio = [];
             if ($item->getTaxRatio()) {
                 $taxRatio = unserialize($item->getTaxRatio());
             }
             $taxRatio[\Magento\Weee\Model\Total\Quote\Weee::ITEM_TYPE] = $itemWeeeTax / $orderItemWeeeTax;
             $item->setTaxRatio(serialize($taxRatio));
         }
         $item->setWeeeTaxAppliedRowAmount($weeeAmount);
         $item->setBaseWeeeTaxAppliedRowAmount($baseWeeeAmount);
         $newApplied = [];
         $applied = $this->_weeeData->getApplied($orderItem);
         foreach ($applied as $one) {
             $title = (string) $one['title'];
             $one['base_row_amount'] = $invoice->roundPrice($one['base_row_amount'] * $ratio, $title . '_base');
             $one['row_amount'] = $invoice->roundPrice($one['row_amount'] * $ratio, $title);
             $one['base_row_amount_incl_tax'] = $invoice->roundPrice($one['base_row_amount_incl_tax'] * $ratio, $title . '_base');
             $one['row_amount_incl_tax'] = $invoice->roundPrice($one['row_amount_incl_tax'] * $ratio, $title);
             $newApplied[] = $one;
         }
         $this->_weeeData->setApplied($item, $newApplied);
         //Update order item
         $newApplied = [];
         $applied = $this->_weeeData->getApplied($orderItem);
         foreach ($applied as $one) {
             if (isset($one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED])) {
                 $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] + $baseWeeeAmount;
             } else {
                 $one[WeeeHelper::KEY_BASE_WEEE_AMOUNT_INVOICED] = $baseWeeeAmount;
             }
             if (isset($one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED])) {
                 $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] + $weeeAmount;
             } else {
                 $one[WeeeHelper::KEY_WEEE_AMOUNT_INVOICED] = $weeeAmount;
             }
             if (isset($one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED])) {
                 $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] + $itemWeeeTax;
             } else {
                 $one[WeeeHelper::KEY_BASE_WEEE_TAX_AMOUNT_INVOICED] = $itemWeeeTax;
             }
             if (isset($one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED])) {
                 $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] = $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] + $itemBaseWeeeTax;
             } else {
                 $one[WeeeHelper::KEY_WEEE_TAX_AMOUNT_INVOICED] = $itemBaseWeeeTax;
             }
             $newApplied[] = $one;
         }
         $this->_weeeData->setApplied($orderItem, $newApplied);
         $item->setWeeeTaxRowDisposition($item->getWeeeTaxDisposition() * $item->getQty());
         $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxDisposition() * $item->getQty());
         $totalWeeeAmount += $weeeAmount;
         $baseTotalWeeeAmount += $baseWeeeAmount;
//.........这里部分代码省略.........
开发者ID:shabbirvividads,项目名称:magento2,代码行数:101,代码来源:Weee.php

示例15: createByInvoice

 /**
  * Prepare order creditmemo based on invoice and requested params
  *
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @param array $data
  * @return Creditmemo
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function createByInvoice(\Magento\Sales\Model\Order\Invoice $invoice, array $data = [])
 {
     $order = $invoice->getOrder();
     $totalQty = 0;
     $qtys = isset($data['qtys']) ? $data['qtys'] : [];
     $creditmemo = $this->convertor->toCreditmemo($order);
     $creditmemo->setInvoice($invoice);
     $invoiceQtysRefunded = [];
     foreach ($invoice->getOrder()->getCreditmemosCollection() as $createdCreditmemo) {
         if ($createdCreditmemo->getState() != Creditmemo::STATE_CANCELED && $createdCreditmemo->getInvoiceId() == $invoice->getId()) {
             foreach ($createdCreditmemo->getAllItems() as $createdCreditmemoItem) {
                 $orderItemId = $createdCreditmemoItem->getOrderItem()->getId();
                 if (isset($invoiceQtysRefunded[$orderItemId])) {
                     $invoiceQtysRefunded[$orderItemId] += $createdCreditmemoItem->getQty();
                 } else {
                     $invoiceQtysRefunded[$orderItemId] = $createdCreditmemoItem->getQty();
                 }
             }
         }
     }
     $invoiceQtysRefundLimits = [];
     foreach ($invoice->getAllItems() as $invoiceItem) {
         $invoiceQtyCanBeRefunded = $invoiceItem->getQty();
         $orderItemId = $invoiceItem->getOrderItem()->getId();
         if (isset($invoiceQtysRefunded[$orderItemId])) {
             $invoiceQtyCanBeRefunded = $invoiceQtyCanBeRefunded - $invoiceQtysRefunded[$orderItemId];
         }
         $invoiceQtysRefundLimits[$orderItemId] = $invoiceQtyCanBeRefunded;
     }
     foreach ($invoice->getAllItems() as $invoiceItem) {
         $orderItem = $invoiceItem->getOrderItem();
         if (!$this->canRefundItem($orderItem, $qtys, $invoiceQtysRefundLimits)) {
             continue;
         }
         $item = $this->convertor->itemToCreditmemoItem($orderItem);
         if ($orderItem->isDummy()) {
             $qty = 1;
         } else {
             if (isset($qtys[$orderItem->getId()])) {
                 $qty = (double) $qtys[$orderItem->getId()];
             } elseif (!count($qtys)) {
                 $qty = $orderItem->getQtyToRefund();
             } else {
                 continue;
             }
             if (isset($invoiceQtysRefundLimits[$orderItem->getId()])) {
                 $qty = min($qty, $invoiceQtysRefundLimits[$orderItem->getId()]);
             }
         }
         $qty = min($qty, $invoiceItem->getQty());
         $totalQty += $qty;
         $item->setQty($qty);
         $creditmemo->addItem($item);
     }
     $creditmemo->setTotalQty($totalQty);
     $this->initData($creditmemo, $data);
     if (!isset($data['shipping_amount'])) {
         $isShippingInclTax = $this->taxConfig->displaySalesShippingInclTax($order->getStoreId());
         if ($isShippingInclTax) {
             $baseAllowedAmount = $order->getBaseShippingInclTax() - $order->getBaseShippingRefunded() - $order->getBaseShippingTaxRefunded();
         } else {
             $baseAllowedAmount = $order->getBaseShippingAmount() - $order->getBaseShippingRefunded();
             $baseAllowedAmount = min($baseAllowedAmount, $invoice->getBaseShippingAmount());
         }
         $creditmemo->setBaseShippingAmount($baseAllowedAmount);
     }
     $creditmemo->collectTotals();
     return $creditmemo;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:78,代码来源:CreditmemoFactory.php


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