Browse Source

Gestion de l'éligibilité

reduction
Guillaume 4 years ago
parent
commit
0ec8dc3d07
6 changed files with 102 additions and 8 deletions
  1. +57
    -0
      ShopBundle/Controller/CitiesController.php
  2. +0
    -4
      ShopBundle/Form/RegistrationType.php
  3. +2
    -2
      ShopBundle/Repository/BaseRepository.php
  4. +1
    -1
      ShopBundle/Repository/ProductCategoryRepository.php
  5. +0
    -1
      ShopBundle/Resources/translations/lcshop.fr.yaml
  6. +42
    -0
      ShopBundle/Services/Cities.php

+ 57
- 0
ShopBundle/Controller/CitiesController.php View File

@@ -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) ;
}


}

+ 0
- 4
ShopBundle/Form/RegistrationType.php View File

@@ -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
]);
}


+ 2
- 2
ShopBundle/Repository/BaseRepository.php View File

@@ -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()

+ 1
- 1
ShopBundle/Repository/ProductCategoryRepository.php View File

@@ -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')

+ 0
- 1
ShopBundle/Resources/translations/lcshop.fr.yaml View File

@@ -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

+ 42
- 0
ShopBundle/Services/Cities.php View File

@@ -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;
}
}

Loading…
Cancel
Save