Files
ltsecurityinc/app/code/Lts/Customer/Setup/Patch/Schema/AddIsNetsuiteSyncCustomerAttribute.php

95 lines
2.7 KiB
PHP

<?php
/**
* Copyright © All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Lts\Customer\Setup\Patch\Schema;
use Magento\Customer\Model\Customer;
use Magento\Customer\Setup\CustomerSetup;
use Magento\Customer\Setup\CustomerSetupFactory;
use Magento\Eav\Model\Entity\Attribute\Set;
use Magento\Eav\Model\Entity\Attribute\SetFactory;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
class AddIsNetsuiteSyncCustomerAttribute implements DataPatchInterface, PatchRevertableInterface
{
/**
* Constructor
*
* @param ModuleDataSetupInterface $moduleDataSetup
* @param CustomerSetupFactory $customerSetupFactory
* @param SetFactory $attributeSetFactory
*/
public function __construct(
private ModuleDataSetupInterface $moduleDataSetup,
private CustomerSetupFactory $customerSetupFactory,
private SetFactory $attributeSetFactory
) {
}
/**
* @return void
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Validator\ValidateException
*/
public function apply(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
$customerSetup->addAttribute(
Customer::ENTITY,
'netsuite_cseg_ncg_rep_office',
[
'label' => 'netsuite_cseg_ncg_rep_office',
'input' => 'text',
'type' => 'static',
'source' => '',
'required' => false,
'position' => 333,
'visible' => false,
'system' => false,
'backend' => ''
]
);
$this->moduleDataSetup->getConnection()->endSetup();
}
public function revert(): void
{
$this->moduleDataSetup->getConnection()->startSetup();
/** @var CustomerSetup $customerSetup */
$customerSetup = $this->customerSetupFactory->create(['setup' => $this->moduleDataSetup]);
$customerSetup->removeAttribute(\Magento\Customer\Model\Customer::ENTITY, 'is_netsuite_sync');
$this->moduleDataSetup->getConnection()->endSetup();
}
/**
* {@inheritdoc}
*/
public function getAliases(): array
{
return [];
}
/**
* {@inheritdoc}
*/
public static function getDependencies(): array
{
return [
];
}
}