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/Customer/Setup/Patch/Data/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

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

declare(strict_types=1);

namespace Cnc\Customer\Setup\Patch\Data;

use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;

class CustomerAttributes implements DataPatchInterface
{
    private $attributes = [
        'customer' => [
            'cnc_industry_sector' => [
                'type' => 'int',
                'label' => 'Industry sector',
                'input' => 'select',
                'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                'required' => false,
                'sort_order' => 1000,
                'visible' => true,
                'system' => false,
                'default' => null,
                'user_defined' => false,
                'is_user_defined' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'position' => 1000,
                'option' => [
                    'values' => [
                        'Aerospace',
                        'Automotive',
                        'Agri-food',
                        'Metallurgy',
                        'Pharmaceutical',
                        'Metal transformation',
                        'Precision mechanics',
                        'Naval'
                    ]
                ],
            ],
            'cnc_post' => [
                'type' => 'varchar',
                'label' => 'Post',
                'input' => 'text',
                'required' => false,
                'sort_order' => 1010,
                'visible' => true,
                'system' => false,
                'default' => null,
                'user_defined' => false,
                'is_user_defined' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'position' => 1010
            ],
            'cnc_source' => [
                'type' => 'int',
                'label' => 'Source',
                'input' => 'select',
                'source' => \Magento\Eav\Model\Entity\Attribute\Source\Table::class,
                'required' => false,
                'sort_order' => 1020,
                'visible' => true,
                'system' => false,
                'default' => null,
                'user_defined' => false,
                'is_user_defined' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'position' => 1020,
                'option' => [
                    'values' => [
                        'Google',
                        'Social media',
                        'Third party',
                        'Advertising',
                        'Word of mouth'
                    ]
                ],
            ],
            'cnc_purchasing_department_email' => [
                'type' => 'varchar',
                'label' => 'Purchasing department email',
                'input' => 'text',
                'required' => false,
                'sort_order' => 1030,
                'visible' => true,
                'system' => false,
                'default' => null,
                'user_defined' => false,
                'is_user_defined' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'position' => 1030
            ],
            'cnc_purchasing_department_phone' => [
                'type' => 'varchar',
                'label' => 'Purchasing department phone',
                'input' => 'text',
                'required' => false,
                'sort_order' => 1040,
                'visible' => true,
                'system' => false,
                'default' => null,
                'user_defined' => false,
                'is_user_defined' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'position' => 1040
            ],
            'cnc_accounts_department_email' => [
                'type' => 'varchar',
                'label' => 'Accounts department email',
                'input' => 'text',
                'required' => false,
                'sort_order' => 1050,
                'visible' => true,
                'system' => false,
                'default' => null,
                'user_defined' => false,
                'is_user_defined' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'position' => 1050
            ],
            'cnc_accounts_department_phone' => [
                'type' => 'varchar',
                'label' => 'Accounts department phone',
                'input' => 'text',
                'required' => false,
                'sort_order' => 1060,
                'visible' => true,
                'system' => false,
                'default' => null,
                'user_defined' => false,
                'is_user_defined' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'position' => 1060
            ],
            'cnc_technical_service_phone' => [
                'type' => 'varchar',
                'label' => 'Technical service phone',
                'input' => 'text',
                'required' => false,
                'sort_order' => 1070,
                'visible' => true,
                'system' => false,
                'default' => null,
                'user_defined' => false,
                'is_user_defined' => false,
                'is_used_in_grid' => false,
                'is_visible_in_grid' => false,
                'is_filterable_in_grid' => false,
                'is_searchable_in_grid' => false,
                'position' => 1070
            ],
        ]
    ];

    /**
     * @var ModuleDataSetupInterface
     */
    private $moduleDataSetup;

    /**
     * @var CustomerSetupFactory
     */
    private $customerSetupFactory;

    /**
     * @var AttributeSetFactory
     */
    private $attributeSetFactory;

    /**
     * CustomerAttributes constructor.
     * @param ModuleDataSetupInterface $moduleDataSetup
     * @param CustomerSetupFactory $customerSetupFactory
     * @param AttributeSetFactory $attributeSetFactory
     */
    public function __construct(
        ModuleDataSetupInterface $moduleDataSetup,
        CustomerSetupFactory $customerSetupFactory,
        AttributeSetFactory $attributeSetFactory
    ) {
        $this->moduleDataSetup = $moduleDataSetup;
        $this->customerSetupFactory = $customerSetupFactory;
        $this->attributeSetFactory = $attributeSetFactory;
    }

    public function apply(): void
    {
        /** @var CustomerSetup $customerSetup */
        $customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
        $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
        $attributeSetId = $customerEntity->getDefaultAttributeSetId();

        /** @var $attributeSet AttributeSet */
        $attributeSet = $this->attributeSetFactory->create();
        $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

        $customerAttributes = $this->attributes['customer'];
        foreach ($customerAttributes as $attributeName => $attributeData) {
            $customerSetup->addAttribute(
                Customer::ENTITY,
                $attributeName,
                $attributeData
            );

            $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, $attributeName);
            $attribute->addData([
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => [
                    'customer_account_create',
                    'customer_account_edit',
                    'checkout_register',
                    'adminhtml_customer'
                ],
            ]);

            $attribute->save();
        }

        $entityAttributes = [
            'customer' => [
                'gender' => [
                    'is_visible' => false
                ],
                'prefix' => [
                    'is_visible' => true
                ]
            ]
        ];
        $customerSetup->upgradeAttributes($entityAttributes);
    }

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

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

Spamworldpro Mini