58 lines
1.9 KiB
PHP
58 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace External\ZNZBundle\Controller;
|
|
|
|
use External\ZNZBundle\Dto\B2BFeedDefinition;
|
|
use External\ZNZBundle\Util\ZNZFeedUtil;
|
|
use KupShop\KupShopBundle\Context\CurrencyContext;
|
|
use KupShop\KupShopBundle\Context\LanguageContext;
|
|
use KupShop\KupShopBundle\Util\Contexts;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
/**
|
|
* Zpětná kompatibilita s jejich starýma B2B feedama.
|
|
*/
|
|
class ZNZFeedController extends AbstractController
|
|
{
|
|
#[Route(path: '/feeds/download/{category}/hash/{hash}/format/{format}/currency/{currency}/type/{type}/', requirements: ['format' => 'xml|csv|xlsx'])]
|
|
public function znzB2BFeed(
|
|
ZNZFeedUtil $feedUtil,
|
|
string $category,
|
|
string $hash,
|
|
string $format,
|
|
string $currency,
|
|
string $type,
|
|
#[MapQueryParameter] ?string $language = null,
|
|
#[MapQueryParameter] bool $download = false,
|
|
): Response {
|
|
$languageContext = Contexts::get(LanguageContext::class);
|
|
if (!$language || !($languageContext->getSupported()[$language] ?? false)) {
|
|
$language = $languageContext->getActiveId();
|
|
}
|
|
|
|
$response = $feedUtil->getB2BFeed(
|
|
new B2BFeedDefinition(
|
|
category: $category,
|
|
userHash: $hash,
|
|
format: $format,
|
|
currency: Contexts::get(CurrencyContext::class)->getOrDefault($currency)->getId(),
|
|
type: $type,
|
|
language: $language,
|
|
),
|
|
$download
|
|
);
|
|
|
|
if (!$response) {
|
|
throw new NotFoundHttpException('Feed not found');
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
}
|