text 创建属性,组属性

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 创建属性,组属性相关的知识,希望对你有一定的参考价值。

<?php

namespace Padi\Catalog\Setup;

use Magento\Catalog\Model\ProductFactory;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\TestFramework\Event\Magento;
use Padi\ApiClub\Model\ProductType;
use Padi\Catalog\Model\ProductRepository;
use Psr\Log\LoggerInterface;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Catalog\Model\Product\Action as ProductAction;

use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
use Magento\Store\Model\WebsiteRepository;
use Magento\Store\Model\ResourceModel\Website\CollectionFactory as WebsiteCollectionFactory;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory as ProductCollectionFactory;

class UpgradeData implements UpgradeDataInterface
{
    /**
     * @var ObjectManagerInterface
     */
    private $objectManager;

    /**
     * Page factory
     *
     * @var LoggerInterface
     */
    private $logger;

    /**
     * EAV setup factory
     *
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

    private $attributeSet;
    private $websiteRepository;
    private $websiteCollectionFactory;
    private $productCollectionFactory;
    private $productAction;

    /**
     * @var \Magento\Catalog\Api\ProductRepositoryInterface
     */
    private $productRepository;
    /**
     * @var \Magento\Framework\App\State
     */
    private $state;

    /**
     * UpgradeData constructor.
     * @param ObjectManagerInterface $manager
     * @param EavSetupFactory $eavSetupFactory
     * @param AttributeSet $attributeSet
     * @param WebsiteRepository $websiteRepository
     * @param WebsiteCollectionFactory $websiteCollectionFactory
     * @param ProductCollectionFactory $productCollectionFactory
     * @param ProductAction $productAction
     * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
     * @param \Magento\Framework\App\State $state
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    public function __construct(
        ObjectManagerInterface $manager,
        EavSetupFactory $eavSetupFactory,
        AttributeSet $attributeSet,
        WebsiteRepository $websiteRepository,
        WebsiteCollectionFactory $websiteCollectionFactory,
        ProductCollectionFactory $productCollectionFactory,
        ProductAction $productAction,
        \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
        \Magento\Framework\App\State $state
    ) {
        $this->objectManager = $manager;
        $this->eavSetupFactory = $eavSetupFactory;
        $this->attributeSet = $attributeSet;
        $this->websiteRepository = $websiteRepository;
        $this->websiteCollectionFactory = $websiteCollectionFactory;
        $this->productCollectionFactory = $productCollectionFactory;
        $this->productAction = $productAction;
        $this->logger = $this->objectManager->get('Psr\Log\LoggerInterface');
        $this->productRepository = $productRepository;
        $this->state = $state;
        $state->setAreaCode('admin');
        
    }

    /**
     * @param ModuleDataSetupInterface $setup
     * @param ModuleContextInterface $context
     */
    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
    {
        $setup->startSetup();
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
        $groupName = 'PADI';
        $entityTypeId = $eavSetup->getEntityTypeId('catalog_product');
        $defaultSetId = $eavSetup->getDefaultAttributeSetId($entityTypeId);
        $data = [
            'attribute_set_name' => ProductType::E_LEARNING,
            'entity_type_id' => $entityTypeId,
            'sort_order' => 0
        ];
        $eLearningSet = $eavSetup->getAttributeSet($entityTypeId, $data['attribute_set_name'], 'attribute_set_name');
        if (!$eLearningSet) {
            $eLearningSet = $this->objectManager->create(AttributeSet::class);
            $eLearningSet->setData($data);
            $eLearningSet->validate();
            $eLearningSet->save();
            $eLearningSet->initFromSkeleton($defaultSetId);
            $eLearningSet->save();
        }
        $eLearningSetId = $eavSetup->getAttributeSetId($entityTypeId, $eLearningSet);

        if (version_compare($context->getVersion(), '0.0.3') < 0) {
            /** @var \Magento\Eav\Setup\EavSetup $eavSetup */
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'label_highlight',
                [
                    'group' => $groupName,
                    'type' => 'int',
                    'label' => 'Label Highlight',
                    'input' => 'select',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'option' => array(
                        'values' => array(
                            0 => 'Featured'
                        ),
                    ),
                    'apply_to' => '',
                ]
            );
        }

        if (version_compare($context->getVersion(), '0.0.4') < 0) {
            $eavSetup->addAttributeGroup($entityTypeId, $eLearningSetId, $groupName);
            if(!$eavSetup->getAttributeId($entityTypeId, 'minimum_age'))
            {
                $eavSetup->addAttribute(
                    \Magento\Catalog\Model\Product::ENTITY,
                    'minimum_age',
                    [
                        'type' => 'int',
                        'label' => 'Minimum Required Age',
                        'input' => 'select',
                        'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE,
                        'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                        'visible' => true,
                        'required' => false,
                        'user_defined' => true,
                        'searchable' => true,
                        'filterable' => true,
                        'comparable' => false,
                        'visible_on_front' => true,
                        'used_in_product_listing' => true,
                        'unique' => false,
                        'option' => [
                            'values' => range(1, 20)
                        ],
                        'apply_to' => '',
                    ]
                );
                $eavSetup->addAttributeToSet(
                    $entityTypeId,
                    $eLearningSetId,
                    $groupName,
                    $eavSetup->getAttributeId($entityTypeId, 'minimum_age')
                );
            }
            if(!$eavSetup->getAttributeId($entityTypeId, 'age_requirement'))
            {
                $eavSetup->addAttribute(
                    \Magento\Catalog\Model\Product::ENTITY,
                    'age_requirement',
                    [
                        'type' => 'int',
                        'label' => 'Age Requirement',
                        'input' => 'select',
                        'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE,
                        'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                        'visible' => true,
                        'required' => false,
                        'user_defined' => true,
                        'searchable' => true,
                        'filterable' => true,
                        'comparable' => false,
                        'visible_on_front' => true,
                        'used_in_product_listing' => true,
                        'unique' => false,
                        'option' => [
                            'values' => ['Under 18 years of age']
                        ],
                        'apply_to' => '',
                    ]
                );
                $eavSetup->addAttributeToSet(
                    $entityTypeId,
                    $eLearningSetId,
                    $groupName,
                    $eavSetup->getAttributeId($entityTypeId, 'age_requirement')
                );
            }
        }

        if (version_compare($context->getVersion(), '0.0.5') < 0) {
            if(!$eavSetup->getAttributeId($entityTypeId, 'is_recurring'))
            {
                $eavSetup->addAttribute(
                    \Magento\Catalog\Model\Product::ENTITY,
                    'is_recurring',
                    [
                        'group' => $groupName,
                        'type' => 'int',
                        'label' => 'Is Recurring',
                        'input' => 'select',
                        'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE,
                        'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
                        'visible' => true,
                        'required' => false,
                        'user_defined' => true,
                        'searchable' => true,
                        'filterable' => true,
                        'comparable' => false,
                        'visible_on_front' => true,
                        'used_in_product_listing' => true,
                        'unique' => false,
                        'default' => 0,
                        'apply_to' => '',
                    ]
                );
            }
        }
        if (version_compare($context->getVersion(), '0.0.6') < 0) {
            if(!$eavSetup->getAttributeId($entityTypeId, 'club_discount_elegible'))
            {
                $eavSetup->addAttribute(
                    \Magento\Catalog\Model\Product::ENTITY,
                    'club_discount_elegible',
                    [
                        'group' => $groupName,
                        'type' => 'int',
                        'label' => 'Club Discount Eligible',
                        'input' => 'boolean',
                        'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE,
                        'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
                        'visible' => true,
                        'required' => false,
                        'user_defined' => true,
                        'searchable' => true,
                        'filterable' => true,
                        'comparable' => false,
                        'visible_on_front' => true,
                        'used_in_product_listing' => true,
                        'unique' => false,
                        'default' => 0,
                        'apply_to' => '',
                    ]
                );
            }
        }

        if (version_compare($context->getVersion(), '0.0.6') < 0) {
          if(!$eavSetup->getAttributeId($entityTypeId, 'club_discount_eligible'))
          {
              $eavSetup->addAttribute(
                  \Magento\Catalog\Model\Product::ENTITY,
                  'club_discount_eligible',
                  [
                      'group' => $groupName,
                      'type' => 'int',
                      'label' => 'Club Discount Eligible',
                      'input' => 'boolean',
                      'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE,
                      'source' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
                      'visible' => true,
                      'required' => false,
                      'user_defined' => true,
                      'searchable' => true,
                      'filterable' => true,
                      'comparable' => false,
                      'visible_on_front' => true,
                      'used_in_product_listing' => true,
                      'unique' => false,
                      'default' => 0,
                      'apply_to' => '' ,
                    ]
                );
            }
        }

        if (version_compare($context->getVersion(), '0.0.7') < 0) {
            $entityTypeId = $eavSetup->getEntityTypeId('catalog_product');
            $defaultSetId = $eavSetup->getDefaultAttributeSetId($entityTypeId);
            $data = [
                'attribute_set_name' => ProductType::E_LEARNING,
                'entity_type_id' => $entityTypeId,
                'sort_order' => 0
            ];
            $eLearningSet = $eavSetup->getAttributeSet($entityTypeId, $data['attribute_set_name'], 'attribute_set_name');
            if (!$eLearningSet) {
                $eLearningSet = $this->objectManager->create(AttributeSet::class);
                $eLearningSet->setData($data);
                $eLearningSet->validate();
                $eLearningSet->save();
                $eLearningSet->initFromSkeleton($defaultSetId);
                $eLearningSet->save();
            }
            $data = [
                'attribute_set_name' => ProductType::TOUCH,
                'entity_type_id' => $entityTypeId,
                'sort_order' => 0
            ];
            $touchSet = $eavSetup->getAttributeSet($entityTypeId, $data['attribute_set_name'], 'attribute_set_name');
            if (!$touchSet) {
                $touchSet = $this->objectManager->create(AttributeSet::class);
                $touchSet->setData($data);
                $touchSet->validate();
                $touchSet->save();
                $touchSet->initFromSkeleton($defaultSetId);
                $touchSet->save();
            }
            $data = [
                'attribute_set_name' => 'Gear',
                'entity_type_id' => $entityTypeId,
                'sort_order' => 0
            ];
            $gearSet = $eavSetup->getAttributeSet($entityTypeId, $data['attribute_set_name'], 'attribute_set_name');
            if (!$gearSet) {
                $gearSet = $this->objectManager->create(AttributeSet::class);
                $gearSet->setData($data);
                $gearSet->validate();
                $gearSet->save();
                $gearSet->initFromSkeleton($defaultSetId);
                $gearSet->save();
            }
        }
        if (version_compare($context->getVersion(), '0.0.8') < 0) {
            /** @var ProductCollection $productCollection */
            $productCollection = $this->productCollectionFactory->create();
            $productIds = $productCollection->getAllIds();
            /** @var WebsiteCollection $websiteCollection */
            $websiteCollection = $this->websiteCollectionFactory->create();
            $websiteIds = $websiteCollection->getAllIds();
            $this->productAction->updateWebsites($productIds, $websiteIds, 'add');
        }
        if (version_compare($context->getVersion(), '0.0.9') < 0) {
            if(!$eavSetup->getAttributeId($entityTypeId, 'product_code'))
            {
                $eavSetup->addAttribute(
                    \Magento\Catalog\Model\Product::ENTITY,
                    'product_code',
                    [
                        'group' => $groupName,
                        'type' => 'text',
                        'label' => 'Product Code',
                        'input' => 'text',
                        'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_WEBSITE,
                        'visible' => true,
                        'required' => false,
                        'user_defined' => true,
                        'searchable' => true,
                        'filterable' => true,
                        'comparable' => false,
                        'visible_on_front' => true,
                        'used_in_product_listing' => true,
                        'unique' => false,
                        'default' => '',
                        'apply_to' => '',
                    ]
                );
            }
        }

        if (version_compare($context->getVersion(), '0.0.10') < 0) {
            $entityTypeId = $eavSetup->getEntityTypeId('catalog_product');
            $defaultSetId = $eavSetup->getDefaultAttributeSetId($entityTypeId);
            $data = [
                'attribute_set_name' => ProductType::MY_PADI_CLUB,
                'entity_type_id' => $entityTypeId,
                'sort_order' => 0
            ];
            $myPadiClubSet = $eavSetup->getAttributeSet($entityTypeId, $data['attribute_set_name'], 'attribute_set_name');
            if (!$myPadiClubSet) {
                $myPadiClubSet = $this->objectManager->create(AttributeSet::class);
                $myPadiClubSet->setData($data);
                $myPadiClubSet->validate();
                $myPadiClubSet->save();
                $myPadiClubSet->initFromSkeleton($defaultSetId);
                $myPadiClubSet->save();
            }

            $data = [
                'attribute_set_name' => ProductType::MY_PADI_CLUB_DISCOUNT,
                'entity_type_id' => $entityTypeId,
                'sort_order' => 0
            ];
            $myPadiClubDiscountSet = $eavSetup->getAttributeSet($entityTypeId, $data['attribute_set_name'], 'attribute_set_name');
            if (!$myPadiClubDiscountSet) {
                $myPadiClubDiscountSet = $this->objectManager->create(AttributeSet::class);
                $myPadiClubDiscountSet->setData($data);
                $myPadiClubDiscountSet->validate();
                $myPadiClubDiscountSet->save();
                $myPadiClubDiscountSet->initFromSkeleton($defaultSetId);
                $myPadiClubDiscountSet->save();
            }

            $data = [
                'attribute_set_name' => ProductType::DONATION,
                'entity_type_id' => $entityTypeId,
                'sort_order' => 0
            ];
            $donationSet = $eavSetup->getAttributeSet($entityTypeId, $data['attribute_set_name'], 'attribute_set_name');
            if (!$donationSet) {
                $donationSet = $this->objectManager->create(AttributeSet::class);
                $donationSet->setData($data);
                $donationSet->validate();
                $donationSet->save();
                $donationSet->initFromSkeleton($defaultSetId);
                $donationSet->save();
            }

            $data = [
                'attribute_set_name' => ProductType::TOUCH,
                'entity_type_id' => $entityTypeId,
                'sort_order' => 0
            ];
            $touchSet = $eavSetup->getAttributeSet($entityTypeId, $data['attribute_set_name'], 'attribute_set_name');
            if (!$touchSet) {
                $touchSet = $this->objectManager->create(AttributeSet::class);
                $touchSet->setData($data);
                $touchSet->validate();
                $touchSet->save();
                $touchSet->initFromSkeleton($defaultSetId);
                $touchSet->save();
            }
        }

        if (version_compare($context->getVersion(), '0.0.11') < 0) {
            $groupName = 'Content';
            /** @var \Magento\Eav\Setup\EavSetup $eavSetup */
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'prerequisites_label',
                [
                    'type' => 'text',
                    'label' => 'Prerequisites',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'apply_to' => '',
                    'sort_order' => 100,
                    'default' => 'Prerequisites'
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'prerequisites_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'prerequisites_content',
                [
                    'type' => 'text',
                    'label' => 'Prerequisites - Description',
                    'input' => 'textarea',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'apply_to' => '',
                    'sort_order' => 103,
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'prerequisites_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'average_time_label',
                [
                    'type' => 'text',
                    'label' => 'Average Time',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'apply_to' => '',
                    'default' => 'Average time commitment',
                    'sort_order' => 105,
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'average_time_label')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'average_time_content',
                [
                    'type' => 'text',
                    'label' => 'Average Time - Description',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'sort_order' => 107,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'average_time_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'average_time_content_2',
                [
                    'type' => 'text',
                    'label' => 'Average Time - Description',
                    'input' => 'textarea',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'sort_order' => 111,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'average_time_content_2')
            );


            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'chapters_label',
                [
                    'type' => 'text',
                    'label' => 'Chapters',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'default' => 'Chapters',
                    'sort_order' => 113,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'chapters_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'chapters_content',
                [
                    'type' => 'int',
                    'label' => 'Select Chapters',
                    'input' => 'select',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'option' => [
                        'values' => range(0, 100)
                    ],
                    'sort_order' => 115,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'chapters_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'quizzes_label',
                [
                    'type' => 'text',
                    'label' => 'Quizzes',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'defaul' => 'Quizzes',
                    'sort_order' => 117,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'quizzes_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'quizzes_content',
                [
                    'type' => 'int',
                    'label' => 'Select Quizzes',
                    'input' => 'select',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'option' => [
                        'values' => range(0, 100)
                    ],
                    'sort_order' => 119,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'quizzes_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'tests_label',
                [
                    'type' => 'text',
                    'label' => 'Tests',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'default' => 'Tests',
                    'sort_order' => 121,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'tests_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'tests_content',
                [
                    'type' => 'int',
                    'label' => 'Select Tests',
                    'input' => 'select',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'option' => [
                        'values' => range(0, 100)
                    ],
                    'sort_order' => 123,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'tests_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'what_does_cover_label',
                [
                    'type' => 'text',
                    'label' => 'Cover',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'default' => 'What does it cover?',
                    'sort_order' => 125,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'what_does_cover_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'what_does_cover_content',
                [
                    'type' => 'text',
                    'label' => 'Cover - Description',
                    'input' => 'textarea',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'default' => 'What does it cover?',
                    'sort_order' => 127,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'what_does_cover_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'how_does_work_label',
                [
                    'type' => 'text',
                    'label' => 'How Does Work',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'default' => 'How does it work?',
                    'sort_order' => 129,
                    'apply_to' => ''
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'how_does_work_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'how_does_work_content',
                [
                    'type' => 'text',
                    'label' => 'About Work - Description',
                    'input' => 'textarea',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'sort_order' => 131,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'how_does_work_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'what_else_is_label',
                [
                    'type' => 'text',
                    'label' => 'Required To Course',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'default' => 'What else is required to complete the course',
                    'sort_order' => 133,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'what_else_is_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'what_else_is_content',
                [
                    'type' => 'text',
                    'label' => 'About Required - Description',
                    'input' => 'textarea',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'sort_order' => 135,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'what_else_is_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'what_does_cost_label',
                [
                    'type' => 'text',
                    'label' => 'Cost',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'default' => 'What does it cost?',
                    'sort_order' => 137,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'what_does_cost_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'what_does_cost_content',
                [
                    'type' => 'text',
                    'label' => 'Cost - Description',
                    'input' => 'textarea',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'sort_order' => 139,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'what_does_cost_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'how_long_label',
                [
                    'type' => 'text',
                    'label' => 'How Long',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'default' => 'How long do you have to complete the eLearning course?',
                    'sort_order' => 141,
                    'apply_to' => ''
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'how_long_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'how_long_content',
                [
                    'type' => 'text',
                    'label' => 'How Long - Description',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'sort_order' => 143,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'how_long_content')
            );

            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'how_do_you_document_label',
                [
                    'type' => 'text',
                    'label' => 'Document',
                    'input' => 'text',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'default' => 'How do you document that you have completed the eLearning segment?',
                    'sort_order' => 145,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'how_do_you_document_label')
            );
            $eavSetup->addAttribute(
                \Magento\Catalog\Model\Product::ENTITY,
                'how_do_you_document_content',
                [
                    'type' => 'text',
                    'label' => 'Document - Description',
                    'input' => 'textarea',
                    'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
                    'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                    'visible' => true,
                    'required' => false,
                    'user_defined' => true,
                    'searchable' => true,
                    'filterable' => true,
                    'comparable' => false,
                    'visible_on_front' => true,
                    'used_in_product_listing' => true,
                    'unique' => false,
                    'sort_order' => 147,
                    'apply_to' => '',
                ]
            );
            $eavSetup->addAttributeToSet(
                $entityTypeId,
                $eLearningSetId,
                $groupName,
                $eavSetup->getAttributeId($entityTypeId, 'how_do_you_document_content')
            );
        }

        if (version_compare($context->getVersion(), '0.0.12') < 0) {
            /** @var EavSetup $eavSetup */
            $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

            /**
             * Install eav entity types to the eav/entity_type table
             */
            $eavSetup->addAttribute(
                'catalog_product',
                'top_image',
                [
                    'type' => 'varchar',
                    'label' => 'Top Header',
                    'input' => 'media_image',
                    'frontend' => 'Magento\Catalog\Model\Product\Attribute\Frontend\Image',
                    'required' => false,
                    'sort_order' => 4,
                    'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
                    'used_in_product_listing' => true
                ]
            );

            $groupId = (int)$eavSetup->getAttributeGroupByCode(
                \Magento\Catalog\Model\Product::ENTITY,
                'Default',
                'image-management',
                'attribute_group_id'
            );
            $eavSetup->addAttributeToGroup(\Magento\Catalog\Model\Product::ENTITY, 'Default', $groupId, 'top_image');
        }

        if (version_compare($context->getVersion(), '0.0.13') < 0) {
            $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'chapters_content', 'frontend_input', 'text');
            $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'chapters_content', 'frontend_class', 'validate-number');

            $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'quizzes_content', 'frontend_input', 'text');
            $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'quizzes_content', 'frontend_class', 'validate-number');

            $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'tests_content', 'frontend_input', 'text');
            $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, 'tests_content', 'frontend_class', 'validate-number');
        }

        if (version_compare($context->getVersion(), '0.0.14') < 0) {

            $discountAtrributeSet   = $eavSetup->getAttributeSetId($entityTypeId,\Padi\ApiClub\Model\ProductType::MY_PADI_CLUB_DISCOUNT);
            $reActivate             = $this->productRepository->get(\Padi\ApiClub\Model\ProductType::REACTIVATE_SKU);
            $discountCode           = $this->productRepository->get($reActivate->getData('product_code'));
            $discountCode->setAttributeSetId($discountAtrributeSet);
            $this->productRepository->save($discountCode);
        }

        if (version_compare($context->getVersion(), '0.0.15') < 0) {

            $productMyPadiClub1 = $this->productRepository->get('40941-1');
            $productMyPadiClub1->setName('My PADI Club Premium Membership');

            $productMyPadiClub2 = $this->productRepository->get('40941-2');
            $productMyPadiClub2->setName('My PADI Club Premium Membership');

            $productAwareDonation = $this->productRepository->get('2102166');
            $productAwareDonation->setName('Project AWARE Donation');

            $this->productRepository->save($productMyPadiClub1);
            $this->productRepository->save($productMyPadiClub2);
            $this->productRepository->save($productAwareDonation);
        }
      
        $setup->endSetup();
    }

    protected function getObjectManager()
    {
        return $this->objectManager;
    }
}

以上是关于text 创建属性,组属性的主要内容,如果未能解决你的问题,请参考以下文章

XSL:根据属性计数和匹配创建组

为啥 System.Text.RegularExpressions.Group 没有 Name 属性?

php 创建属性产品,组

text 创建和保存客户属性

text 创建属性multiselect

鸿蒙开发|Button组件