Skip to main content

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 entityNameApp\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 entityNameApp\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 null wenn die Attribute-Id nicht existiert; false wenn 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?

ScenarioHelper
Webhook empfangen, brauche das Domain-Controller-ObjectgetWeclappController()
Lokale DB-Spiegelung anlegengetCommonModel()
Custom-Attribut auslesen vor PUTgetCustomAttribute()
Custom-Attribut setzen, aber nicht andere überschreibenWeclappApiService::updateCustomAttribute() (robuster)
Custom-Attribut komplett entfernenremoveCustomAttribute()

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.