Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Cnc/SerialNumber/Setup/Patch/Data/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/SerialNumber/Setup/Patch/Data/CreateProductSerialNumberAttribute.php
<?php

declare(strict_types=1);

namespace Cnc\SerialNumber\Setup\Patch\Data;

use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\DB\Ddl\Table;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;

class CreateProductSerialNumberAttribute implements DataPatchInterface
{
    /** @var ModuleDataSetupInterface */
    private $moduleDataSetup;
    /** @var EavSetupFactory */
    private $eavSetupFactory;

    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        EavSetupFactory $eavSetupFactory
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->eavSetupFactory = $eavSetupFactory;
    }

    public static function getDependencies(): array
    {
        return [];
    }

    public function apply(): void
    {
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);
        $attributes = $this->getAttributes();
        $entityTypeId = 'catalog_product';

        foreach ($attributes as $code => $attribute) {
            $eavSetup->addAttribute($entityTypeId, $code, [
                'label' => $attribute['label'],
                'input' => $attribute['input'],
                'type' => $attribute['type'],
                'source' => $attribute['source'],
                'required' => $attribute['required'],
                'position' => $attribute['position'],
                'visible' => $attribute['visible'],
                'system' => $attribute['system'],
                'is_used_in_grid' => $attribute['is_used_in_grid'],
                'is_visible_in_grid' => $attribute['is_visible_in_grid'],
                'is_filterable_in_grid' => $attribute['is_filterable_in_grid'],
                'is_searchable_in_grid' => $attribute['is_searchable_in_grid'],
                'definition' => [
                    'type' => $attribute['definition']['type'],
                    'nullable' => $attribute['definition']['nullable'],
                    'comment' => $attribute['definition']['comment'],
                ],
            ]);
        }
    }

    private function getAttributes(): array
    {
        return [
            'manufacturer_id' => [
                'label' => 'Origin',
                'input' => 'text',
                'type' => 'static',
                'source' => '',
                'required' => false,
                'position' => 10,
                'visible' => true,
                'system' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'definition' => [
                    'type' => Table::TYPE_TEXT,
                    'nullable' => true,
                    'comment' => 'Origin',
                ],
            ],
            'sn_created_at' => [
                'label' => 'Created At',
                'input' => 'date',
                'type' => 'static',
                'source' => '',
                'required' => false,
                'position' => 20,
                'visible' => true,
                'system' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'definition' => [
                    'type' => Table::TYPE_DATE,
                    'nullable' => true,
                    'comment' => 'Created At',
                ],
            ],
            'sn_created_by' => [
                'label' => 'Created By',
                'input' => 'text',
                'type' => 'static',
                'source' => '',
                'required' => false,
                'position' => 30,
                'visible' => true,
                'system' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'definition' => [
                    'type' => Table::TYPE_TEXT,
                    'nullable' => true,
                    'comment' => 'Created By',
                ],
            ],
            'sn_source_stock' => [
                'label' => 'Source Stock',
                'input' => 'text',
                'type' => 'static',
                'source' => '',
                'required' => false,
                'position' => 40,
                'visible' => true,
                'system' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'definition' => [
                    'type' => Table::TYPE_TEXT,
                    'nullable' => true,
                    'comment' => 'Source Stock',
                ],
            ],
        ];
    }

    public function getAliases(): array
    {
        return [];
    }
}

Spamworldpro Mini