Skip to content

Instantly share code, notes, and snippets.

@Frank-Magmodules
Created May 23, 2024 08:23
Show Gist options
  • Save Frank-Magmodules/3c92482d272d988ee797f1f0bebc2554 to your computer and use it in GitHub Desktop.
Save Frank-Magmodules/3c92482d272d988ee797f1f0bebc2554 to your computer and use it in GitHub Desktop.
779.diff
diff --git a/Model/OrderLines.php b/Model/OrderLines.php
index f1eaf9ef..1e135d1c 100644
--- a/Model/OrderLines.php
+++ b/Model/OrderLines.php
@@ -214,7 +214,14 @@ public function getShipmentOrderLines(ShipmentInterface $shipment): array
$orderItemId = $item->getOrderItemId();
$lineId = $this->getOrderLineByItemId($orderItemId)->getLineId();
- $line = ['id' => $lineId, 'quantity' => $item->getQty()];
+
+ $qty = $item->getQty();
+ // Support for fractional quantities
+ if (round($qty) != $qty) {
+ $qty *= 100;
+ }
+
+ $line = ['id' => $lineId, 'quantity' => $qty];
if ($orderHasDiscount) {
$orderItem = $item->getOrderItem();
@@ -284,9 +291,15 @@ public function getCreditmemoOrderLines(CreditmemoInterface $creditmemo, bool $a
continue;
}
+ $qty = round($item->getQty());
+ // Support for fractional quantities
+ if (round($item->getQty()) != $item->getQty()) {
+ $qty *= 100;
+ }
+
$line = [
'id' => $lineId,
- 'quantity' => round($item->getQty()),
+ 'quantity' => $qty,
];
if ($item->getBaseDiscountAmount()) {
diff --git a/Service/Order/Lines/Order.php b/Service/Order/Lines/Order.php
index 592949fb..eaf0d0a9 100644
--- a/Service/Order/Lines/Order.php
+++ b/Service/Order/Lines/Order.php
@@ -172,11 +172,18 @@ private function getOrderLine(OrderItemInterface $item, $zeroPriceLine = false)
$vatAmount = 0;
}
+ $quantity = $item->getQtyOrdered();
+ // Handle items with a fractional quantity
+ if (round($item->getQtyOrdered()) != $item->getQtyOrdered()) {
+ $unitPrice = ($totalAmount + $discountAmount) / ($item->getQtyOrdered() * 100);
+ $quantity *= 100;
+ }
+
$orderLine = [
'item_id' => $item->getId(),
'type' => $item->getIsVirtual() !== null && (int) $item->getIsVirtual() !== 1 ? 'physical' : 'digital',
'name' => preg_replace('/[^\p{L}\p{N} -]/u', '', $item->getName() ?? ''),
- 'quantity' => round($item->getQtyOrdered()),
+ 'quantity' => round($quantity),
'unitPrice' => $this->mollieHelper->getAmountArray($this->currency, $unitPrice),
'totalAmount' => $this->mollieHelper->getAmountArray($this->currency, $totalAmount),
'vatRate' => sprintf("%.2f", $item->getTaxPercent()),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment