Skip to content

Commit

Permalink
added SeoKeywords to add SeoEnabled entities (brands, categories, col…
Browse files Browse the repository at this point in the history
…lections and products) and in all components that need it
  • Loading branch information
abdelhamiderrahmouni committed Feb 5, 2024
1 parent 13ed0ab commit b211c6a
Show file tree
Hide file tree
Showing 29 changed files with 207 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Shopper\Framework\Traits\Database;

return new class extends Migration
{
use Database\Migration;

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::whenTableDoesntHaveColumn($this->getTableName('brands'), 'seo_keywords', function (Blueprint $table) {
$table->string('seo_keywords', 260)->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::whenTableHasColumn($this->getTableName('brands'),'seo_keywords', function (Blueprint $table) {
$table->dropColumn('seo_keywords');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Shopper\Framework\Traits\Database;

return new class extends Migration
{
use Database\Migration;

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::whenTableDoesntHaveColumn($this->getTableName('categories'), 'seo_keywords', function (Blueprint $table) {
$table->string('seo_keywords', 260)->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::whenTableHasColumn($this->getTableName('categories'),'seo_keywords', function (Blueprint $table) {
$table->dropColumn('seo_keywords');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Shopper\Framework\Traits\Database;

return new class extends Migration
{
use Database\Migration;

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::whenTableDoesntHaveColumn($this->getTableName('collections'), 'seo_keywords', function (Blueprint $table) {
$table->string('seo_keywords', 260)->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::whenTableHasColumn($this->getTableName('collections'),'seo_keywords', function (Blueprint $table) {
$table->dropColumn('seo_keywords');
});
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Shopper\Framework\Traits\Database;

return new class extends Migration
{
use Database\Migration;

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::whenTableDoesntHaveColumn($this->getTableName('products'), 'seo_keywords', function (Blueprint $table) {
$table->string('seo_keywords', 260)->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::whenTableHasColumn($this->getTableName('products'),'seo_keywords', function (Blueprint $table) {
$table->dropColumn('seo_keywords');
});
}
};
1 change: 1 addition & 0 deletions resources/lang/en/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
'ga_json' => 'Json Account Credentials',
'gtag' => 'Your Google Tag Manager account ID',
'pixel_id' => 'Your Facebook Pixel account ID',
'keywords' => 'Keywords'
],

'placeholder' => [
Expand Down
1 change: 1 addition & 0 deletions resources/lang/fr/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
'ga_json' => 'Références du compte en Json',
'gtag' => 'ID de compte Google Tag Manager',
'pixel_id' => 'ID du compte Facebook Pixel',
'keywords' => 'Mots clés',
],

'placeholder' => [
Expand Down
8 changes: 7 additions & 1 deletion resources/views/components/forms/seo.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@props(['slug', 'title', 'description', 'url', 'canUpdate'])
@props(['slug', 'title', 'description', 'keywords', 'url', 'canUpdate'])

<div class="bg-white rounded-lg shadow-md divide-y divide-secondary-200 dark:bg-secondary-800 dark:divide-secondary-700">
<div class="p-4 sm:p-5">
Expand Down Expand Up @@ -33,6 +33,9 @@
<p class="mt-1 text-secondary-500 text-sm leading-5 dark:text-secondary-400">
{{ str_limit($description, 160) }}
</p>
<p class="mt-1 text-secondary-500 text-sm leading-5 dark:text-secondary-400">
{{ str_limit($keywords, 255) }}
</p>
</div>
@endif
</div>
Expand All @@ -51,6 +54,9 @@
<x-shopper::forms.textarea wire:model.debounce.500ms="seoDescription" id="seo_description" />
</div>
</div>
<x-shopper::forms.group for="seo_keywords" :label="__('shopper::layout.forms.label.keywords')">
<x-shopper::forms.input wire:model.debounce.500ms="seoKeywords" id="seo_keywords" type="text" autocomplete="off" />
</x-shopper::forms.group>
</div>
@endif
</div>
1 change: 1 addition & 0 deletions resources/views/livewire/brands/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class="pl-16"
:title="$seoTitle"
:url="str_slug($name)"
:description="$seoDescription"
:keywords="$seoKeywords"
:canUpdate="$updateSeo"
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/brands/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
:title="$seoTitle"
:url="$brand->slug"
:description="$seoDescription"
:keywords="$seoKeywords"
:canUpdate="$updateSeo"
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/categories/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
:title="$seoTitle"
:url="str_slug($name)"
:description="$seoDescription"
:keywords="$seoKeywords"
:canUpdate="$updateSeo"
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/categories/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
:title="$seoTitle"
:url="$category->slug"
:description="$seoDescription"
:keywords="$seoKeywords"
:canUpdate="$updateSeo"
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/collections/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ class="p-4 sm:p-5"
:title="$seoTitle"
:url="str_slug($name)"
:description="$seoDescription"
:keywords="$seoKeywords"
:canUpdate="$updateSeo"
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/collections/edit.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
:title="$seoTitle"
:url="$collection->slug"
:description="$seoDescription"
:keywords="$seoKeywords"
:canUpdate="$updateSeo"
/>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/livewire/products/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class="py-0 pl-2 pr-7 border-transparent bg-transparent"
:title="$seoTitle"
:url="str_slug($name)"
:description="$seoDescription"
:keywords="$seoKeywords"
:canUpdate="$updateSeo"
/>
</div>
Expand Down
3 changes: 3 additions & 0 deletions resources/views/livewire/products/forms/form-seo.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<x-shopper::forms.textarea wire:model.defer="seoDescription" id="seo_description" />
</div>
</div>
<x-shopper::forms.group :label="__('shopper::layout.forms.label.keywords')">
<x-shopper::forms.input wire:model.defer="seoKeywords" id="seo_keywords" type="text" autocomplete="off" />
</x-shopper::forms.group>
<div>
<x-shopper::forms.group :label="__('shopper::layout.forms.label.friendly_url')" for="slug" isRequired :error="$errors->first('slug')">
<x-shopper::forms.input wire:model.defer="slug" id="slug" type="text" autocomplete="off" placeholder="my-custom-url" />
Expand Down
6 changes: 4 additions & 2 deletions src/Http/Livewire/Brands/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ class Create extends AbstractBaseComponent

public ?string $fileUrl = null;

public $seoAttributes = [
public array $seoAttributes = [
'name' => 'name',
'description' => 'description',
'keywords' => 'keywords',
];

protected $listeners = [
Expand Down Expand Up @@ -54,7 +55,8 @@ public function store(): void
'description' => $this->description,
'is_enabled' => $this->is_enabled,
'seo_title' => $this->seoTitle,
'seo_description' => $this->seoDescription,
'seo_description' => str_limit($this->seoDescription, 157),
'seo_keywords' => str_limit($this->seoKeywords, 255),
]);

if ($this->fileUrl) {
Expand Down
5 changes: 4 additions & 1 deletion src/Http/Livewire/Brands/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ class Edit extends AbstractBaseComponent

public ?string $fileUrl = null;

public $seoAttributes = [
public array $seoAttributes = [
'name' => 'name',
'description' => 'description',
'keywords' => 'keywords',
];

protected $listeners = [
Expand Down Expand Up @@ -58,6 +59,7 @@ public function mount($brand): void
$this->updateSeo = true;
$this->seoTitle = $brand->seo_title ?? $brand->name;
$this->seoDescription = $brand->seo_description;
$this->seoKeywords = $brand->seo_keywords;
}

public function isUpdate(): bool
Expand All @@ -77,6 +79,7 @@ public function store(): void
'is_enabled' => $this->is_enabled,
'seo_title' => $this->seoTitle,
'seo_description' => str_limit($this->seoDescription, 157),
'seo_keywords' => str_limit($this->seoKeywords, 255),
]);

if ($this->fileUrl) {
Expand Down
6 changes: 4 additions & 2 deletions src/Http/Livewire/Categories/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ class Create extends AbstractBaseComponent

public $parent;

public $seoAttributes = [
public array $seoAttributes = [
'name' => 'name',
'description' => 'description',
'keywords' => 'keywords',
];

protected $listeners = [
Expand Down Expand Up @@ -58,7 +59,8 @@ public function store(): void
'description' => $this->description,
'is_enabled' => $this->is_enabled,
'seo_title' => $this->seoTitle,
'seo_description' => $this->seoDescription,
'seo_description' => str_limit($this->seoDescription, 157),
'seo_keywords' => str_limit($this->seoKeywords, 255),
]);

if ($this->fileUrl) {
Expand Down
5 changes: 4 additions & 1 deletion src/Http/Livewire/Categories/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ class Edit extends AbstractBaseComponent

public $parent;

public $seoAttributes = [
public array $seoAttributes = [
'name' => 'name',
'description' => 'description',
'keywords' => 'keywords',
];

protected $listeners = [
Expand All @@ -54,6 +55,7 @@ public function mount($category): void
$this->updateSeo = true;
$this->seoTitle = $category->seo_title ?? $category->name;
$this->seoDescription = $category->seo_description;
$this->seoKeywords = $category->seo_keywords;
$this->selectedCategory = $category->parent_id ? [$category->parent_id] : [];
$this->parent = $category->parent_id ? $category->parent : null;
}
Expand Down Expand Up @@ -85,6 +87,7 @@ public function store(): void
'is_enabled' => $this->is_enabled,
'seo_title' => $this->seoTitle,
'seo_description' => str_limit($this->seoDescription, 157),
'seo_keywords' => str_limit($this->seoKeywords, 255),
]);

if ($this->fileUrl) {
Expand Down
4 changes: 3 additions & 1 deletion src/Http/Livewire/Collections/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class Create extends Component

public string $condition_match = 'all';

public $seoAttributes = [
public array $seoAttributes = [
'name' => 'name',
'description' => 'description',
'keywords' => 'keywords',
];

protected $listeners = [
Expand Down Expand Up @@ -70,6 +71,7 @@ public function store(): void
'match_conditions' => $this->condition_match,
'seo_title' => $this->seoTitle,
'seo_description' => $this->seoDescription,
'seo_keywords' => str_limit($this->seoKeywords, 255),
'published_at' => $this->publishedAt ?? now(),
]);

Expand Down
Loading

0 comments on commit b211c6a

Please sign in to comment.