This commit is contained in:
ludo
2024-02-19 23:51:32 +01:00
parent 15a6621a56
commit 869b148e20
18 changed files with 440 additions and 85 deletions

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Console\Commands;
use App\Models\Shop\Article;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
class FixSlug extends Command
{
protected $signature = 'FixSlug';
protected $description = 'Slugify articles';
public function handle()
{
$articles = Article::all();
foreach ($articles as $article) {
$article->slug = null;
$article->update(['name' => $article->name]);
}
return 0;
}
}

View File

@@ -16,6 +16,12 @@ class ArticleController extends Controller
return response()->json(Articles::autocomplete($str));
}
public function showBySlug($slug)
{
$id = Articles::getIDBySlug($slug);
return $id ? $this->show($id) : view('errors.404');
}
public function show($id)
{
$data = [

View File

@@ -17,7 +17,6 @@ class StoreVariationPost extends FormRequest
'package_id' => 'required',
'quantity' => 'required',
'unity_id' => 'required',
'weight' => 'required',
];
}
}

View File

@@ -6,6 +6,7 @@ use App\Models\Botanic\Specie;
use App\Models\Botanic\Variety;
use App\Traits\Model\HasComments;
use App\Traits\Model\Imageable;
use Cviebrock\EloquentSluggable\Sluggable;
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -16,6 +17,8 @@ use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Kirschbaum\PowerJoins\PowerJoins;
use Laravel\Scout\Searchable;
use RalphJSmit\Laravel\SEO\Support\HasSEO;
use RalphJSmit\Laravel\SEO\Support\SEOData;
use Rinvex\Categories\Traits\Categorizable;
use Rinvex\Tags\Traits\Taggable;
use Spatie\MediaLibrary\HasMedia;
@@ -29,10 +32,12 @@ class Article extends Model implements HasMedia
use EloquentJoin;
use HasComments;
use HasRelationships;
use HasSEO;
use Imageable;
use Powerjoins;
use RevisionableTrait;
use Searchable;
use Sluggable;
use SoftDeletes;
use Taggable;
use UserStamps;
@@ -177,6 +182,11 @@ class Article extends Model implements HasMedia
return $productId ? $query->where($this->table.'.product_id', $productId) : $query;
}
public function scopeBySlug($query, $slug)
{
return $slug ? $query->where($this->table.'.slug', $slug) : $query;
}
public function scopeByTag($query, $tagId)
{
return $tagId ? $query->whereHas('tags', function ($query) use ($tagId) {
@@ -227,4 +237,25 @@ class Article extends Model implements HasMedia
'description' => html_entity_decode(strip_tags($description)),
];
}
public function getDynamicSEOData(): SEOData
{
// $pathToFeaturedImageRelativeToPublicPath = // ..;
// Override only the properties you want:
return new SEOData(
title: $this->name,
description: $this->description,
// image: $pathToFeaturedImageRelativeToPublicPath,
);
}
public function sluggable(): array
{
return [
'slug' => [
'source' => 'name'
]
];
}
}

View File

@@ -3,11 +3,9 @@
namespace App\Repositories\Shop;
use App\Models\Shop\Article;
use App\Models\Shop\Merchandise;
use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties;
use App\Repositories\Core\Comments;
use App\Repositories\Core\Tag;
use App\Traits\Model\Basic;
use App\Traits\Repository\Imageable;
use Illuminate\Support\Str;
@@ -27,6 +25,11 @@ class Articles
return $export;
}
public static function getIDBySlug($slug)
{
return Article::bySlug($slug)->first()->id;
}
public static function getOffersGroupedByNature($id, $saleChannelId = false)
{
$articleIds = ArticleSiblings::getSiblingsIds($id);
@@ -178,6 +181,7 @@ class Articles
'product_name' => $article->product->name,
'parent_name' => trim(str_replace($article->product->name, '', $article->name)),
'offers' => $article->offers->toArray(),
'slug' => $article->slug,
];
}