<?php
declare(strict_types=0);
/*
* WellCommerce Foundation
*
* This file is part of the WellCommerce package.
*
* (c) Adam Piotrowski <adam@wellcommerce.org>, Adrian Potepa <adrian@wellcommerce.org>
*
* For the full copyright and license information,
* please view the LICENSE file that was distributed with this source code.
*/
namespace WellCommerce\Bundle\AppBundle\Repository;
use Doctrine\Persistence\ManagerRegistry;
use WellCommerce\Bundle\AppBundle\Entity\Shop;
use WellCommerce\Bundle\CoreBundle\Doctrine\Repository\EntityRepository;
/**
* Class ShopRepository
*
* @author Adam Piotrowski <adam@wellcommerce.org>
*/
class ShopRepository extends EntityRepository
{
public function __construct(ManagerRegistry $registry, string $className = Shop::class)
{
parent::__construct($registry, $className);
}
public function resolve(int $currentShopId, string $url): Shop
{
if (0 === $currentShopId) {
$currentShop = $this->findOneBy(['url' => $url]);
if ($currentShop instanceof Shop) {
return $currentShop;
}
}
$currentShop = $this->find($currentShopId);
if ($currentShop instanceof Shop) {
return $currentShop;
}
return $this->findOneBy([]);
}
}