@@ -0,0 +1,57 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Controller ; | |||
use Lc\ShopBundle\Services\Cities; | |||
use Symfony\Component\HttpFoundation\Request; | |||
use Symfony\Component\HttpFoundation\JsonResponse; | |||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
class CitiesController extends AbstractController | |||
{ | |||
protected $cities ; | |||
public function __construct(Cities $cities) | |||
{ | |||
$this->cities = $cities ; | |||
} | |||
public function index(Request $request) : JsonResponse | |||
{ | |||
$term = $request->get('term') ; | |||
$context = $request->get('context') ; | |||
$data = [ | |||
'boost' => 'population', | |||
] ; | |||
if(strlen($term) == 5) { | |||
$data['codePostal'] = $term ; | |||
} | |||
else { | |||
$data['nom'] = $term; | |||
} | |||
$result = array_merge( | |||
json_decode($this->cities->callApi('get', 'communes', array_merge($data, ['codeRegion' => 27]))), | |||
json_decode($this->cities->callApi('get', 'communes', array_merge($data, ['codeRegion' => 44]))) | |||
); | |||
$return = [] ; | |||
foreach($result as $city) { | |||
$return[] = [ | |||
'label' => $city->nom, | |||
'value' => $city->code | |||
] ; | |||
} | |||
if($context == 'frontend') { | |||
$return = [ | |||
'items' => $return | |||
] ; | |||
} | |||
return new JsonResponse($return) ; | |||
} | |||
} |
@@ -33,10 +33,6 @@ class RegistrationType extends AbstractType | |||
]) | |||
->add('lastName', TextType::class, [ | |||
'label' => 'Nom' | |||
]) | |||
->add('isSubscribedNewsletter', CheckboxType::class, [ | |||
'label' => 'S\'inscrire à la newsletter', | |||
'required' => false | |||
]); | |||
} | |||
@@ -25,11 +25,11 @@ class BaseRepository extends EntityRepository implements ServiceEntityRepository | |||
} | |||
public function findByMerchantQuery($merchant) | |||
public function findByMerchantQuery() | |||
{ | |||
return $this->createQueryBuilder('e') | |||
->where('e.merchant = :currentMerchant') | |||
->setParameter('currentMerchant', $merchant->getId()) ; | |||
->setParameter('currentMerchant', $this->globalParam->getCurrentMerchant()->getId()) ; | |||
} | |||
public function findAll() |
@@ -30,7 +30,7 @@ class ProductCategoryRepository extends BaseRepository implements DefaultReposit | |||
public function findAllParents() | |||
{ | |||
return $this->findByMerchantQuery($this->globalParam->getCurrentMerchant()) | |||
return $this->findByMerchantQuery() | |||
->andWhere('e.parent is NULL') | |||
->andWhere('e.status >= 0') | |||
->orderBy('e.position', 'ASC') |
@@ -52,7 +52,6 @@ field: | |||
roles: Rôle attribué | |||
addresses: Adresses | |||
enabled: Activé | |||
isSubscribedNewsletter: Inscris à la newsletter | |||
zips: Codes postaux | |||
cities: Villes | |||
orderPriceMin: Montant minimum de commande |
@@ -0,0 +1,42 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Services ; | |||
class Cities | |||
{ | |||
function callApi($method, $url, $data = false) | |||
{ | |||
$url = 'https://geo.api.gouv.fr/'.$url ; | |||
$curl = curl_init(); | |||
switch ($method) | |||
{ | |||
case "POST": | |||
curl_setopt($curl, CURLOPT_POST, 1); | |||
if ($data) | |||
curl_setopt($curl, CURLOPT_POSTFIELDS, $data); | |||
break; | |||
case "PUT": | |||
curl_setopt($curl, CURLOPT_PUT, 1); | |||
break; | |||
default: | |||
if ($data) | |||
$url = sprintf("%s?%s", $url, http_build_query($data)); | |||
} | |||
// Optional Authentication: | |||
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); | |||
curl_setopt($curl, CURLOPT_USERPWD, "username:password"); | |||
curl_setopt($curl, CURLOPT_URL, $url); | |||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); | |||
$result = curl_exec($curl); | |||
curl_close($curl); | |||
return $result; | |||
} | |||
} |