Kaynağa Gözat

Creation MerchantResolver

feature/ticket
Fab 3 yıl önce
ebeveyn
işleme
54b93d3936
1 değiştirilmiş dosya ile 55 ekleme ve 1 silme
  1. +55
    -1
      Resolver/MerchantResolver.php

+ 55
- 1
Resolver/MerchantResolver.php Dosyayı Görüntüle

@@ -7,13 +7,67 @@
namespace Lc\CaracoleBundle\Resolver;


use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\SovBundle\Resolver\UrlResolver;
use Symfony\Component\HttpFoundation\RequestStack;

class MerchantResolver
{
protected $requestStack;
protected $em;
protected $urlResolver;

public function __construct(EntityManagerInterface $entityManager, RequestStack $requestStack, UrlResolver $urlResolver)
{
$this->requestStack = $requestStack;
$this->em = $entityManager;
$this->urlResolver = $urlResolver;
}

public function getCurrent(): MerchantInterface
{
//return ;
/* if($currentMerchant) {
return $currentMerchant ;
}*/

$currentMerchant = false;
$request = $this->requestStack->getCurrentRequest();

$merchantRepo = $this->em->getRepository(MerchantInterface::class);
$merchants = $merchantRepo->findAll();

if ($request) {
if ($this->urlResolver->isServerLocalhost()) {
foreach ($merchants as $merchant) {
if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_LOCAL']) {
$currentMerchant = $merchant;
}
}
} // distant
else {
foreach ($merchants as $merchant) {
$url = $merchant->getMerchantConfig('url');
if ($url && strlen($url) && strpos($url, $_SERVER['HTTP_HOST']) !== false) {
$currentMerchant = $merchant;
}
}
}
} else {
/*if ($_ENV['CURRENT_MERCHANT_COMMAND']) {
foreach ($merchants as $merchant) {
if ($merchant->getId() == $_ENV['CURRENT_MERCHANT_COMMAND']) {
$currentMerchant = $merchant;
}
}
}*/
}

if ($currentMerchant instanceof MerchantInterface) {
return $currentMerchant;
} else {
throw new \ErrorException('Aucun merchant courant');
}
}

}

Yükleniyor…
İptal
Kaydet