I am extending this class :
Magento\Sales\Model\Service\InvoiceService
My extended file :
namespace Company\Vendor\Model\Service;
use Magento\Sales\Api\InvoiceManagementInterface;
use Magento\Sales\Model\Order;
class InvoiceService extends \Magento\Sales\Model\Service\InvoiceService implements InvoiceManagementInterface
{
public function prepareInvoice(Order $order, array $qtys = [])
{
$invoice = $this->orderConverter->toInvoice($order);
$totalQty = 0;
$qtys = parent::prepareItemsQty($order, $qtys); // modified line
//$qtys = $this->prepareItemsQty($order, $qtys); // core line
foreach ($order->getAllItems() as $orderItem) {
if (!$this->_canInvoiceItem($orderItem)) {
continue;
}
$item = $this->orderConverter->itemToInvoiceItem($orderItem);
if ($orderItem->isDummy()) {
$qty = $orderItem->getQtyOrdered() ? $orderItem->getQtyOrdered() : 1;
} elseif (isset($qtys[$orderItem->getId()])) {
$qty = (double) $qtys[$orderItem->getId()];
} elseif (empty($qtys)) {
$qty = $orderItem->getQtyToInvoice();
} else {
$qty = 0;
}
$totalQty += $qty;
$this->setInvoiceItemQuantity($item, $qty);
$invoice->addItem($item);
}
$invoice->setTotalQty($totalQty);
$invoice->collectTotals();
$order->getInvoiceCollection()->addItem($invoice);
return $invoice;
}
}
I am getting an error here:$this->prepareItemsQty($order, $qtys);
So I am a bit confused about how to call another function of parent functions here.
Note: I don't want to declare code of prepareItemsQty() here (extended class).
\Magento\Sales\Model\Service\InvoiceService
class or you want to extends\Magento\Sales\Model\Service\InvoiceService
? – Amit Bera♦ Sep 6 at 7:57