Skip to content

Commit

Permalink
fixed slideshow if enable many languages
Browse files Browse the repository at this point in the history
  • Loading branch information
yushine committed Dec 24, 2024
1 parent 777e6b0 commit 474b910
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
2 changes: 1 addition & 1 deletion innopacks/common/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ function theme_path(string $path): string
*/
function theme_asset(string $theme, string $path, ?bool $secure = null): string
{
if (config('app.debug')) {
if (config('app.debug') && Str::endsWith($path, ['.js', '.css'])) {
return mix("themes/$theme/$path");
}

Expand Down
4 changes: 2 additions & 2 deletions innopacks/front/resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
@hookinsert('home.content.top')

<section class="module-content">
@if (system_setting('slideshow'))
@if ($slideshow)
<section class="module-line">
<div class="swiper" id="module-swiper-1">
<div class="module-swiper swiper-wrapper">
@foreach (system_setting('slideshow', []) as $slide)
@foreach ($slideshow as $slide)
@if ($slide['image'][front_locale_code()] ?? false)
<div class="swiper-slide">
<a href="{{ $slide['link'] ?: 'javascript:void(0)' }}"><img
Expand Down
2 changes: 2 additions & 0 deletions innopacks/front/src/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use App\Http\Controllers\Controller;
use InnoShop\Common\Repositories\ArticleRepo;
use InnoShop\Common\Repositories\ProductRepo;
use InnoShop\Front\Repositories\HomeRepo;

class HomeController extends Controller
{
Expand All @@ -30,6 +31,7 @@ public function index(): mixed

$news = ArticleRepo::getInstance()->getLatestArticles();
$data = [
'slideshow' => HomeRepo::getInstance()->getSlideShow(),
'tab_products' => $tabProducts,
'news' => $news,
];
Expand Down
57 changes: 57 additions & 0 deletions innopacks/front/src/Repositories/HomeRepo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/**
* Copyright (c) Since 2024 InnoShop - All Rights Reserved
*
* @link https://www.innoshop.com
* @author InnoShop <team@innoshop.com>
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

namespace InnoShop\Front\Repositories;

use InnoShop\Common\Models\Category;
use InnoShop\Common\Models\Product;

class HomeRepo
{
/**
* @return static
*/
public static function getInstance(): static
{
return new static;
}

/**
* @return array
*/
public function getSlideShow(): array
{
$slideShow = system_setting('slideshow');
if (empty($slideShow)) {
return [];
}

$result = [];
foreach ($slideShow as $item) {
if (str_starts_with($item['link'], 'category:')) {
$categoryID = str_replace('category:', '', $item['link']);
$category = Category::query()->find($categoryID);
if (empty($category)) {
$category = Category::query()->where('slug', $categoryID)->first();
}
$item['link'] = $category->url;
} elseif (str_starts_with($item['link'], 'product:')) {
$productID = str_replace('product:', '', $item['link']);
$product = Product::query()->find($productID);
if (empty($product)) {
$product = Product::query()->where('slug', $productID)->first();
}
$item['link'] = $product->url;
}
$result[] = $item;
}

return $result;
}
}

0 comments on commit 474b910

Please sign in to comment.