grizzlyware/aero-rich-additionals

允许在 Aero Commerce 中的模型上记录结构化附加属性

v1.2.1 2024-08-30 15:29 UTC

This package is auto-updated.

Last update: 2024-08-30 15:29:40 UTC


README

Grizzlyware

Aero Commerce 的丰富附加组件

此软件包允许在 Aero Commerce 中的模型上记录结构化附加属性。

image

安装

您可以通过 Composer 安装此软件包

composer require grizzlyware/aero-rich-additionals

用法

以下模型可以添加丰富属性(到目前为止!)

  • 产品
  • 分类
  • 页面
  • 配送方式

将模型类传递给 RichAdditionals 门面上的 add 或辅助方法,然后链式调用方法来配置属性(如有必要)。

<?php

namespace App\Providers;

use Aero\Admin\Facades\Admin;
use Aero\Catalog\Models\Product;
use App\Enums\PaperSize;
use Grizzlyware\Aero\RichAdditionals\AttributeType;
use Grizzlyware\Aero\RichAdditionals\Facades\RichAdditionals;
use Illuminate\Support\ServiceProvider;

class RichAdditionalsProvider extends ServiceProvider
{
    public function boot(): void
    {
        // For performance, only register the additional attributes when the admin panel is booted
        Admin::booted(
            $this->registerAdditionalAttributes(...)
        );
    }

    private function registerAdditionalAttributes(): void
    {
        // Options generated from an enum class
        RichAdditionals::enum(
            'paper_size',
            Product::class,
            PaperSize::class,
        );

        // Free text
        RichAdditionals::add('nickname', Product::class)
            ->setAttributeLabel('Nickname')
            ->setRequired()
            ->setHelp('A nickname for the product')
        ;

        // Manually defined options
        RichAdditionals::add('color', Product::class, AttributeType::DROPDOWN)
            ->setHelp('The color of the product')
            ->setOptions([
                'red' => 'Red',
                'green' => 'Green',
                'blue' => 'Blue',
            ])
        ;

        // Custom validation rules
        RichAdditionals::add('sales_email', Product::class)
            ->setHelp('Email address of the sales manager for this product')
            ->setValidationRules(['email'])
        ;

        // Generate options with a callback
        RichAdditionals::add('aisle_number', Product::class, AttributeType::DROPDOWN)
            ->setHelp('Where is this product located in the store?')
            ->setOptions(fn() => array_combine(range(50, 100), range(50, 100)))
        ;
    }
}

支持

如果您在此软件包中遇到任何问题,请通过 GitHub 提出问题。

此软件包的开发由 Grizzlyware 赞助。

提供商业支持,请联系我们获取更多信息。

安全

如果您发现任何与安全相关的问题,请给此项目的维护者发送电子邮件,不要提出问题