src/AdminBundle/Admin/Vehicles/Passenger/InStockAdmin.php line 10

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Admin\Vehicles\Passenger;
  3. use Exception;
  4. use AdminBundle\Admin\Vehicles\BaseInStockAdmin;
  5. use CoreBundle\Entity\Vehicles\InStock;
  6. use CoreBundle\Model\Vehicles\InStockVehicle as InStockVehicleModel;
  7. use CoreBundle\Model\Vehicles\VehicleType;
  8. class InStockAdmin extends BaseInStockAdmin
  9. {
  10.     protected $baseRouteName 'in-stock-passenger';
  11.     protected $baseRoutePattern 'in-stock-passenger-action';
  12.     protected function getVehicleType(): int {
  13.         return VehicleType::PASSENGER_TYPE;
  14.     }
  15.     protected function getVariationAdminCode(): string
  16.     {
  17.         return 'admin.vehicles.passenger_variation';
  18.     }
  19.     protected function getVehicleAdminCode(): string
  20.     {
  21.         return 'admin.vehicles.passenger_vehicle';
  22.     }
  23.     private function getPhotos(InStockVehicleModel $inStock) {
  24.         $twig $this->getConfigurationPool()->getContainer()->get('sonata.media.twig.extension');
  25.         $result = [];
  26.         foreach ($inStock->getGallery()->getGalleryItems() as $galleryItem) {
  27.             $result[] = 'https://vidi.ua'.$twig->path($galleryItem'reference');
  28.         }
  29.         return $result;
  30.     }
  31.     /**
  32.      * @param InStock $object
  33.      * @return void
  34.      * @throws Exception
  35.      */
  36.     public function prePersistf($object)
  37.     {
  38.         $autoRia $this->getConfigurationPool()->getContainer()->get('core.autoria.api');
  39.         $inStock $this->getConfigurationPool()->getContainer()->get('core.factory.in-stock-vehicle')->createByEntity($object);
  40.         $data = [
  41.             'currencyId' => 2,
  42.             'price' => $inStock->price(),
  43.             'categoryId' => 1,
  44.             'markaId' => $inStock->getBrand()->getRiaId(),
  45.             'modelId' => $inStock->getModel()->getRiaId(),
  46.             'baseId' => $inStock->getModel()->getId(),
  47.             'equipId' => $inStock->getEquipment()->getId(),
  48.             'year' => $inStock->getEquipment()->getId(),
  49.             'inStock' => 1,
  50.             'testDrive' => 1,
  51.             'withoutFirstRegistration' => 0,
  52.             'description' => $inStock->getContent('ua'),
  53.             'vinCode' => $inStock->getVin(),
  54.             'photos' => $this->getPhotos($inStock),
  55.         ];
  56.         $result $autoRia->addNewVehicle($data);
  57.         parent::prePersist($object);
  58.     }
  59. }