• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Order\Invoice类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: toInvoice

 /**
  * Convert order object to invoice
  *
  * @param   \Magento\Sales\Model\Order $order
  * @return  \Magento\Sales\Model\Order\Invoice
  */
 public function toInvoice(\Magento\Sales\Model\Order $order)
 {
     $invoice = $this->_orderInvoiceFactory->create();
     $invoice->setOrder($order)->setStoreId($order->getStoreId())->setCustomerId($order->getCustomerId())->setBillingAddressId($order->getBillingAddressId())->setShippingAddressId($order->getShippingAddressId());
     $this->_objectCopyService->copyFieldsetToTarget('sales_convert_order', 'to_invoice', $order, $invoice);
     return $invoice;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Order.php


示例2: 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


示例3: _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


示例4: collect

 /**
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     /**
      * Check order grand total and invoice amounts
      */
     if ($invoice->isLast()) {
         //
     }
     return $this;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:Grand.php


示例5: collect

 /**
  * Collect total cost of invoiced items
  *
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @return $this
  */
 public function collect(\Magento\Sales\Model\Order\Invoice $invoice)
 {
     $baseInvoiceTotalCost = 0;
     foreach ($invoice->getAllItems() as $item) {
         if (!$item->getHasChildren()) {
             $baseInvoiceTotalCost += $item->getBaseCost() * $item->getQty();
         }
     }
     $invoice->setBaseCost($baseInvoiceTotalCost);
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:17,代码来源:Cost.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();
     $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


示例7: 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


示例8: setStateValue

 /**
  * Update invoice state value
  * Method set text label instead id value
  * @return void
  */
 private function setStateValue()
 {
     $value = $this->getData(self::$stateAttributeCode);
     /** @var \Magento\Framework\Phrase $state */
     $state = Invoice::getStates()[$value];
     $this->setCustomAttribute(self::$stateAttributeCode, $state->getText());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:12,代码来源:Document.php


示例9: 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


示例10: send

 /**
  * Sends order invoice email to the customer.
  *
  * Email will be sent immediately in two cases:
  *
  * - if asynchronous email sending is disabled in global settings
  * - if $forceSyncMode parameter is set to TRUE
  *
  * Otherwise, email will be sent later during running of
  * corresponding cron job.
  *
  * @param Invoice $invoice
  * @param bool $forceSyncMode
  * @return bool
  */
 public function send(Invoice $invoice, $forceSyncMode = false)
 {
     $invoice->setSendEmail(true);
     if (!$this->globalConfig->getValue('sales_email/general/async_sending') || $forceSyncMode) {
         $order = $invoice->getOrder();
         $transport = ['order' => $order, 'invoice' => $invoice, 'comment' => $invoice->getCustomerNoteNotify() ? $invoice->getCustomerNote() : '', 'billing' => $order->getBillingAddress(), 'payment_html' => $this->getPaymentHtml($order), 'store' => $order->getStore(), 'formattedShippingAddress' => $this->getFormattedShippingAddress($order), 'formattedBillingAddress' => $this->getFormattedBillingAddress($order)];
         $this->eventManager->dispatch('email_invoice_set_template_vars_before', ['sender' => $this, 'transport' => $transport]);
         $this->templateContainer->setTemplateVars($transport);
         if ($this->checkAndSend($order)) {
             $invoice->setEmailSent(true);
             $this->invoiceResource->saveAttribute($invoice, ['send_email', 'email_sent']);
             return true;
         }
     }
     $this->invoiceResource->saveAttribute($invoice, 'send_email');
     return false;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:32,代码来源:InvoiceSender.php


示例11: 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


示例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: testProcessRelation

 public function testProcessRelation()
 {
     $this->addressHandlerMock->expects($this->once())->method('removeEmptyAddresses')->with($this->orderMock)->willReturnSelf();
     $this->addressHandlerMock->expects($this->once())->method('process')->with($this->orderMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->orderItemMock]);
     $this->orderMock->expects($this->exactly(3))->method('getId')->willReturn('order-id-value');
     $this->orderItemMock->expects($this->once())->method('setOrderId')->with('order-id-value')->willReturnSelf();
     $this->orderItemMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->orderItemRepositoryMock->expects($this->once())->method('save')->with($this->orderItemMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getPayment')->willReturn($this->orderPaymentMock);
     $this->orderPaymentMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf();
     $this->orderPaymentMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->orderPaymentResourceMock->expects($this->once())->method('save')->with($this->orderPaymentMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getStatusHistories')->willReturn([$this->orderStatusHistoryMock]);
     $this->orderStatusHistoryMock->expects($this->once())->method('setParentId')->with('order-id-value')->willReturnSelf();
     $this->orderStatusHistoryMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->statusHistoryResource->expects($this->once())->method('save')->with($this->orderStatusHistoryMock)->willReturnSelf();
     $this->orderMock->expects($this->exactly(2))->method('getRelatedObjects')->willReturn([$this->orderInvoiceMock]);
     $this->orderInvoiceMock->expects($this->once())->method('setOrder')->with($this->orderMock)->willReturnSelf();
     $this->orderInvoiceMock->expects($this->once())->method('save')->willReturnSelf();
     $this->relationProcessor->processRelation($this->orderMock);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:22,代码来源:RelationTest.php


示例14: testCalcRowTotal

 public function testCalcRowTotal()
 {
     $this->item->setData(['order_item_id' => 1, 'qty' => 2]);
     $this->item->setInvoice($this->invoiceMock);
     $this->invoiceMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock);
     $this->orderMock->expects($this->once())->method('getItemById')->with(1)->willReturn($this->orderItemMock);
     $this->orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getRowTotal')->willReturn(2);
     $this->orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(2);
     $this->orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(1);
     $this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(0);
     $this->invoiceMock->expects($this->exactly(4))->method('roundPrice')->willReturnMap([[2, 'regular', false, 2], [2, 'base', false, 2], [2, 'including', false, 2], [2, 'including_base', false, 2]]);
     $this->assertEquals($this->item->calcRowTotal(), $this->item);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:18,代码来源:ItemTest.php


示例15: testExecute

 /**
  *  test execute method
  */
 public function testExecute()
 {
     $this->requestMock->expects($this->exactly(4))->method('getParam')->will($this->returnValueMap([['order_id', null, 'order_id'], ['creditmemo_id', null, 'creditmemo_id'], ['creditmemo', null, 'creditmemo'], ['invoice_id', null, 'invoice_id']]));
     $this->creditmemoLoaderMock->expects($this->once())->method('setOrderId')->with($this->equalTo('order_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemoId')->with($this->equalTo('creditmemo_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setCreditmemo')->with($this->equalTo('creditmemo'));
     $this->creditmemoLoaderMock->expects($this->once())->method('setInvoiceId')->with($this->equalTo('invoice_id'));
     $this->creditmemoLoaderMock->expects($this->once())->method('load')->will($this->returnValue($this->creditmemoMock));
     $this->creditmemoMock->expects($this->exactly(2))->method('getInvoice')->will($this->returnValue($this->invoiceMock));
     $this->invoiceMock->expects($this->once())->method('getIncrementId')->will($this->returnValue('invoice-increment-id'));
     $this->titleMock->expects($this->exactly(2))->method('prepend')->will($this->returnValueMap([['Credit Memos', null], ['New Memo for #invoice-increment-id', null], ['item-title', null]]));
     $this->objectManagerMock->expects($this->once())->method('get')->with($this->equalTo('Magento\\Backend\\Model\\Session'))->will($this->returnValue($this->backendSessionMock));
     $this->backendSessionMock->expects($this->once())->method('getCommentText')->with($this->equalTo(true))->will($this->returnValue('comment'));
     $this->creditmemoMock->expects($this->once())->method('setCommentText')->with($this->equalTo('comment'));
     $this->resultPageMock->expects($this->any())->method('getConfig')->will($this->returnValue($this->pageConfigMock));
     $this->pageConfigMock->expects($this->any())->method('getTitle')->willReturn($this->titleMock);
     $this->resultPageFactoryMock->expects($this->once())->method('create')->willReturn($this->resultPageMock);
     $this->resultPageMock->expects($this->once())->method('setActiveMenu')->with('Magento_Sales::sales_order')->willReturnSelf();
     $this->resultPageMock->expects($this->atLeastOnce())->method('getConfig')->willReturn($this->pageConfigMock);
     $this->assertInstanceOf('Magento\\Backend\\Model\\View\\Result\\Page', $this->controller->execute());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:24,代码来源:NewActionTest.php


示例16: testCollect

 /**
  * @param array $orderData
  * @param array $invoiceData
  * @param array $expectedResults
  * @dataProvider collectDataProvider
  */
 public function testCollect($orderData, $invoiceData, $expectedResults)
 {
     $roundingDelta = [];
     $this->setupOrder($orderData);
     //Set up weeeData mock
     $this->weeeData->expects($this->once())->method('includeInSubtotal')->will($this->returnValue($invoiceData['include_in_subtotal']));
     //Set up invoice mock
     /** @var \Magento\Sales\Model\Order\Invoice\Item[] $invoiceItems */
     $invoiceItems = [];
     foreach ($invoiceData['items'] as $itemKey => $invoiceItemData) {
         $invoiceItems[$itemKey] = $this->getInvoiceItem($invoiceItemData);
     }
     $this->invoice->expects($this->once())->method('getAllItems')->will($this->returnValue($invoiceItems));
     $this->invoice->expects($this->once())->method('isLast')->will($this->returnValue($invoiceData['is_last']));
     foreach ($invoiceData['data_fields'] as $key => $value) {
         $this->invoice->setData($key, $value);
     }
     $this->invoice->expects($this->any())->method('roundPrice')->will($this->returnCallback(function ($price, $type) use(&$roundingDelta) {
         if (!isset($roundingDelta[$type])) {
             $roundingDelta[$type] = 0;
         }
         $roundedPrice = round($price + $roundingDelta[$type], 2);
         $roundingDelta[$type] = $price - $roundedPrice;
         return $roundedPrice;
     }));
     $this->model->collect($this->invoice);
     //verify invoice data
     foreach ($expectedResults['invoice_data'] as $key => $value) {
         $this->assertEquals($value, $this->invoice->getData($key), 'Invoice data field ' . $key . ' is incorrect');
     }
     //verify invoice item data
     foreach ($expectedResults['invoice_items'] as $itemKey => $itemData) {
         $invoiceItem = $invoiceItems[$itemKey];
         foreach ($itemData as $key => $value) {
             if ($key == 'tax_ratio') {
                 $taxRatio = unserialize($invoiceItem->getData($key));
                 $expectedTaxRatio = unserialize($itemData[$key]);
                 $this->assertEquals($expectedTaxRatio['weee'], $taxRatio['weee'], "Tax ratio is incorrect");
             } else {
                 $this->assertEquals($value, $invoiceItem->getData($key), 'Invoice item field ' . $key . ' is incorrect');
             }
         }
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:50,代码来源:WeeeTest.php


示例17: processInvoice

 /**
  * Mock capture transaction id in invoice
  *
  * @param \Magento\Sales\Model\Order\Invoice $invoice
  * @param \Magento\Sales\Model\Order\Payment $payment
  * @return $this
  */
 public function processInvoice($invoice, $payment)
 {
     $invoice->setTransactionId(1);
     return $this;
 }
开发者ID:aiesh,项目名称:magento2,代码行数:12,代码来源:Authorizenet.php


示例18: cancelInvoiceAndRegisterCancellation

 /**
  * Cancel invoice and register order cancellation
  *
  * @param Invoice|false $invoice
  * @param string $message
  */
 protected function cancelInvoiceAndRegisterCancellation($invoice, $message)
 {
     if ($invoice instanceof Invoice) {
         $invoice->cancel();
         $this->getOrder()->addRelatedObject($invoice);
     }
     $this->getOrder()->registerCancellation($message, false);
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:14,代码来源:Payment.php


示例19: updateBaseAmountPaidOnlineTotal

 /**
  * Triggers invoice pay and updates base_amount_paid_online total.
  *
  * @param \Magento\Sales\Model\Order\Invoice|false $invoice
  */
 protected function updateBaseAmountPaidOnlineTotal($invoice)
 {
     if ($invoice instanceof Invoice) {
         $invoice->pay();
         $this->_updateTotals(['base_amount_paid_online' => $invoice->getBaseGrandTotal()]);
         $this->getOrder()->addRelatedObject($invoice);
     }
 }
开发者ID:niranjanssiet,项目名称:magento2,代码行数:13,代码来源:Payment.php


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Order\Item类代码示例发布时间:2022-05-23
下一篇:
PHP Order\Creditmemo类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap