public function testCollect() { $this->creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$this->creditmemoItemMock, $this->creditmemoItemMock]); $this->creditmemoItemMock->expects($this->exactly(2))->method('getHasChildren')->willReturn(false); $this->creditmemoItemMock->expects($this->exactly(2))->method('getBaseCost')->willReturn(10); $this->creditmemoItemMock->expects($this->exactly(2))->method('getQty')->willReturn(2); $this->creditmemoMock->expects($this->once())->method('setBaseCost')->with(40)->willReturnSelf(); $this->assertEquals($this->total, $this->total->collect($this->creditmemoMock)); }
public function testProcessRelations() { $this->creditmemoMock->expects($this->once())->method('getId')->willReturn('creditmemo-id-value'); $this->creditmemoMock->expects($this->exactly(2))->method('getItems')->willReturn([$this->itemMock]); $this->creditmemoMock->expects($this->exactly(2))->method('getComments')->willReturn([$this->commentMock]); $this->itemMock->expects($this->once())->method('setParentId')->with('creditmemo-id-value')->willReturnSelf(); $this->itemResourceMock->expects($this->once())->method('save')->with($this->itemMock)->willReturnSelf(); $this->commentResourceMock->expects($this->once())->method('save')->with($this->commentMock)->willReturnSelf(); $this->relationProcessor->processRelation($this->creditmemoMock); }
/** * @dataProvider calcRowTotalDataProvider */ public function testCalcRowTotal($qty) { $creditmemoMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->getMock(); $creditmemoMock->expects($this->exactly(4))->method('roundPrice')->will($this->returnCallback(function ($arg) { return round($arg, 2); })); $qtyInvoiced = 10; $qtyRefunded = 2; $qtyAvailable = $qtyInvoiced - $qtyRefunded; $rowInvoiced = 5; $amountRefunded = 2; $expectedRowTotal = ($rowInvoiced - $amountRefunded) / $qtyAvailable * $qty; $expectedRowTotal = round($expectedRowTotal, 2); $orderItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->getMock(); $orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn($qtyInvoiced); $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn($qtyRefunded); $orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn($rowInvoiced); $orderItemMock->expects($this->once())->method('getAmountRefunded')->willReturn($amountRefunded); $orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn($rowInvoiced); $orderItemMock->expects($this->once())->method('getBaseAmountRefunded')->willReturn($amountRefunded); $orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1); $orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1); $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1); $orderItemMock->expects($this->any())->method('getQtyToRefund')->willReturn($qtyAvailable); $this->item->setData('qty', $qty); $this->item->setCreditmemo($creditmemoMock); $this->item->setOrderItem($orderItemMock); $result = $this->item->calcRowTotal(); $this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', $result); $this->assertEquals($expectedRowTotal, $this->item->getData('row_total')); $this->assertEquals($expectedRowTotal, $this->item->getData('base_row_total')); }
public function testCalcRowTotal() { $creditmemoMock = $this->getMockBuilder('\\Magento\\Sales\\Model\\Order\\Creditmemo')->disableOriginalConstructor()->getMock(); $creditmemoMock->expects($this->exactly(4))->method('roundPrice')->willReturnMap([[0.375, 'regular', false, 0.4], [0.375, 'base', false, 0.4], [1, 'including', false, 1.0], [1, 'including_base', false, 1.0]]); $orderItemMock = $this->getMockBuilder('Magento\\Sales\\Model\\Order\\Item')->disableOriginalConstructor()->getMock(); $orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(10); $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(2); $orderItemMock->expects($this->once())->method('getRowInvoiced')->willReturn(5); $orderItemMock->expects($this->once())->method('getAmountRefunded')->willReturn(2); $orderItemMock->expects($this->once())->method('getBaseRowInvoiced')->willReturn(5); $orderItemMock->expects($this->once())->method('getBaseAmountRefunded')->willReturn(2); $orderItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1); $orderItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1); $orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(1); $orderItemMock->expects($this->once())->method('getQtyOrdered')->willReturn(1); $this->item->setData('qty', 1); $this->item->setCreditmemo($creditmemoMock); $this->item->setOrderItem($orderItemMock); $result = $this->item->calcRowTotal(); $this->assertInstanceOf('Magento\\Sales\\Model\\Order\\Creditmemo\\Item', $result); }
public function testCollect() { $this->creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$this->creditmemoItemMock]); $this->creditmemoItemMock->expects($this->atLeastOnce())->method('getOrderItem')->willReturn($this->orderItemMock); $this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(false); $this->creditmemoItemMock->expects($this->once())->method('calcRowTotal')->willReturnSelf(); $this->creditmemoItemMock->expects($this->once())->method('getRowTotal')->willReturn(1); $this->creditmemoItemMock->expects($this->once())->method('getBaseRowTotal')->willReturn(1); $this->creditmemoItemMock->expects($this->once())->method('getRowTotalInclTax')->willReturn(1); $this->creditmemoItemMock->expects($this->once())->method('getBaseRowTotalInclTax')->willReturn(1); $this->creditmemoMock->expects($this->once())->method('setSubtotal')->with(1)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setBaseSubtotal')->with(1)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setSubtotalInclTax')->with(1)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('setBaseSubtotalInclTax')->with(1)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('getGrandTotal')->willReturn(1); $this->creditmemoMock->expects($this->once())->method('setGrandTotal')->with(2)->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('getBaseGrandTotal')->willReturn(1); $this->creditmemoMock->expects($this->once())->method('setBaseGrandTotal')->with(2)->willReturnSelf(); $this->assertEquals($this->total, $this->total->collect($this->creditmemoMock)); }
public function testCollect() { $this->creditmemoMock->expects($this->exactly(2))->method('setDiscountAmount')->willReturnSelf(); $this->creditmemoMock->expects($this->exactly(2))->method('setBaseDiscountAmount')->willReturnSelf(); $this->creditmemoMock->expects($this->once())->method('getOrder')->willReturn($this->orderMock); $this->creditmemoMock->expects($this->once())->method('getBaseShippingAmount')->willReturn(1); $this->orderMock->expects($this->once())->method('getBaseShippingDiscountAmount')->willReturn(1); $this->orderMock->expects($this->exactly(2))->method('getBaseShippingAmount')->willReturn(1); $this->orderMock->expects($this->once())->method('getShippingAmount')->willReturn(1); $this->creditmemoMock->expects($this->once())->method('getAllItems')->willReturn([$this->creditmemoItemMock]); $this->creditmemoItemMock->expects($this->atLeastOnce())->method('getOrderItem')->willReturn($this->orderItemMock); $this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(false); $this->orderItemMock->expects($this->once())->method('getDiscountInvoiced')->willReturn(1); $this->orderItemMock->expects($this->once())->method('getBaseDiscountInvoiced')->willReturn(1); $this->orderItemMock->expects($this->once())->method('getQtyInvoiced')->willReturn(1); $this->orderItemMock->expects($this->once())->method('getDiscountRefunded')->willReturn(1); $this->orderItemMock->expects($this->once())->method('getQtyRefunded')->willReturn(0); $this->creditmemoItemMock->expects($this->once())->method('isLast')->willReturn(false); $this->creditmemoItemMock->expects($this->atLeastOnce())->method('getQty')->willReturn(1); $this->creditmemoItemMock->expects($this->exactly(1))->method('setDiscountAmount')->willReturnSelf(); $this->creditmemoItemMock->expects($this->exactly(1))->method('setBaseDiscountAmount')->willReturnSelf(); $this->creditmemoMock->expects($this->exactly(2))->method('roundPrice')->willReturnMap([[1, 'regular', true, 1], [1, 'base', true, 1]]); $this->assertEquals($this->total, $this->total->collect($this->creditmemoMock)); }
/** * Whether to show 'Return to stock' checkbox for item * * @param Item $item * @return bool */ public function canReturnItemToStock($item = null) { if (null !== $item) { if (!$item->hasCanReturnToStock()) { $productId = $item->getOrderItem()->getProductId(); if ($productId && $this->stockItemService->getManageStock($productId)) { $item->setCanReturnToStock(true); } else { $item->setCanReturnToStock(false); } } $canReturnToStock = $item->getCanReturnToStock(); } else { $canReturnToStock = $this->_scopeConfig->getValue(\Magento\CatalogInventory\Model\Stock\Item::XML_PATH_CAN_SUBTRACT, \Magento\Store\Model\ScopeInterface::SCOPE_STORE); } return $canReturnToStock; }
/** * @param \Magento\Sales\Model\Order\Creditmemo\Item $item * @return $this */ public function addItem(\Magento\Sales\Model\Order\Creditmemo\Item $item) { $item->setCreditmemo($this)->setParentId($this->getId())->setStoreId($this->getStoreId()); if (!$item->getId()) { $this->setItems(array_merge($this->getItems(), [$item])); } return $this; }
/** * Set item for render * * @param QuoteItem|OrderItem|InvoiceItem|CreditMemoItem $item * @return $this */ public function setItem($item) { $this->item = $item; $this->storeId = $item->getStoreId(); return $this; }
/** * @param \Magento\Sales\Model\Order\Creditmemo\Item $item * @return $this */ public function addItem(\Magento\Sales\Model\Order\Creditmemo\Item $item) { $item->setCreditmemo($this)->setParentId($this->getId())->setStoreId($this->getStoreId()); if (!$item->getId()) { $this->getItemsCollection()->addItem($item); } return $this; }
/** * Whether to show 'Return to stock' column for item parent * * @param Item $item * @return bool */ public function canParentReturnToStock($item = null) { if ($item !== null) { if ($item->getCreditmemo()->getOrder()->hasCanReturnToStock()) { return $item->getCreditmemo()->getOrder()->getCanReturnToStock(); } } elseif ($this->getOrder()->hasCanReturnToStock()) { return $this->getOrder()->getCanReturnToStock(); } return $this->canReturnToStock(); }
/** * Return the total amount minus discount * * @param OrderItem|InvoiceItem|CreditMemoItem $item * @return mixed */ public function getBaseTotalAmount($item) { $totalAmount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount() + $item->getBaseTaxAmount() + $item->getBaseHiddenTaxAmount() + $this->weeeHelper->getBaseRowWeeeTaxInclTax($item); return $totalAmount; }
/** * Calculate base total amount for the item * * @param QuoteItem|Item|InvoiceItem|CreditmemoItem $item * @return mixed */ public function getBaseTotalAmount($item) { $baseTotalAmount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount(); return $baseTotalAmount; }