Country stats and searching by exact model name.
All checks were successful
/ deploy-job (push) Successful in 0s

This commit is contained in:
2026-02-24 08:44:23 +01:00
parent 59f10e620f
commit 0da1aa4ff6
5 changed files with 49 additions and 9 deletions

View File

@@ -10,19 +10,31 @@ use Symfony\Component\Routing\Attribute\Route;
final class CountryController extends BaseController final class CountryController extends BaseController
{ {
#[Route('/country/{country?}', name: 'app_country')] #[Route('/country/{countryName?}', name: 'app_country')]
public function __invoke(?string $country): Response public function __invoke(?string $countryName): Response
{ {
/** @var Product[] $products */ /** @var Product[] $products */
$products = Product::with(['price', 'lowestPrice', 'country']) $products = Product::with(['price', 'lowestPrice', 'country'])
->join('countries', 'countries.id', '=', 'products.country_id') ->join('countries', 'countries.id', '=', 'products.country_id')
->where('countryName', $country) ->where('countryName', $countryName)
->orderByDesc('starred') ->orderByDesc('starred')
->orderByDesc('created_by') ->orderByDesc('created_by')
->get(); ->get();
$country = Country::where('countryName', $country)->first(); $country = Country::where('countryName', $countryName)->first();
return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'country', 'country' => $country]); return $this->render('productList.html.twig', ['products' => $products, 'listType' => 'country', 'country' => $country, 'countryStats' => $this->countryStats($countryName)]);
}
private function countryStats(string $country): array
{
$countryProducts = Product::join('countries', 'countries.id', '=', 'products.country_id')
->where('countryName', $country);
$stats = [];
$stats['items'] = $countryProducts->get()->count();
// $stats['items2'] = $countryProducts->dd();
return $stats;
} }
} }

View File

@@ -32,6 +32,32 @@ final class ProductController extends BaseController
ksort($stockList); ksort($stockList);
ksort($priceList); ksort($priceList);
return $this->render('product.html.twig', [
'product' => $product,
'price_list' => $this->prepareChartData($priceList),
'stock_list' => $this->prepareChartData($stockList),
'price_dates' => implode("','", $this->dateRange(array_key_first($priceList), array_key_last($priceList))),
]);
}
#[Route('/product/model/{productModel}', name: 'app_product_model')]
public function productModel(string $productModel): Response
{
$product = Product::with([
'price' => fn($query) => $query->orderBy('created_at', 'desc'),
'stock' => fn($query) => $query->orderBy('created_at', 'desc'),
])->where('subTitle', $productModel)->first();
if (null === $product) {
throw $this->createNotFoundException('Product not found');
}
$priceList = $product->price()->pluck('price', 'created_at')->mapWithKeys(fn($price, $createdAt) => [explode(' ', $createdAt)[0] => $price])->toArray();
$stockList = $product->stock()->pluck('stock', 'created_at')->mapWithKeys(fn($stock, $createdAt) => [explode(' ', $createdAt)[0] => $stock])->toArray();
ksort($stockList);
ksort($priceList);
return $this->render('product.html.twig', [ return $this->render('product.html.twig', [
'product' => $product, 'product' => $product,
'price_list' => $this->prepareChartData($priceList), 'price_list' => $this->prepareChartData($priceList),

View File

@@ -11,7 +11,7 @@
<td> <td>
<a href='{{ path('app_product', {'productId': product.id}) }}' <a href='{{ path('app_product', {'productId': product.id}) }}'
class="text-decoration-none">{{ product.name }}</a> class="text-decoration-none">{{ product.name }}</a>
<span class="badge text-bg-light"><a href="{{ path('app_search', {'search': product.subTitle}) }}" <span class="badge text-bg-light"><a href="{{ path('app_product_model', {'productModel': product.subTitle}) }}"
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span> class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
{% if product.promotions is not null and product.promotions.hasPromotion %}<a {% if product.promotions is not null and product.promotions.hasPromotion %}<a
href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span> href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span>

View File

@@ -21,6 +21,8 @@
{% if listType == 'country' and country is not null%} {% if listType == 'country' and country is not null%}
<h2 class="text-muted mt-4 mx-4">{{ country.countryName }}</h2> <h2 class="text-muted mt-4 mx-4">{{ country.countryName }}</h2>
<h5 class="mx-4 my-0">Currency: {{ country.currency }}</h5>
{{ dump(countryStats) }}
{% endif %} {% endif %}
@@ -64,10 +66,10 @@
<a href="{{ path('app_new') }}"><span class="badge text-bg-success">is new</span></a> <a href="{{ path('app_new') }}"><span class="badge text-bg-success">is new</span></a>
{% endif %} {% endif %}
<span class="badge text-bg-light"><a <span class="badge text-bg-light"><a
href="{{ path('app_search', {'search': product.subTitle}) }}" href="{{ path('app_product_model', {'productModel': product.subTitle}) }}"
class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span> class="link-underline link-underline-opacity-0 link-dark">{{ product.subTitle }}</a></span>
{% if product.promotions is not null and product.promotions.hasPromotion %}<a href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span></a>{% endif %} {% if product.promotions is not null and product.promotions.hasPromotion %}<a href="{{ path('app_promos', {'promo': product.promotions.slug}) }}"><span class="badge bg-info">PROMO: {{ product.promotions.tag }}</span></a>{% endif %}
<span class="badge text-bg-light"><a href="{{ path('app_country', {'country': product.country.countryName}) }}" class="link-underline link-underline-opacity-0 link-dark">{{ product.country.countryName }}</a></span> <span class="badge text-bg-light"><a href="{{ path('app_country', {'countryName': product.country.countryName}) }}" class="link-underline link-underline-opacity-0 link-dark">{{ product.country.countryName }}</a></span>
</td> </td>
<td class="align-middle"> <td class="align-middle">
<nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';"> <nav aria-label="breadcrumb" style="--bs-breadcrumb-divider: '>';">

View File

@@ -39,7 +39,7 @@
</a> </a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
{% for country in getCountries() %} {% for country in getCountries() %}
<li><a class="dropdown-item" href="{{ path('app_country', {'country': country.countryName}) }}">{{ country.countryName }}</a></li> <li><a class="dropdown-item" href="{{ path('app_country', {'countryName': country.countryName}) }}">{{ country.countryName }}</a></li>
{% endfor %} {% endfor %}
</ul> </ul>
</li> </li>