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/CreateCncPaymentAttributes.php
<?php
/**
 * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * Cnc
 * Radosław Stępień <[email protected]> <[email protected]>
 */
namespace Cnc\Customer\Setup\Patch\Data;

use Cnc\Customer\Model\Config;
use Magento\Customer\Model\Customer;
use Magento\Eav\Model\Config as EavConfig;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
use Magento\Customer\Model\Attribute\Backend\Data\Boolean;
use Magento\Eav\Setup\EavSetup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Zend_Validate_Exception;

class CreateCncPaymentAttributes implements DataPatchInterface
{
    const ATTRIBUTES_TO_UPDATE = [
        Config::CUSTOMER_ATTRIBUTE_ENABLE_OFF_PAY_CODE,
        Config::CUSTOMER_ATTRIBUTE_ENABLE_PAYMENT_ON_RECEIPT_INVOICE
    ];

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

    /**
     * EavSetupFactory
     *
     * @var EavSetupFactory
     */
    private $eavSetupFactory;

    /**
     * @var EavConfig
     */
    private $eavConfig;

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

    /**
     * CreateCncPaymentAttributes constructor.
     *
     * @param EavConfig $eavConfig
     * @param ModuleDataSetupInterface $moduleDataSetup
     * @param EavSetupFactory $eavSetupFactory
     * @param AttributeSetFactory $attributeSetFactory
     */
    public function __construct(
        EavConfig $eavConfig,
        ModuleDataSetupInterface $moduleDataSetup,
        EavSetupFactory $eavSetupFactory,
        AttributeSetFactory $attributeSetFactory
    ) {
        $this->eavConfig = $eavConfig;
        $this->moduleDataSetup = $moduleDataSetup;
        $this->eavSetupFactory = $eavSetupFactory;
        $this->attributeSetFactory = $attributeSetFactory;
    }

    /**
     * Get array of patches that have to be executed prior to this.
     * @return string[]
     */
    public static function getDependencies()
    {
        return [];
    }

    /**
     * Get aliases (previous names) for the patch.
     *
     * @return string[]
     */
    public function getAliases()
    {
        return [];
    }

    /**
     * Run code inside patch
     * @return void
     * @throws LocalizedException
     * @throws Zend_Validate_Exception
     */
    public function apply()
    {
        /** @var EavSetup $eavSetup */
        $eavSetup = $this->eavSetupFactory->create(['setup' => $this->moduleDataSetup]);

        $customerEntity = $this->eavConfig->getEntityType('customer');
        $attributeSetId = $customerEntity->getDefaultAttributeSetId();

        $attributeSet = $this->attributeSetFactory->create();
        $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);

        $eavSetup->addAttribute(Customer::ENTITY, Config::CUSTOMER_ATTRIBUTE_ENABLE_OFF_PAY_CODE, [
            'label' => 'Is offline payment enable?',
            'type' => 'int',
            'backend' => Boolean::class,
            'input' => 'boolean',
            'global' => ScopedAttributeInterface::SCOPE_STORE,
            'user_defined' => true,
            'system' => false,
            'required' => false,
            'position' => 1080,
            'is_visible' => true,
            'default' => false,
        ]);
        $eavSetup->addAttribute(Customer::ENTITY, Config::CUSTOMER_ATTRIBUTE_ENABLE_PAYMENT_ON_RECEIPT_INVOICE, [
            'label' => 'Is payment on receipt of invoice enable?',
            'type' => 'int',
            'backend' => Boolean::class,
            'input' => 'boolean',
            'global' => ScopedAttributeInterface::SCOPE_STORE,
            'user_defined' => true,
            'system' => false,
            'required' => false,
            'position' => 1090,
            'is_visible' => true,
            'default' => false,
        ]);

        foreach (self::ATTRIBUTES_TO_UPDATE as $attrCode) {
            $customAttribute = $this->eavConfig->getAttribute(
                'customer',
                $attrCode
            );

            $customAttribute->addData([
                'attribute_set_id' => $attributeSetId,
                'attribute_group_id' => $attributeGroupId,
                'used_in_forms' => ['adminhtml_customer', 'customer_account_edit']
            ]);
            $customAttribute->save();
        }
    }
}

Spamworldpro Mini