src/Controller/Api/CheckoutController.php line 185

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api;
  3. use App\Env;
  4. use App\Func;
  5. use stdClass;
  6. use App\Entity\City;
  7. use App\Entity\Page;
  8. use App\Entity\User;
  9. use App\Entity\Region;
  10. use App\Entity\Esystem;
  11. use App\Entity\Delivery;
  12. use App\Service\Auth\Auth;
  13. use App\Service\Cart\Cart;
  14. use App\Repository\CityRepository;
  15. use App\Repository\UserRepository;
  16. use App\Service\Checkout\Checkout;
  17. use App\Repository\RegionRepository;
  18. use App\Repository\EsystemRepository;
  19. use App\Repository\DeliveryRepository;
  20. use Doctrine\ORM\EntityManagerInterface;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\Security\Core\Security;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\Routing\Annotation\Route;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. class CheckoutController extends AbstractController
  27. {
  28.     protected EntityManagerInterface $em;
  29.     protected $default_region_id '0c5b2444-70a0-4932-980c-b4dc0d3f02b5';
  30.     protected $default_city_id '0c5b2444-70a0-4932-980c-b4dc0d3f02b5';
  31.     protected Checkout $Checkout;
  32.     protected Cart $Cart;
  33.     protected User $User;
  34.     protected Auth $Auth;
  35.     //Repositories    
  36.     protected RegionRepository $Regions;
  37.     protected CityRepository $Cities;
  38.     protected DeliveryRepository $Deliveries;
  39.     protected EsystemRepository $Esystems;
  40.     protected UserRepository $Users;
  41.     public function __construct(EntityManagerInterface $emCheckout $CheckoutCart $CartAuth $AuthSecurity $security)
  42.     {
  43.         if (Env::site() == Env::DOM || Env::site() == Env::OPT) {
  44.             $this->default_region_id 'dcaadb64-4b33-11e4-ab6d-005056801329';
  45.             $this->default_city_id 'e718a680-4b33-11e4-ab6d-005056801329';
  46.         }
  47.         $this->em $em;
  48.         $this->Checkout $Checkout;
  49.         $this->Cart $Cart;
  50.         $this->Auth $Auth;
  51.         $this->Auth->setUser($security->getUser());
  52.         $this->Regions $this->em->getRepository(Region::class);
  53.         $this->Cities $this->em->getRepository(City::class);
  54.         $this->Deliveries $this->em->getRepository(Delivery::class);
  55.         $this->Esystems $this->em->getRepository(Esystem::class);
  56.         $this->Users $this->em->getRepository(User::class);
  57.     }
  58.     // Разделение строки на фамилию, имя, определение пола
  59.     #[Route(path'/api/checkout/cleanname'name'api_checkout_cleanname_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  60.     #[Route(path'/{_locale}/api/checkout/cleanname'name'api_checkout_cleanname'requirements: ['_locale' => '%app.langs%'])]
  61.     public function cleanname(Request $request): Response
  62.     {
  63.         $fullname = (string) $request->query->get('fullname');
  64.         $curl curl_init();
  65.         $headers[] = 'Content-Type: application/json';
  66.         $headers[] = 'Authorization: Token ' Env::code_dadata();
  67.         $headers[] = 'X-Secret: ' Env::code_dadata_2();
  68.         $request = [$fullname];
  69.         curl_setopt($curlCURLOPT_URL"https://cleaner.dadata.ru/api/v1/clean/name");
  70.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  71.         curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  72.         curl_setopt($curlCURLOPT_POSTFIELDSjson_encode($requestJSON_UNESCAPED_UNICODE));
  73.         $response curl_exec($curl);
  74.         $data json_decode($responsetrue)[0];
  75.         $response = [];
  76.         if (($data['name']) && ($data['surname'])) {
  77.             $usersurname $data['surname'];
  78.             $username $data['name'];
  79.             switch ($data['gender']) {
  80.                 case 'Ж':
  81.                     $usergender 'F';
  82.                     break;
  83.                 case 'М':
  84.                     $usergender 'M';
  85.                     break;
  86.                 default:
  87.                     $usergender null;
  88.             }
  89.         }
  90.         $response['username'] = $username;
  91.         $response['usersurname'] = $usersurname;
  92.         $response['usergender'] = $usergender;
  93.         return $this->json($response);
  94.     }
  95.     // Подсказки при вводе ФИО
  96.     #[Route(path'/api/checkout/fiohint'name'api_checkout_fiohint_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  97.     #[Route(path'/{_locale}/api/checkout/fiohint'name'api_checkout_fiohint'requirements: ['_locale' => '%app.langs%'])]
  98.     public function fiohint(Request $request): Response
  99.     {
  100.         $fullname = (string) $request->query->get('fullname');
  101.         $curl curl_init();
  102.         $headers[] = 'Content-Type: application/json';
  103.         $headers[] = 'Authorization: Token ' Env::code_dadata();
  104.         $request = ['query' => $fullname'parts' => ['surname''name'], 'count' => 10];
  105.         curl_setopt($curlCURLOPT_URL"https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/fio");
  106.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  107.         curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  108.         curl_setopt($curlCURLOPT_POSTFIELDSjson_encode($request));
  109.         $response curl_exec($curl);
  110.         $suggestions json_decode($response);
  111.         //var_dump($suggestions);
  112.         $apiResponce = [];
  113.         foreach ($suggestions->suggestions as $suggestion) {
  114.             $obj = new stdClass();
  115.             $obj->value $suggestion->value;
  116.             $obj->name $suggestion->data->name;
  117.             $obj->surname $suggestion->data->surname;
  118.             $obj->gender $suggestion->data->gender;
  119.             $apiResponce[] = $obj;
  120.         }
  121.         return $this->json($apiResponce);
  122.     }
  123.     #[Route(path'/api/checkout/citydetect'name'api_checkout_citydetect_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  124.     #[Route(path'/{_locale}/api/checkout/citydetect'name'api_checkout_citydetect'requirements: ['_locale' => '%app.langs%'])]
  125.     public function citydetect(Request $request): Response
  126.     {
  127.         $city_fias_id $this->Checkout->getCity_fias_id();
  128.         if ($city_fias_id) {
  129.         } else {
  130.             if (Env::site() == env::DOM || Env::site() == env::OPT) {
  131.                 $ip $_SERVER["REMOTE_ADDR"];
  132.                 $request = @file_get_contents("https://api.sypexgeo.net/json/" $ip);
  133.                 $array json_decode($requesttrue);
  134.                 $city_name = isset($array['city']['name_ru']) ? $array['city']['name_ru'] : "";
  135.                 $city $this->Cities->findOneBy(["name" => $city_name]);
  136.                 if (!$city) {
  137.                     $region $this->Regions->findOneBy(['fias_id' => $this->default_region_id]);
  138.                     $city $this->Cities->findOneBy(['fias_id' => $this->default_city_id]);
  139.                     $this->Checkout->setRegion_fias_id($region->getFiasId());
  140.                     $this->Checkout->setRegion_name($region->getName());
  141.                     $this->Checkout->setCity_fias_id($city->getFiasId());
  142.                     $this->Checkout->setCity_name($city->getName());
  143.                     $this->Checkout->setCity_post_code($city->getPostalCode());
  144.                 } else {
  145.                     $region $this->Regions->find($city->getRegion());
  146.                     $this->Checkout->setRegion_fias_id($region->getFiasId());
  147.                     $this->Checkout->setRegion_name($region->getName());
  148.                     $this->Checkout->setCity_fias_id($city->getFiasId());
  149.                     $this->Checkout->setCity_name($city->getName());
  150.                     $this->Checkout->setCity_post_code($city->getPostalCode());
  151.                 }
  152.             } elseif (Env::site() == env::MIR || Env::site() == env::OPT_MIR) {
  153.                 $curl curl_init();
  154.                 $headers[] = 'Accept: application/json';
  155.                 $headers[] = 'Authorization: Token ' Env::code_dadata();
  156.                 curl_setopt($curlCURLOPT_URL"https://suggestions.dadata.ru/suggestions/api/4_1/rs/iplocate/address?ip=" $_SERVER['REMOTE_ADDR']);
  157.                 curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  158.                 curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  159.                 $response json_decode(curl_exec($curl));
  160.                 if ($response->location == null) {
  161.                     $region $this->Regions->findOneBy(['fias_id' => $this->default_region_id]);
  162.                     $city $this->Cities->findOneBy(['fias_id' => $this->default_city_id]);
  163.                     $this->Checkout->setRegion_fias_id($region->getFiasId());
  164.                     $this->Checkout->setRegion_name($region->getName());
  165.                     $this->Checkout->setCity_fias_id($city->getFiasId());
  166.                     $this->Checkout->setCity_name($city->getName());
  167.                     $this->Checkout->setCity_post_code($city->getPostalCode());
  168.                 } else {
  169.                     $this->Checkout->setRegion_fias_id($response->location->data->region_fias_id);
  170.                     $this->Checkout->setRegion_name($response->location->data->region_with_type);
  171.                     $this->Checkout->setCity_fias_id(($response->location->data->settlement_fias_id $response->location->data->settlement_fias_id $response->location->data->city_fias_id));
  172.                     $this->Checkout->setCity_name(($response->location->data->settlement_with_type $response->location->data->settlement_with_type $response->location->data->city_with_type));
  173.                     $this->Checkout->setCity_post_code($response->location->data->postal_code);
  174.                 }
  175.             } else {
  176.                 $this->Checkout->setRegion_fias_id('default');
  177.             }
  178.         }
  179.         return $this->json($this->Checkout->getCheckout());
  180.     }
  181.     // Подсказки при вводе города
  182.     #[Route(path'/api/checkout/citylist'name'api_checkout_citylist_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  183.     #[Route(path'/{_locale}/api/checkout/citylist'name'api_checkout_citylist'requirements: ['_locale' => '%app.langs%'])]
  184.     public function citylist(Request $request): Response
  185.     {
  186.         $q = (string) $request->query->get('string');
  187.         if (Env::site() == env::DOM || Env::site() == env::OPT) {
  188.             /** @var \App\Entity\City[] $cities */
  189.             $cities $this->em->createQuery("SELECT c FROM App\Entity\City c WHERE c.kw LIKE '%" $q "%' ORDER BY c.type ASC")->setMaxResults(10)->getResult(); // Check
  190.             if (count($cities)) {
  191.                 $response = new \stdClass();
  192.                 $response->suggestions = [];
  193.                 foreach ($cities as $city) {
  194.                     $region $this->Regions->find($city->getRegion());
  195.                     if ($region) {
  196.                         $suggestion = new \stdClass();
  197.                         $suggestion->value $city->getType() . ' ' $city->getName() . ", " $region->getName();
  198.                         $suggestion->data = new \stdClass();
  199.                         $suggestion->data->city_fias_id $city->getFiasId();
  200.                         array_push($response->suggestions$suggestion);
  201.                     }
  202.                 }
  203.             } else {
  204.                 $response = new \stdClass();
  205.                 $response->suggestions = [];
  206.             }
  207.         } else {
  208.             $curl curl_init();
  209.             $headers[] = 'Content-Type: application/json';
  210.             $headers[] = 'Accept: application/json';
  211.             $headers[] = 'Authorization: Token ' Env::code_dadata();
  212.             $request = ['query' => $q'from_bound' => ['value' => 'city'], 'to_bound' => ['value' => 'settlement'], 'count' => 10];
  213.             curl_setopt($curlCURLOPT_URL"https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address");
  214.             curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  215.             curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  216.             curl_setopt($curlCURLOPT_POSTFIELDSjson_encode($requestJSON_UNESCAPED_UNICODE));
  217.             $response curl_exec($curl);
  218.             $response json_decode($response);
  219.         }
  220.         return $this->json($response);
  221.     }
  222.     // Выбор города
  223.     #[Route(path'/api/checkout/selectcity'name'api_checkout_selectcity_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  224.     #[Route(path'/{_locale}/api/checkout/selectcity'name'api_checkout_selectcity'requirements: ['_locale' => '%app.langs%'])]
  225.     public function selectcity(Request $requestCheckout $Checkout): Response
  226.     {
  227.         $fias_id = (string) $request->query->get('fias_id');
  228.         if ($fias_id) {
  229.             if (Env::site() == env::DOM || Env::site() == env::OPT) {
  230.                 $city $this->Cities->findOneBy(['fias_id' => $fias_id]); // Check
  231.                 if ($city->getId()) {
  232.                     $region $this->Regions->find($city->getRegion());
  233.                     if ($region) {
  234.                         $Checkout->setRegion_fias_id($region->getFiasId());
  235.                         $Checkout->setRegion_name($region->getName());
  236.                         $Checkout->setCity_fias_id($city->getFiasId());
  237.                         $Checkout->setCity_name($city->getName());
  238.                         $Checkout->setCity_post_code($city->getPostalCode());
  239.                         $Checkout->setUseraddr('');
  240.                         $Checkout->setUserlat('');
  241.                         $Checkout->setUserlon('');
  242.                         $Checkout->setDelivery_post_code('');
  243.                         $Checkout->setDelivery_post_name('');
  244.                         $Checkout->setDelivery_post_worktime('');
  245.                         $Checkout->setDelivery_post_phone('');
  246.                         $Checkout->setDelivery_post_email('');
  247.                         $Checkout->setDelivery_sub_id(0);
  248.                         $Checkout->setDelivery_sub_name('');
  249.                         $Checkout->setDelivery_cost(0);
  250.                     }
  251.                 }
  252.             } else {
  253.                 $curl curl_init();
  254.                 $headers[] = 'Content-Type: application/json';
  255.                 $headers[] = 'Accept: application/json';
  256.                 $headers[] = 'Authorization: Token ' Env::code_dadata();
  257.                 $request = ['query' => $fias_id];
  258.                 curl_setopt($curlCURLOPT_URL"https://suggestions.dadata.ru/suggestions/api/4_1/rs/findById/address");
  259.                 curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  260.                 curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  261.                 curl_setopt($curlCURLOPT_POSTFIELDSjson_encode($request));
  262.                 $response json_decode(curl_exec($curl));
  263.                 if (!count($response->suggestions)) {
  264.                     $region $this->Regions->findOneBy(['fias_id' => $this->default_region_id]);
  265.                     $city $this->Cities->findOneBy(['fias_id' => $this->default_city_id]);
  266.                     $Checkout->setRegion_fias_id($region->getFiasId());
  267.                     $Checkout->setRegion_name($region->getName());
  268.                     $Checkout->setCity_fias_id($city->getFiasId());
  269.                     $Checkout->setCity_name($city->getName());
  270.                     $Checkout->setCity_post_code($city->getPostalCode());
  271.                     $Checkout->setUseraddr('');
  272.                     $Checkout->setUserlat('');
  273.                     $Checkout->setUserlon('');
  274.                     $Checkout->setDelivery_post_code('');
  275.                     $Checkout->setDelivery_post_name('');
  276.                     $Checkout->setDelivery_post_worktime('');
  277.                     $Checkout->setDelivery_post_phone('');
  278.                     $Checkout->setDelivery_post_email('');
  279.                     $Checkout->setDelivery_sub_id(0);
  280.                     $Checkout->setDelivery_sub_name('');
  281.                     $Checkout->setDelivery_cost(0);
  282.                 } else {
  283.                     $Checkout->setRegion_fias_id($response->suggestions[0]->data->region_fias_id);
  284.                     $Checkout->setRegion_name($response->suggestions[0]->data->region_with_type);
  285.                     $Checkout->setCity_fias_id(($response->suggestions[0]->data->settlement_fias_id $response->suggestions[0]->data->settlement_fias_id $response->suggestions[0]->data->city_fias_id));
  286.                     $Checkout->setCity_name(($response->suggestions[0]->data->settlement_with_type $response->suggestions[0]->data->settlement_with_type $response->suggestions[0]->data->city_with_type));
  287.                     $Checkout->setCity_post_code($response->suggestions[0]->data->postal_code);
  288.                     $city $this->Cities->findOneBy(['fias_id' => $Checkout->getCity_fias_id()]);
  289.                     if ($city->getPostalCode()) {
  290.                         $Checkout->setCity_post_code($city->getPostalCode());
  291.                     }
  292.                     $Checkout->setUseraddr('');
  293.                     $Checkout->setUserlat('');
  294.                     $Checkout->setUserlon('');
  295.                     $Checkout->setDelivery_post_code('');
  296.                     $Checkout->setDelivery_post_name('');
  297.                     $Checkout->setDelivery_post_worktime('');
  298.                     $Checkout->setDelivery_post_phone('');
  299.                     $Checkout->setDelivery_post_email('');
  300.                     $Checkout->setDelivery_sub_id(0);
  301.                     $Checkout->setDelivery_sub_name('');
  302.                     $Checkout->setDelivery_cost(0);
  303.                 }
  304.             }
  305.         }
  306.         return $this->json($Checkout->getCheckout());
  307.     }
  308.     // Подсказки при вводе адреса
  309.     #[Route(path'/api/checkout/addresslist'name'api_checkout_addresslist_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  310.     #[Route(path'/{_locale}/api/checkout/addresslist'name'api_checkout_addresslist'requirements: ['_locale' => '%app.langs%'])]
  311.     public function addressList(Request $requestCheckout $Checkout): Response
  312.     {
  313.         $q = (string) $request->query->get('string');
  314.         $curl curl_init();
  315.         $headers[] = 'Content-Type: application/json';
  316.         $headers[] = 'Accept: application/json';
  317.         $headers[] = 'Authorization: Token ' Env::code_dadata();
  318.         $request = ['query' => $q'locations' => ['city_fias_id' => $Checkout->getCity_fias_id(), ['settlement_fias_id' => $Checkout->getCity_fias_id()]], 'from_bound' => ['value' => 'street'], 'to_bound' => ['value' => 'flat'], 'count' => 10];
  319.         curl_setopt($curlCURLOPT_URL"https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/address");
  320.         curl_setopt($curlCURLOPT_RETURNTRANSFERtrue);
  321.         curl_setopt($curlCURLOPT_HTTPHEADER$headers);
  322.         curl_setopt($curlCURLOPT_POSTFIELDSjson_encode($request));
  323.         $response json_decode(curl_exec($curl), true);
  324.         return $this->json($response);
  325.     }
  326.     // Get Session Vars
  327.     #[Route(path'/api/checkout/get-session-vars'name'api_checkout_get_session_vars_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  328.     #[Route(path'/{_locale}/api/checkout/get-session-vars'name'api_checkout_get_session_vars'requirements: ['_locale' => '%app.langs%'])]
  329.     public function getSessionVars(): Response
  330.     {
  331.         $result = [
  332.             'amount_delivery' => Func::fmtmoney($this->Cart->getAmountDelivery()),
  333.             'amount_with_delivery' => Func::fmtmoney($this->Cart->getAmountWithDelivery()),
  334.             'userlat' => $this->Checkout->getUserlat(),
  335.             'userlon' => $this->Checkout->getUserlon(),
  336.             'delivery_id' => (int) $this->Checkout->getDelivery_id(),
  337.             'delivery_intname' => $this->Checkout->getDelivery_intname(),
  338.             'delivery_name' => $this->Checkout->getDelivery_name(),
  339.             'delivery_post_code' => $this->Checkout->getDelivery_post_code(),
  340.         ];
  341.         return $this->json($result);
  342.     }
  343.     // Выбор сервиса доставки
  344.     #[Route(path'/api/checkout/select-type/{delivery_id}'name'api_checkout_select_type_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  345.     #[Route(path'/{_locale}/api/checkout/select-type/{delivery_id}'name'api_checkout_select_type'requirements: ['_locale' => '%app.langs%'])]
  346.     public function selectType(int $delivery_id 0): Response
  347.     {
  348.         $delivery $this->Deliveries->find($delivery_id);
  349.         if ($delivery) {
  350.             $this->Checkout->setDelivery_id($delivery->getId());
  351.             $this->Checkout->setDelivery_intname($delivery->getIntname());
  352.             $this->Checkout->setDelivery_name($delivery->getName());
  353.             $result = [
  354.                 'error' => null,
  355.                 'delivery_id' => $delivery->getId(),
  356.                 'delivery_intname' => $delivery->getIntname(),
  357.                 'delivery_name' => $delivery->getName(),
  358.             ];
  359.         } else {
  360.             $result = [
  361.                 "error" => "wrong delivery id",
  362.             ];
  363.         }
  364.         return $this->json($result);
  365.     }
  366.     // Выбор варианта доставки
  367.     #[Route(path'/api/checkout/select-price/{sub_id}/{sub_code}/{sub_name}/{cost}'name'api_checkout_select_price_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  368.     #[Route(path'/{_locale}/api/checkout/select-price/{sub_id}/{sub_code}/{sub_name}/{cost}'name'api_checkout_select_price'requirements: ['_locale' => '%app.langs%'])]
  369.     public function selectPrice(int $sub_id 0string $sub_code ''string $sub_name ''string $cost ''): Response
  370.     {
  371.         $this->Checkout->setDelivery_sub_id($sub_id);
  372.         $this->Checkout->setDelivery_sub_code($sub_code);
  373.         $this->Checkout->setDelivery_sub_name($sub_name);
  374.         $this->Checkout->setDelivery_cost($cost);
  375.         $result = [
  376.             'error' => null,
  377.             'delivery_sub_id' => $sub_id,
  378.             'delivery_sub_code' => $sub_code,
  379.             'delivery_sub_name' => $sub_name,
  380.             'delivery_cost' => $cost,
  381.         ];
  382.         return $this->json($result);
  383.     }
  384.     // Изменение цены доставки
  385.     #[Route(path'/api/checkout/set-price/{cost}'name'api_checkout_set_price_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  386.     #[Route(path'/{_locale}/api/checkout/set-price/{cost}'name'api_checkout_set_price'requirements: ['_locale' => '%app.langs%'])]
  387.     public function setPrice($cost ''): Response
  388.     {
  389.         $this->Checkout->setDelivery_cost($cost);
  390.         $result = [
  391.             'delivery_cost' => $cost,
  392.         ];
  393.         return $this->json($result);
  394.     }
  395.     // Выбор отделения доставки
  396.     #[Route(path'/api/checkout/select-code/{code}/{name}/{worktime}/{phone}/{email}'name'api_checkout_select_code_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  397.     #[Route(path'/{_locale}/api/checkout/select-code/{code}/{name}/{worktime}/{phone}/{email}'name'api_checkout_select_code'requirements: ['_locale' => '%app.langs%'])]
  398.     public function selectCode(string $code ''string $name ''string $worktime ''string $phone ''string $email ''): Response
  399.     {
  400.         $this->Checkout->setUserlat('');
  401.         $this->Checkout->setDelivery_post_code($code);
  402.         $this->Checkout->setDelivery_post_name($name);
  403.         $this->Checkout->setDelivery_post_worktime($worktime);
  404.         $this->Checkout->setDelivery_post_phone($phone);
  405.         $this->Checkout->setDelivery_post_email($email);
  406.         $result = [
  407.             'error' => null,
  408.             'delivery_post_code' => $code,
  409.             'delivery_post_name' => $name,
  410.             'delivery_post_worktime' => $worktime,
  411.             'delivery_post_phone' => $phone,
  412.             'delivery_post_email' => $email,
  413.         ];
  414.         return $this->json($result);
  415.     }
  416.     // Выбор отделения доставки
  417.     #[Route(path'/api/checkout/select-address/{addr}/{lat}/{lon}'name'api_checkout_select-address_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  418.     #[Route(path'/{_locale}/api/checkout/select-address/{addr}/{lat}/{lon}'name'api_checkout_select-address'requirements: ['_locale' => '%app.langs%'])]
  419.     public function selectAddress(string $addr ''string $lat ''string $lon ''): Response
  420.     {
  421.         $this->Checkout->setUseraddr($addr);
  422.         $this->Checkout->setUserlat($lat);
  423.         $this->Checkout->setUserlon($lon);
  424.         $result = [
  425.             'useraddr' => $addr,
  426.             'userlat' => $lat,
  427.             'userlon' => $lon,
  428.         ];
  429.         return $this->json($result);
  430.     }
  431.     // Выбор способа оплаты
  432.     #[Route(path'/api/checkout/payment/select-type/{id}'name'checkout_payment_select_type_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  433.     #[Route(path'/{_locale}/api/checkout/payment/select-type/{id}'name'checkout_payment_select_type'requirements: ['_locale' => '%app.langs%'])]
  434.     public function payment(int $id): Response
  435.     {
  436.         $esystem $this->Esystems->find($id);
  437.         if ($esystem) {
  438.             $this->Checkout->setPayment_id($id);
  439.             $this->Checkout->setPayment_name($esystem->getName());
  440.             $result = [
  441.                 'payment_id' => $id,
  442.                 'payment_name' => $esystem->getName(),
  443.             ];
  444.         } else {
  445.             $result = [
  446.                 'error' => "wrong id",
  447.             ];
  448.         }
  449.         return $this->json($result);
  450.     }
  451.     // Данные компании
  452.     #[Route(path'/api/checkout/payment/company-data'name'checkout_payment_company_data_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  453.     #[Route(path'/{_locale}/api/checkout/payment/company-data'name'checkout_payment_company_data'requirements: ['_locale' => '%app.langs%'])]
  454.     public function companyData(Request $request): Response
  455.     {      
  456.         $company_nip $request->get('company_nip');
  457.         $company_name $request->get('company_name');
  458.         $company_index $request->get('company_index');
  459.         $company_city $request->get('company_city');
  460.         $company_street $request->get('company_street');
  461.         $company_house $request->get('company_house');
  462.         $company_flat $request->get('company_flat');
  463.         $this->Checkout->setCompanyNip($company_nip);
  464.         $this->Checkout->setCompanyName($company_name);
  465.         $this->Checkout->setCompanyIndex($company_index);
  466.         $this->Checkout->setCompanyCity($company_city);
  467.         $this->Checkout->setCompanyStreet($company_street);
  468.         $this->Checkout->setCompanyHouse($company_house);
  469.         $this->Checkout->setCompanyFlat($company_flat);
  470.         if($this->Auth->getUserId()) {
  471.             $user $this->Users->find($this->Auth->getUserId());
  472.             $user->setCompanyNip($company_nip);
  473.             $user->setCompanyName($company_name);
  474.             $user->setCompanyIndex($company_index);
  475.             $user->setCompanyCity($company_city);
  476.             $user->setCompanyStreet($company_street);
  477.             $user->setCompanyHouse($company_house);
  478.             $user->setCompanyFlat($company_flat);
  479.             $this->em->persist($user);
  480.             $this->em->flush();
  481.         }
  482.         return $this->json(true);
  483.     }
  484.     // Очистка данных компании
  485.     #[Route(path'/api/checkout/payment/clear-company-data'name'checkout_payment_clear_company_data_no_locale'defaults: ['_locale' => '%app.default_lang%'])]
  486.     #[Route(path'/{_locale}/api/checkout/payment/clear-company-data'name'checkout_payment_clear_company_data'requirements: ['_locale' => '%app.langs%'])]
  487.     public function clearCompanyData(): Response
  488.     {
  489.         $this->Checkout->setCompanyNip('');
  490.         $this->Checkout->setCompanyName('');
  491.         $this->Checkout->setCompanyIndex('');
  492.         $this->Checkout->setCompanyCity('');
  493.         $this->Checkout->setCompanyStreet('');
  494.         $this->Checkout->setCompanyHouse('');
  495.         $this->Checkout->setCompanyFlat('');
  496.         return $this->json(true);
  497.     }
  498. }