Skip to content

Commit

Permalink
修复产品扩展组关系同步问题并优化相关功能
Browse files Browse the repository at this point in the history
- 修复了产品更新时扩展产品组关系未同步的问题
- 优化了产品创建和更新流程,确保扩展产品组关系正确同步
-调整了产品SKU默认值的设置逻辑
- 优化了产品信息展示,增加了扩展产品组的返回
- 修复了一些与产品属性和SKU相关的小问题
  • Loading branch information
liushoukun committed Oct 11, 2024
1 parent 46fd16a commit e5545e0
Showing 1 changed file with 75 additions and 65 deletions.
140 changes: 75 additions & 65 deletions src/Clusters/Product/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Support\Arr;
use RedJasmine\Ecommerce\Domain\Models\Enums\OrderQuantityLimitTypeEnum;
use RedJasmine\Ecommerce\Domain\Models\Enums\ProductTypeEnum;
use RedJasmine\Ecommerce\Domain\Models\Enums\ShippingTypeEnum;
Expand Down Expand Up @@ -148,13 +150,13 @@ public static function productAttributesFields() : array
SelectTree::make('category_id')
->label(__('red-jasmine-product::product.fields.category_id'))
->relationship('category', 'name', 'parent_id')
->enableBranchNode()
// ->enableBranchNode()
->parentNullValue(0)
->default(0), // 设置可选
SelectTree::make('brand_id')
->label(__('red-jasmine-product::product.fields.brand_id'))
->relationship('brand', 'name', 'parent_id')
->enableBranchNode()
// ->enableBranchNode()
->parentNullValue(0)
->default(0),
Forms\Components\TextInput::make('product_model')
Expand All @@ -171,10 +173,13 @@ public static function productAttributesFields() : array
->where('owner_id', $get('owner_id'))
,
)
->enableBranchNode()
// ->enableBranchNode()
->parentNullValue(0)
->independent(false)
->storeResults()
->default(0),

// TODO
SelectTree::make('extend_product_groups')
->label(__('red-jasmine-product::product.fields.extend_groups'))
->relationship(relationship: 'extendProductGroups',
Expand All @@ -186,8 +191,9 @@ public static function productAttributesFields() : array
->where('owner_id', $get('owner_id'))
,
)
//->saveRelationshipsUsing(null)
//->loadStateFromRelationshipsUsing(null)

// ->enableBranchNode()
->parentNullValue(0)
->default([]),

Expand All @@ -210,6 +216,8 @@ protected static function basicProps() : Repeater
->live()
->columnSpan(2)
->required()
->disabled(fn($state) => $state)
->dehydrated()
->options(ProductProperty::limit(50)->pluck('name', 'id')->toArray())
->searchable()
->getSearchResultsUsing(fn(string $search
Expand Down Expand Up @@ -373,67 +381,6 @@ protected static function specifications() : array
) => $get('is_multiple_spec')), ];
}


public static function saleInfoFields() : array
{
return [


Forms\Components\TextInput::make('unit')
->label(__('red-jasmine-product::product.fields.unit'))
->maxLength(32),
Forms\Components\TextInput::make('unit_quantity')
->label(__('red-jasmine-product::product.fields.unit_quantity'))
->numeric()
->default(1)
->minValue(1),

Forms\Components\TextInput::make('outer_id')
->label(__('red-jasmine-product::product.fields.outer_id'))
->maxLength(255),
Forms\Components\TextInput::make('barcode')
->label(__('red-jasmine-product::product.fields.barcode'))
->maxLength(32),

Forms\Components\TextInput::make('min_limit')
->label(__('red-jasmine-product::product.fields.min_limit'))
->required()
->numeric()
->default(0),
Forms\Components\TextInput::make('max_limit')
->label(__('red-jasmine-product::product.fields.max_limit'))
->required()
->numeric()
->default(0),
Forms\Components\TextInput::make('step_limit')
->label(__('red-jasmine-product::product.fields.step_limit'))
->required()
->numeric()
->default(1),
Forms\Components\TextInput::make('vip')
->label(__('red-jasmine-product::product.fields.vip'))
->required()
->numeric()
->default(0),

Forms\Components\ToggleButtons::make('order_quantity_limit_type')
->label(__('red-jasmine-product::product.fields.order_quantity_limit_type'))
->required()
->live()
->grouped()
->useEnum(OrderQuantityLimitTypeEnum::class)
->default(OrderQuantityLimitTypeEnum::UNLIMITED),

Forms\Components\TextInput::make('order_quantity_limit_num')
->label(__('red-jasmine-product::product.fields.order_quantity_limit_num'))
->required()
->numeric()
->default(0)
->visible(fn(Forms\Get $get) => $get('order_quantity_limit_type') !== OrderQuantityLimitTypeEnum::UNLIMITED->value)
,
];
}

protected static function saleProps() : Repeater
{
return Repeater::make('sale_props')
Expand All @@ -446,6 +393,8 @@ protected static function saleProps() : Repeater
->columns(1)
->required()
->columnSpan(1)
->disabled(fn($state) => $state)
->dehydrated()
->options(ProductProperty::limit(50)->pluck('name', 'id')->toArray())
->searchable()
->getSearchResultsUsing(fn(string $search) : array => ProductProperty::where('name',
Expand Down Expand Up @@ -558,6 +507,67 @@ protected static function skus() : TableRepeater
->addable(false);
}

public static function saleInfoFields() : array
{
return [


Forms\Components\TextInput::make('unit')
->label(__('red-jasmine-product::product.fields.unit'))
->maxLength(32),
Forms\Components\TextInput::make('unit_quantity')
->label(__('red-jasmine-product::product.fields.unit_quantity'))
->numeric()
->default(1)
->minValue(1),

Forms\Components\TextInput::make('outer_id')
->label(__('red-jasmine-product::product.fields.outer_id'))
->maxLength(255),
Forms\Components\TextInput::make('barcode')
->label(__('red-jasmine-product::product.fields.barcode'))
->maxLength(32),

Forms\Components\TextInput::make('min_limit')
->label(__('red-jasmine-product::product.fields.min_limit'))
->required()
->numeric()
->default(0),
Forms\Components\TextInput::make('max_limit')
->label(__('red-jasmine-product::product.fields.max_limit'))
->required()
->numeric()
->default(0),
Forms\Components\TextInput::make('step_limit')
->label(__('red-jasmine-product::product.fields.step_limit'))
->required()
->numeric()
->default(1),
Forms\Components\TextInput::make('vip')
->label(__('red-jasmine-product::product.fields.vip'))
->required()
->numeric()
->default(0),

Forms\Components\ToggleButtons::make('order_quantity_limit_type')
->label(__('red-jasmine-product::product.fields.order_quantity_limit_type'))
->required()
->live()
->grouped()
->useEnum(OrderQuantityLimitTypeEnum::class)
->default(OrderQuantityLimitTypeEnum::UNLIMITED),

Forms\Components\TextInput::make('order_quantity_limit_num')
->label(__('red-jasmine-product::product.fields.order_quantity_limit_num'))
->required()
->numeric()
->default(0)
->suffix('')
->visible(fn(Forms\Get $get) => $get('order_quantity_limit_type') !== OrderQuantityLimitTypeEnum::UNLIMITED->value)
,
];
}

public static function descriptionFields() : array
{
return [
Expand Down

0 comments on commit e5545e0

Please sign in to comment.