Ontdek de code van Sander

001<?php002 003public function get(004   ServerRequestInterface $request005): ResponseInterface {006  $queryParams = $request->getQueryParams();007  $urlParams = $this->determineAnalyticsParameters($queryParams);008 009  if (isset($queryParams['p'])) {010      $urlParams['productId'] = $queryParams['p'];011      return $this->createProductRedirect($urlParams);012  }013 014  return $this->responseFactory->emptyBody(StatusCodeInterface::STATUS_NOT_FOUND);015}016 017 018private function determineAnalyticsParameters(array $queryParams): array019{020  $campaign = [021      'object' => 'product_card',022  ];023 024  if (isset($queryParams['p'])) {025      $campaign['product_id'] = $queryParams['p'];026  }027 028  if (isset($queryParams['l'])) {029      $locationData = explode('.', $queryParams['l']);030      $campaign['store_id'] = $locationData[0];031      if (isset($locationData[1])) {032          $campaign['display_id'] = $locationData[1];033          $campaign['object'] = 'poster';034      }035  }036 037  if (isset($queryParams['s'])) {038      $campaign['slug'] = $queryParams['s'];039  }040 041  $campaignString = '';042  foreach ($campaign as $key => $value) {043      $campaignString .= "[$key:$value]";044  }045 046  return [047    'utm_source' => 'coolblue',048    'utm_medium' => 'qr_stores',049    'utm_campaign' => $campaignString050  ];051}
Winkelmodus
Dit is echte code uit de Coolblue App. Scroll er gerust doorheen.
Vorige
Volgende