Inhalt
Ich habe eine CustomSalesChannelContextFactory
implementiert, um basierend auf der Auswahl „business“ oder „private“ im Cookie den Preis netto bzw. brutto anzuzeigen:
public function create(string $token, string $salesChannelId, array $options = []): SalesChannelContext
{
$request = $this->requestStack->getCurrentRequest();
if (!$request) {
return $this->decorated->create($token, $salesChannelId, $options);
}
$customerType = $request->cookies->get('customer-type')
?? $request->headers->get('customer-type');
if (!in_array($customerType, ['business', 'private'], true)) {
return $this->decorated->create($token, $salesChannelId, $options);
}
$options['customerGroupId'] = $customerType === 'business'
? '0193b9f622ac7073a66584f14f56cc25'
: 'cfbd5018d38d41d8adca10d94fc8bdd6';
$newToken = bin2hex(random_bytes(16));
$this->contextPersister->save(
$newToken,
['customerGroupId' => $options['customerGroupId']],
$salesChannelId
);
return $this->decorated->create($newToken, $salesChannelId, $options);
}
Erwartung: Im Frontend ändert sich die customerGroupId
entsprechend der Auswahl und die Preise werden netto bzw. brutto korrekt aktualisiert.
Tatsächlich: Die customerGroupId
ändert sich weder in den Logs noch im Storefront.
Gesuchte Hilfe:
Wie kann ich in dieser Factory die customerGroupId
aus dem Cookie endgültig überschreiben, sodass in allen Storefront-Anfragen die korrekten Preise angezeigt werden?