Files
kupshop/bundles/KupShop/GraphQLBundle/ApiPublic/Controller/SellerController.php
2025-08-02 16:30:27 +02:00

44 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
namespace KupShop\GraphQLBundle\ApiPublic\Controller;
use KupShop\GraphQLBundle\ApiAdmin\Annotation\Module;
use KupShop\GraphQLBundle\ApiShared\Types\Seller\Seller;
use KupShop\KupShopBundle\Util\Contexts;
use KupShop\SellerBundle\Context\SellerContext;
use KupShop\SellerBundle\Utils\SellerUtil;
use TheCodingMachine\GraphQLite\Annotations\Query;
class SellerController
{
public function __construct(private ?SellerUtil $sellerUtil)
{
}
/**
* Načte aktivní prodejnu.
*/
#[Query]
#[Module(\Modules::JS_SHOP)]
public function seller(): ?Seller
{
if (!findModule(\Modules::SELLERS)) {
return null;
}
$sellerContext = Contexts::get(SellerContext::class);
$sellerId = $sellerContext->getActiveId();
if ($sellerId && ($seller = $this->sellerUtil->getSeller((int) $sellerId))) {
$sellerContext->remember($sellerId);
return new Seller($seller);
}
return null;
}
}