本文整理汇总了PHP中Magento\Sales\Model\Order\Invoice类的典型用法代码示例。如果您正苦于以下问题:PHP Invoice类的具体用法?PHP Invoice怎么用?PHP Invoice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Invoice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}