Weclapp Helper
App\Http\Helpers\Weclapp\Helper
Statische Lookup-Tabellen + Custom-Attribute-Manipulation. Wird vom WebHookCallController und WeclappApiService genutzt.
Modell-Mappings
getWeclappModel(string $key): ?string
Mapping entityName → App\Models\Weclapp\<Model>. Über 150 Einträge, von accountTransaction bis weclappOs.
use App\Http\Helpers\Weclapp\Helper as wcHelper;
$modelClass = wcHelper::getWeclappModel('customer');
// → \App\Models\Weclapp\Customer::class
$customer = (new $modelClass())->whereKey($id)->firstOrFail();
getCommonModel(string $key): ?string
Mapping entityName → App\Models\Common\Weclapp\<Model> (lokales Spiegel-Modell in der Common-DB).
wcHelper::getCommonModel('party');
// → \App\Models\Common\Weclapp\Party::class
getMfrModel(string $key): ?string
Mapping entityName → entsprechendes Modell in der Common-MFR-Tabelle.
wcHelper::getMfrModel('party');
// → \App\Models\Common\Mfr\Companies::class
getMfrMapping(string $key): ?string & getMfrController(string $key): ?string
Wer mappt was bei der Weclapp → MFR Synchronisation?
wcHelper::getMfrMapping('party'); // → CompanyMapping
wcHelper::getMfrController('party'); // → \App\Http\Controllers\Mfr\CompanyController::class
getWeclappController(string $key): ?string
Welcher Domain-Controller verarbeitet einen Webhook?
wcHelper::getWeclappController('opportunity'); // → OpportunityController::class
wcHelper::getWeclappController('task'); // → TaskController::class
wcHelper::getWeclappController('contract'); // → ContractController::class
Custom Attributes
Helper für das Weclapp customAttributes[]-Konzept (jede Entity kann beliebig viele Custom-Felder haben, identifiziert durch attributeDefinitionId).
getCustomAttribute(array $customAttributes, $AttId): mixed
Liest den Wert eines Custom-Attribute aus. Greift auf den ersten Nicht-attributeDefinitionId-Key zu (stringValue / numberValue / booleanValue / dateValue).
$mfrId = wcHelper::getCustomAttribute(
$entity['customAttributes'],
2652615, // MfrId
);
Returns
nullwenn die Attribute-Id nicht existiert;falsewenn das Attribut da ist aber keinen Wert hat.
setCustomAttribute(array $customAttributes, $AttId, $value)
Setzt den Wert in einem bestehenden Eintrag. Findet das Slot-Type aus dem ersten Nicht-Id-Key. Returns das modifizierte Attribut oder null.
$updated = wcHelper::setCustomAttribute(
$entity['customAttributes'],
2652615,
'NEW-MFR-ID',
);
Achtung: returns nur das eine Attribut, nicht das gesamte Array. Der Caller muss es zurückschreiben.
removeCustomAttribute(array &$customAttributes, $AttId): bool
Entfernt das Attribut by Reference und reindiziert das Array. Returns true bei Erfolg.
wcHelper::removeCustomAttribute($entity['customAttributes'], 2652615);
getItems(array $items, $id, $attr = 'id')
Generischer Lookup über ein Array von Assoc-Arrays:
$item = wcHelper::getItems($salesOrder['items'], 'X-123', 'articleNumber');
Wann nutze ich was?
| Scenario | Helper |
|---|---|
| Webhook empfangen, brauche das Domain-Controller-Object | getWeclappController() |
| Lokale DB-Spiegelung anlegen | getCommonModel() |
| Custom-Attribut auslesen vor PUT | getCustomAttribute() |
| Custom-Attribut setzen, aber nicht andere überschreiben | WeclappApiService::updateCustomAttribute() (robuster) |
| Custom-Attribut komplett entfernen | removeCustomAttribute() |
Letztere Empfehlung: für Custom-Attribute-Updates gegen Weclapp lieber WeclappApiService::updateCustomAttribute() nehmen — der kümmert sich automatisch um Auto-Detection des Value-Type, Erhalt anderer Slots und das PUT selbst.