@php $body->load(['model.mark', 'color', 'price.modification', 'price.complectation']); $params = \JustWeCMS\Modules\Param\Entities\Param::whereIn('slug', [ 'name_salon', 'percent_rate', 'percent_rate_formula', 'credit_terms', 'down_payment', 'koef_price' ])->pluck('value', 'slug'); $markName = trim((string) optional($body->model->mark)->name); $modelName = trim((string) optional($body->model)->name); $bodyName = trim((string) ($body->name ?: ($body->generation ?: $body->slug))); $fullName = trim($markName . ' ' . $modelName . ' ' . $bodyName); $imageUrl = function ($path) { if (empty($path)) { return assets_url() . '/img/car-img-1.png'; } return preg_match('/^https?:\/\//', $path) ? $path : url($path); }; $colors = $body->color->sortBy('position')->values(); $mainImage = $colors->first() && !empty($colors->first()->picture) ? $colors->first()->picture : ($body->preview ?: assets_url() . '/img/car-img-1.png'); $modification = $body->modification->sortBy('position')->first(); if (!$modification) { $modification = optional($body->price->sortBy('id')->first())->modification; } $typeLabel = method_exists($body, 'getTypeBody') ? $body->getTypeBody() : $body->type; $typeLabel = $typeLabel ?: null; $gearboxLabel = optional($modification)->gearbox ?: null; $powerLabel = optional($modification)->power ? optional($modification)->power . ' л.с.' : null; $speedLabel = optional($modification)->max_speed ? optional($modification)->max_speed . ' км/ч' : null; $accelerationLabel = optional($modification)->acceleration_100km ? optional($modification)->acceleration_100km . ' сек.' : null; $consumptionValue = optional($modification)->consume_mixed ?: optional($modification)->consume_city; $consumptionLabel = $consumptionValue ? $consumptionValue . ' л' : null; if(isset($body->title) AND !empty($body->title)) { $title = $body->title; } else { $title = sprintf( 'Купить %s %s по выгодной цене | %s', $body->model->mark->name, $body->model->name, \JustWeCMS\Modules\Param\Entities\Param::where('slug', 'name_salon')->first()->value ); } if(isset($body->description) AND !empty($body->description)) { $description = $body->description; } else { $description = sprintf( 'Продажа новых автомобилей %s %s в автосалоне «%s».', $body->model->mark->name, $body->model->name, \JustWeCMS\Modules\Param\Entities\Param::where('slug', 'name_salon')->first()->value, $body->model->mark->name, $body->model->name ); } if(isset($body->og_title) AND !empty($body->og_title)) { $og_title = $body->og_title; } else { $og_title = $title; } if(isset($body->og_description) AND !empty($body->og_description)) { $og_description = $body->og_description; } else { $og_description = $description; } $minPrice = $body->getMinPrice(); $priceOld = $body->getMinPrice('price_old'); $creditPercent = (float) str_replace(',', '.', $params['percent_rate_formula'] ?? 0); $displayRate = trim((string) ($params['percent_rate'] ?? '')); $creditTerm = max(1, (int) ($params['credit_terms'] ?? 60)); $downPaymentRate = (float) str_replace(',', '.', $params['down_payment'] ?? 0) / 100; $creditCoefficient = (float) str_replace(',', '.', $params['koef_price'] ?? 1); $creditPerMount = \JustWeCMS\Modules\Auto\Entities\Price::calcMountPayment( $minPrice, $creditPercent, $creditTerm, $downPaymentRate ) * $creditCoefficient; $priceField = $body->price->where('price', $body->getMinPrice())->first(); $carCount = !empty($body->place_count) ? (int) $body->place_count : abs(trim(crc32($body->id))) % 10 + 1;