From 47c1b9b1ae6d8f5bf7e478e9089700bc4d9d7a9e Mon Sep 17 00:00:00 2001 From: Jerome Aparece Date: Fri, 14 Jan 2022 20:49:17 +0800 Subject: [PATCH] Added a fix to error when creating an invoice for multiple items with the same sku. --- .gitignore | 3 ++- Model/Dibs/Items.php | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 436c7ddd..5a9a7a9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +.vscode .idea/ -.DS_STORE +.DS_STORE \ No newline at end of file diff --git a/Model/Dibs/Items.php b/Model/Dibs/Items.php index ee5b5cda..69652439 100644 --- a/Model/Dibs/Items.php +++ b/Model/Dibs/Items.php @@ -262,7 +262,16 @@ public function addItems($items) $sku = $item->getSku(); //make sku unique (sku could not be unique when we have product with options) if (isset($this->_cart[$sku])) { - $sku = $sku . '-' . $item->getId(); + $itemRefId = $item->getId(); + /** + * use related order_item_id or quote_item_id when item id is not set + * error is observed when creating an invoice and there is more than two items with the same sku but with different configurations + * items after the second similar sku will replace the second item instead of appending as a separate item + */ + $itemRefId = $itemRefId ? $itemRefId : $item->getData('order_item_id'); + $itemRefId = $itemRefId ? $itemRefId : $item->getData('quote_item_id'); + $sku = $sku.'-'.$itemRefId; + } $itemName = $item->getName();