public function CartTokenSubscriber::onRequest in Commerce Cart API 8
Loads the token cart data and resets it to the session.
Parameters
\Symfony\Component\HttpKernel\Event\RequestEvent $event: The response event, which contains the current request.
File
- src/
EventSubscriber/ CartTokenSubscriber.php, line 75
Class
- CartTokenSubscriber
- Cart token subscriber.
Namespace
Drupal\commerce_cart_api\EventSubscriberCode
public function onRequest(RequestEvent $event) {
$cart_token = $event
->getRequest()->query
->get(CartTokenSession::QUERY_NAME);
if ($cart_token) {
$token_cart_data = $this->tempStore
->get($cart_token);
foreach ([
CartSessionInterface::ACTIVE,
CartSessionInterface::COMPLETED,
] as $cart_type) {
if (isset($token_cart_data[$cart_type]) && is_array($token_cart_data[$cart_type])) {
foreach ($token_cart_data[$cart_type] as $token_cart_datum) {
$this->cartSession
->addCartId($token_cart_datum, $cart_type);
}
}
}
}
}