Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature admin roles language #128

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
474b910
fixed slideshow if enable many languages
yushine Dec 24, 2024
f007c80
update packages
yushine Dec 24, 2024
7ccc90d
Prevent front-end from uploading SVG images to avoid SVG XSS attacks.…
yushine Dec 24, 2024
1a5c345
fixed category filters
yushine Dec 26, 2024
425d1d1
fixed the blade insert hook - product.detail.tab.pane.after
yushine Dec 26, 2024
d6007ac
service.checkout.confirm.after
yushine Jan 2, 2025
b691d10
add order printing
yushine Jan 2, 2025
d6c99e1
add variant label for order information
yushine Jan 2, 2025
3e1cb51
refactor for api token
yushine Jan 2, 2025
09ee129
fixed panel order status filters.
Jan 2, 2025
672908e
update variant images
yushine Jan 3, 2025
9b9c118
fixed article resource
yushine Jan 6, 2025
9157eca
fixed shipping printing for order
yushine Jan 6, 2025
34ba2a8
migrate from enterprise: add spu_code, import products with attribute…
yushine Jan 9, 2025
d3bb982
upgrade packages
yushine Jan 10, 2025
09d3a6a
fixed breadcrumb
yushine Jan 10, 2025
30daf7f
fixed token and fixed pdp fallback name
yushine Jan 10, 2025
3c55825
support admin note
yushine Jan 10, 2025
3d48fa0
add administrator remarks
Jan 10, 2025
3c8037c
fix token
Jan 10, 2025
2eac10d
fixed blade hook with output
yushine Jan 13, 2025
2897d52
code format
yushine Jan 10, 2025
c7ecd57
optimize TDK for article, brand, catalog, category, page, product, tag
yushine Jan 13, 2025
12dd71c
fixed shipping address
yushine Jan 13, 2025
65c3322
fixed csrf token duplication
yushine Jan 13, 2025
2552c0a
Optimize TDK
yushine Jan 13, 2025
0070eba
add multilingual
Jan 13, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
299 changes: 153 additions & 146 deletions composer.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions database/seeders/ProductSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private function getProducts(): array
return [
[
'brand_id' => 1,
'spu_code' => 'galaxy-glow-evening-gown',
'slug' => 'galaxy-glow-evening-gown',
'translations' => [
[
Expand Down Expand Up @@ -122,6 +123,7 @@ private function getProducts(): array
],
[
'brand_id' => 1,
'spu_code' => 'urban-elite-suit-jacket',
'slug' => 'urban-elite-suit-jacket',
'translations' => [
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ public function up(): void
$table->string('billing_address_2')->comment('Billing Address 1');
$table->string('billing_zipcode')->comment('Billing Address Zipcode');
$table->text('comment')->nullable()->comment('Order Comment');
$table->text('admin_note')->nullable()->comment('Admin Note');
$table->timestamps();
$table->softDeletes()->comment('Deleted At');
});
Expand Down Expand Up @@ -700,6 +701,7 @@ public function up(): void
$table->unsignedInteger('product_video_id')->default(0)->index('p_pv_id')->comment('Video ID');
$table->unsignedInteger('product_sku_id')->default(0)->index('p_ps_id')->comment('SKU ID');
$table->unsignedInteger('tax_class_id')->default(0)->index('p_tc_id')->comment('Tax Class ID');
$table->string('spu_code', 128)->nullable()->unique()->comment('SPU Code');
$table->string('slug', 128)->nullable()->unique()->comment('URL Slug');
$table->json('variables')->nullable()->comment('Product variables for sku with variants');
$table->boolean('is_virtual')->default(false)->comment('Is Virtual');
Expand Down
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
9 changes: 7 additions & 2 deletions innopacks/common/src/Libraries/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ public static function getInstance(): Breadcrumb
*/
public function getTrail($type, $object, string $title = ''): array
{
if (in_array($type, ['category', 'product', 'catalog', 'article', 'page', 'tag'])) {
if (in_array($type, ['category', 'product', 'tag'])) {
return [
'title' => $object->translation->name ?: $object->translation->title,
'title' => $object->fallbackName('name'),
'url' => $object->url,
];
} elseif (in_array($type, ['catalog', 'article', 'page'])) {
return [
'title' => $object->fallbackName('title'),
'url' => $object->url,
];
} elseif ($type == 'brand') {
Expand Down
129 changes: 129 additions & 0 deletions innopacks/common/src/Libraries/MetaInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?php
/**
* Copyright (c) Since 2024 InnoShop - All Rights Reserved
*
* @link https://www.innoshop.com
* @author InnoShop <[email protected]>
* @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0)
*/

namespace InnoShop\Common\Libraries;

use Illuminate\Support\Str;

class MetaInfo
{
private object $object;

private string $type;

private string $systemMetaTitle;

private string $systemMetaDescription;

private string $systemMetaKeywords;

/**
* @param $object
*/
public function __construct($object)
{
$this->object = $object;
$this->setType();
$this->setSystemInfo();
}

public static function getInstance($object): MetaInfo
{
return new self($object);
}

/**
* @return MetaInfo
*/
public function setType(): static
{
$this->type = Str::lower(class_basename($this->object));

return $this;
}

/**
* @return void
*/
public function setSystemInfo(): void
{
$this->systemMetaTitle = system_setting_locale('meta_title');
$this->systemMetaDescription = system_setting_locale('meta_description');
$this->systemMetaKeywords = system_setting_locale('meta_keywords');
}

/**
* @return string
*/
public function getTitle(): string
{
$metaTitle = $this->object->translation->meta_title ?? '';
if (empty($metaTitle)) {
$metaTitle = $this->getName();
}

if ($this->systemMetaTitle) {
$metaTitle .= ' - '.$this->systemMetaTitle;
}

return $metaTitle;
}

/**
* @return string
*/
public function getDescription(): string
{
$metaDescription = $this->object->translation->meta_description ?? '';
if (empty($metaDescription)) {
$metaDescription = $this->getName();
}

if ($this->systemMetaDescription) {
$metaDescription .= '. '.$this->systemMetaDescription;
}

return $metaDescription;
}

/**
* @return string
*/
public function getKeywords(): string
{
$metaKeywords = $this->object->translation->meta_keywords ?? '';
if (empty($metaKeywords)) {
$metaKeywords = $this->getName();
}

if ($this->systemMetaKeywords) {
$metaKeywords .= ', '.$this->systemMetaKeywords;
}

return $metaKeywords;
}

/**
* @return string
*/
public function getName(): string
{
$object = $this->object;
$type = $this->type;
if (in_array($type, ['category', 'product', 'tag'])) {
return $object->fallbackName('name');
} elseif (in_array($type, ['catalog', 'article', 'page'])) {
return $object->fallbackName('title');
} elseif ($type == 'brand') {
return $object->name;
}

return '';
}
}
2 changes: 2 additions & 0 deletions innopacks/common/src/Models/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace InnoShop\Common\Models;

use Exception;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use InnoShop\Common\Traits\Translatable;
Expand Down Expand Up @@ -45,6 +46,7 @@ public function getTagNamesAttribute(): mixed
* Get slug url link.
*
* @return string
* @throws Exception
*/
public function getUrlAttribute(): string
{
Expand Down
10 changes: 10 additions & 0 deletions innopacks/common/src/Models/Attribute/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

namespace InnoShop\Common\Models\Attribute;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use InnoShop\Common\Models\Attribute;
use InnoShop\Common\Models\BaseModel;

class Translation extends BaseModel
Expand All @@ -18,4 +20,12 @@ class Translation extends BaseModel
protected $fillable = [
'locale', 'name',
];

/**
* @return BelongsTo
*/
public function attribute(): BelongsTo
{
return $this->belongsTo(Attribute::class, 'attribute_id');
}
}
10 changes: 10 additions & 0 deletions innopacks/common/src/Models/Category/Translation.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

namespace InnoShop\Common\Models\Category;

use Illuminate\Database\Eloquent\Relations\BelongsTo;
use InnoShop\Common\Models\BaseModel;
use InnoShop\Common\Models\Category;

class Translation extends BaseModel
{
Expand All @@ -18,4 +20,12 @@ class Translation extends BaseModel
protected $fillable = [
'category_id', 'locale', 'name', 'content', 'meta_title', 'meta_description', 'meta_keywords',
];

/**
* @return BelongsTo
*/
public function category(): BelongsTo
{
return $this->belongsTo(Category::class, 'category_id');
}
}
2 changes: 1 addition & 1 deletion innopacks/common/src/Models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Order extends BaseModel
'shipping_city', 'shipping_address_1', 'shipping_address_2', 'shipping_zipcode', 'billing_method_code',
'billing_method_name', 'billing_customer_name', 'billing_calling_code', 'billing_telephone', 'billing_country',
'billing_country_id', 'billing_state_id', 'billing_state', 'billing_city', 'billing_address_1',
'billing_address_2', 'billing_zipcode', 'comment',
'billing_address_2', 'billing_zipcode', 'comment', 'admin_note',
];

protected $appends = [
Expand Down
4 changes: 2 additions & 2 deletions innopacks/common/src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class Product extends BaseModel
use HasPackageFactory, Replicate, Translatable;

protected $fillable = [
'brand_id', 'product_image_id', 'product_video_id', 'product_sku_id', 'tax_class_id', 'slug', 'is_virtual',
'variables', 'position', 'active', 'weight', 'weight_class', 'sales', 'viewed',
'brand_id', 'product_image_id', 'product_video_id', 'product_sku_id', 'tax_class_id', 'spu_code', 'slug',
'is_virtual', 'variables', 'position', 'active', 'weight', 'weight_class', 'sales', 'viewed',
];

protected $casts = [
Expand Down
51 changes: 48 additions & 3 deletions innopacks/common/src/Repositories/Attribute/ValueRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace InnoShop\Common\Repositories\Attribute;

use Exception;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use InnoShop\Common\Models\Attribute\Value;
Expand All @@ -21,15 +22,17 @@ class ValueRepo extends BaseRepo
/**
* @param $attributeID
* @param $translations
* @return void
* @return mixed
*/
public function createAttribute($attributeID, $translations): void
public function createAttribute($attributeID, $translations): mixed
{
if (empty($attributeID) || empty($translations)) {
return;
return null;
}
$attrValue = Value::query()->create(['attribute_id' => $attributeID]);
$this->updateTranslations($attrValue, $translations);

return $attrValue;
}

/**
Expand Down Expand Up @@ -70,6 +73,48 @@ public function all(array $filters = []): Collection
return $this->builder($filters)->get();
}

/**
* @param $name
* @param string $locale
* @return mixed
* @throws Exception
*/
public function findByName($name, string $locale = ''): mixed
{
if (empty($locale)) {
$locale = locale_code();
}

$translation = Value\Translation::query()
->where('name', $name)
->where('locale', $locale)
->first();

return $translation->value ?? null;
}

/**
* @param $attributeRow
* @param $name
* @param string $locale
* @return mixed
* @throws Exception
*/
public function findOrCreateByName($attributeRow, $name, string $locale = ''): mixed
{
$attributeValue = $this->findByName($name, $locale);
if ($attributeValue) {
return $attributeValue;
}

$data = [];
foreach (locales() as $locale) {
$data[$locale->code] = $name;
}

return $this->createAttribute($attributeRow->id, $data);
}

/**
* @param array $filters
* @return Builder
Expand Down
41 changes: 41 additions & 0 deletions innopacks/common/src/Repositories/AttributeRepo.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,47 @@ public function all(array $filters = []): Collection
return $this->builder($filters)->get();
}

/**
* @param $name
* @param string $locale
* @return mixed
* @throws Exception
*/
public function findByName($name, string $locale = ''): mixed
{
if (empty($locale)) {
$locale = locale_code();
}

$translation = Attribute\Translation::query()->where('name', $name)->where('locale', $locale)->first();

return $translation->attribute ?? null;
}

/**
* @param $name
* @param string $locale
* @return mixed
* @throws Throwable
*/
public function findOrCreateByName($name, string $locale = ''): mixed
{
$attribute = $this->findByName($name, $locale);
if ($attribute) {
return $attribute;
}

$data = [];
foreach (locales() as $locale) {
$data['translations'][] = [
'locale' => $locale->code,
'name' => $name,
];
}

return $this->create($data);
}

/**
* @param array $filters
* @return Builder
Expand Down
Loading
Loading