<?php
namespace AdminBundle\Admin\Vehicles\Passenger;
use Exception;
use AdminBundle\Admin\Vehicles\BaseInStockAdmin;
use CoreBundle\Entity\Vehicles\InStock;
use CoreBundle\Model\Vehicles\InStockVehicle as InStockVehicleModel;
use CoreBundle\Model\Vehicles\VehicleType;
class InStockAdmin extends BaseInStockAdmin
{
protected $baseRouteName = 'in-stock-passenger';
protected $baseRoutePattern = 'in-stock-passenger-action';
protected function getVehicleType(): int {
return VehicleType::PASSENGER_TYPE;
}
protected function getVariationAdminCode(): string
{
return 'admin.vehicles.passenger_variation';
}
protected function getVehicleAdminCode(): string
{
return 'admin.vehicles.passenger_vehicle';
}
private function getPhotos(InStockVehicleModel $inStock) {
$twig = $this->getConfigurationPool()->getContainer()->get('sonata.media.twig.extension');
$result = [];
foreach ($inStock->getGallery()->getGalleryItems() as $galleryItem) {
$result[] = 'https://vidi.ua'.$twig->path($galleryItem, 'reference');
}
return $result;
}
/**
* @param InStock $object
* @return void
* @throws Exception
*/
public function prePersistf($object)
{
$autoRia = $this->getConfigurationPool()->getContainer()->get('core.autoria.api');
$inStock = $this->getConfigurationPool()->getContainer()->get('core.factory.in-stock-vehicle')->createByEntity($object);
$data = [
'currencyId' => 2,
'price' => $inStock->price(),
'categoryId' => 1,
'markaId' => $inStock->getBrand()->getRiaId(),
'modelId' => $inStock->getModel()->getRiaId(),
'baseId' => $inStock->getModel()->getId(),
'equipId' => $inStock->getEquipment()->getId(),
'year' => $inStock->getEquipment()->getId(),
'inStock' => 1,
'testDrive' => 1,
'withoutFirstRegistration' => 0,
'description' => $inStock->getContent('ua'),
'vinCode' => $inStock->getVin(),
'photos' => $this->getPhotos($inStock),
];
$result = $autoRia->addNewVehicle($data);
parent::prePersist($object);
}
}