Skip to content

Commit beea572

Browse files
barisgitjbtronics
andauthored
Add supplier information to KiCad part exports (#955)
* Add supplier information to KiCad part exports - Include supplier name and part numbers from order details in KiCad exports - Handle multiple suppliers with sequential numbering (Supplier 2, Supplier 3, etc.) - Include both active and obsolete order details for comprehensive supplier info - Add null checks to prevent errors when supplier or part number is missing * Add SPN suffix to field name --------- Co-authored-by: Jan Böhmer <[email protected]>
1 parent 442a7aa commit beea572

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Services/EDA/KiCadHelper.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,30 @@ public function getKiCADPart(Part $part): array
237237
$result["fields"]["Part-DB IPN"] = $this->createField($part->getIpn());
238238
}
239239

240+
// Add supplier information from orderdetails (include obsolete orderdetails)
241+
if ($part->getOrderdetails(false)->count() > 0) {
242+
$supplierCounts = [];
243+
244+
foreach ($part->getOrderdetails(false) as $orderdetail) {
245+
if ($orderdetail->getSupplier() !== null && $orderdetail->getSupplierPartNr() !== '') {
246+
$supplierName = $orderdetail->getSupplier()->getName();
247+
248+
$supplierName .= " SPN"; // Append "SPN" to the supplier name to indicate Supplier Part Number
249+
250+
if (!isset($supplierCounts[$supplierName])) {
251+
$supplierCounts[$supplierName] = 0;
252+
}
253+
$supplierCounts[$supplierName]++;
254+
255+
// Create field name with sequential number if more than one from same supplier (e.g. "Mouser", "Mouser 2", etc.)
256+
$fieldName = $supplierCounts[$supplierName] > 1
257+
? $supplierName . ' ' . $supplierCounts[$supplierName]
258+
: $supplierName;
259+
260+
$result["fields"][$fieldName] = $this->createField($orderdetail->getSupplierPartNr());
261+
}
262+
}
263+
}
240264

241265
return $result;
242266
}

0 commit comments

Comments
 (0)