Example #1
0
 /**
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage We found an invalid quantity to invoice item "Item Name".
  */
 public function testSetQtyWrongQty()
 {
     $this->orderItemFactoryMock->expects($this->once())->method('create')->willReturn($this->orderItemMock);
     $this->orderItemMock->expects($this->once())->method('load')->with(1)->willReturn($this->orderItemMock);
     $this->orderItemMock->expects($this->once())->method('getIsQtyDecimal')->willReturn(true);
     $this->orderItemMock->expects($this->once())->method('getQtyToInvoice')->willReturn(2);
     $this->orderItemMock->expects($this->once())->method('isDummy')->willReturn(false);
     $this->item->setOrderItemId(1);
     $this->item->setName('Item Name');
     $this->assertEquals($this->item->setQty(3), $this->item);
 }
Example #2
0
 public function testSetQty()
 {
     $qty = 3;
     $this->assertEquals($this->item->setQty($qty), $this->item);
     $this->assertEquals($this->item->getQty(), $qty);
 }
Example #3
0
 /**
  * Set quantity to invoice item
  *
  * @param \Magento\Sales\Model\Order\Invoice\Item $item
  * @param float $qty
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function setInvoiceItemQuantity(\Magento\Sales\Model\Order\Invoice\Item $item, $qty)
 {
     $qty = $item->getOrderItem()->getIsQtyDecimal() ? (double) $qty : (int) $qty;
     $qty = $qty > 0 ? $qty : 0;
     /**
      * Check qty availability
      */
     $qtyToInvoice = sprintf("%F", $item->getOrderItem()->getQtyToInvoice());
     $qty = sprintf("%F", $qty);
     if ($qty > $qtyToInvoice && !$item->getOrderItem()->isDummy()) {
         throw new \Magento\Framework\Exception\LocalizedException(__('We found an invalid quantity to invoice item "%1".', $item->getName()));
     }
     $item->setQty($qty);
     return $this;
 }