Skip to content

Commit

Permalink
为产品模型添加标签功能
Browse files Browse the repository at this point in the history
- 在 Product 模型中添加 tags 关系
- 创建产品标签中间表
- 更新产品资源和表单,支持多选标签
- 调整产品查询和服务,包含标签数据
- 修改数据库迁移文件,添加标签关联表
  • Loading branch information
liushoukun committed Oct 12, 2024
1 parent d653b0d commit f451944
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/Clusters/Product/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ProductResource extends Resource

public static function callFindQuery(FindQuery $findQuery) : FindQuery
{
$findQuery->include = [ 'skus', 'info', 'extendProductGroups' ];
$findQuery->include = [ 'skus', 'info', 'extendProductGroups', 'tags' ];
return $findQuery;
}

Expand All @@ -77,6 +77,7 @@ public static function callResolveRecord(Model $model) : Model
}
$model->setAttribute('skus', $model->skus->toArray());
$model->setAttribute('extendProductGroups', $model->extendProductGroups->toArray());
$model->setAttribute('tags', $model->tags->toArray());
return $model;
}

Expand Down Expand Up @@ -193,7 +194,7 @@ public static function productAttributesFields() : array
->storeResults()
->default(0),

// TODO

SelectTree::make('extend_product_groups')
->label(__('red-jasmine-product::product.fields.extend_groups'))
->relationship(relationship: 'extendProductGroups',
Expand All @@ -207,10 +208,21 @@ public static function productAttributesFields() : array
)
//->saveRelationshipsUsing(null)
//->loadStateFromRelationshipsUsing(null)

->saveRelationshipsUsing(null)
->parentNullValue(0)
->default([]),

Forms\Components\Select::make('tags')
->multiple()
->label(__('red-jasmine-product::product.fields.tags'))

->relationship(
titleAttribute: 'name',
modifyQueryUsing: fn($query, Forms\Get $get, ?Model $record) => $query->where('owner_type', $get('owner_type'))
->where('owner_id', $get('owner_id')),
)
->default([]),

Forms\Components\Fieldset::make('basicProps')
->label(__('red-jasmine-product::product.fields.basic_props'))
->columns(1)->inlineLabel()
Expand Down

0 comments on commit f451944

Please sign in to comment.