Skip to content

Commit 273bde9

Browse files
committed
Use the providerID as keyword when searching infos for a part with already existing providerreference and preselect the info provider if possible
1 parent 92e4976 commit 273bde9

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Controller/InfoProviderController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,23 @@ public function search(Request $request, #[MapEntity(id: 'target')] ?Part $updat
7777
//When we are updating a part, use its name as keyword, to make searching easier
7878
//However we can only do this, if the form was not submitted yet
7979
if ($update_target !== null && !$form->isSubmitted()) {
80-
$form->get('keyword')->setData($update_target->getName());
80+
//Use the provider reference if available, otherwise use the manufacturer product number
81+
$keyword = $update_target->getProviderReference()->getProviderId() ?? $update_target->getManufacturerProductNumber();
82+
//Or the name if both are not available
83+
if ($keyword === "") {
84+
$keyword = $update_target->getName();
85+
}
86+
87+
$form->get('keyword')->setData($keyword);
88+
89+
//If we are updating a part, which already has a provider, preselect that provider in the form
90+
if ($update_target->getProviderReference()->getProviderKey() !== null) {
91+
try {
92+
$form->get('providers')->setData([$this->providerRegistry->getProviderByKey($update_target->getProviderReference()->getProviderKey())]);
93+
} catch (\InvalidArgumentException $e) {
94+
//If the provider is not found, just ignore it
95+
}
96+
}
8197
}
8298

8399
if ($form->isSubmitted() && $form->isValid()) {

0 commit comments

Comments
 (0)