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

Remove enforced unique validation on SKU #2029

Merged

Conversation

ryanmitchell
Copy link
Contributor

This PR removes the enforced unique validation on SKU.

Dev's can overwrite the SKU validation using extendSkuValidation() hook, but the line removed in this PR still forces unique validation even when you don't want it.

Copy link

vercel bot commented Dec 2, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lunar-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 17, 2025 8:11am

@alecritson alecritson merged commit d2ad394 into lunarphp:1.x Jan 17, 2025
22 checks passed
@ryanmitchell ryanmitchell deleted the fix/remove-sku-unique-validation branch January 17, 2025 08:55
@wychoong
Copy link
Contributor

@ryanmitchell @alecritson i given a quick look, this doesnt seems to be the correct change

  • there is no extendSkuValidation hook for ProductVariantResource
    public static function getSkuFormComponent(): Forms\Components\TextInput
    {
    return Forms\Components\TextInput::make('sku');
    }
  • this only removes when editing Product but not ProductVariant
    ProductVariantResource::getSkuFormComponent()
    ->live()->unique(
    table: fn () => $this->getRecord()->getTable(),
    ignorable: $this->getRecord(),
    ignoreRecord: true,
    ),
  • currently extendSkuValidation only apply for creating new product in ListProducts
    public static function getSkuValidation(): array
    {
    return static::callStaticLunarHook('extendSkuValidation', [
    'required' => true,
    'unique' => true,
    ]);
    }
    public static function getSkuFormComponent(): Component
    {
    $validation = static::getSkuValidation();
    $input = Forms\Components\TextInput::make('sku')
    ->label(__('lunarpanel::product.form.sku.label'))
    ->required($validation['required'] ?? false);
    if ($validation['unique'] ?? false) {
    $input->unique(function () {
    return (new ProductVariant)->getTable();
    });
    }
    return $input;
    }

    public static function createActionFormInputs(): array
    {
    return [
    Grid::make(2)->schema([
    ProductResource::getBaseNameFormComponent(),
    ProductResource::getProductTypeFormComponent()->required(),
    ]),
    Grid::make(2)->schema([
    ProductResource::getSkuFormComponent(),
    ProductResource::getBasePriceFormComponent(),
    ]),
    ];
    }

do let me know if I got it wrong

alecritson added a commit that referenced this pull request Jan 17, 2025
@alecritson
Copy link
Collaborator

@ryanmitchell No problem, I have reverted the change.

@ryanmitchell
Copy link
Contributor Author

ryanmitchell commented Jan 17, 2025

Ok, well the issue still stands, if you dont want unique SKUs currently the system still enforces that.

@alecritson
Copy link
Collaborator

Yes it will need to be revisited if the original PR didn't cover all use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants