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

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Cnc/Checkout/Setup/Patch/Data/CreateMSIStockAttributes.php
<?php
/**
 * Copyright (c) 2021 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * Cnc
 * Krzysztof Majkowski <[email protected]>
 */

namespace Cnc\Checkout\Setup\Patch\Data;

use Kaliop\Core\Model\Import\AbstractImport;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Module\Dir\Reader;
use Magento\Framework\Setup\Patch\DataPatchInterface;
use Psr\Log\LoggerInterface;
use Wyomind\MsiCustomAttributes\Model\CustomAttributeFactory;

class CreateMSIStockAttributes extends AbstractImport implements DataPatchInterface
{
    /**
     * @var LoggerInterface
     */
    private $logger;

    /**
     * @var CustomAttributeFactory
     */
    private $customAttributeFactory;

    /**
     * @var ResourceConnection
     */
    private $resourceConnection;

    /**
     * CreateMSIStockAttributes constructor.
     * @param LoggerInterface $logger
     * @param CustomAttributeFactory $customAttributeFactory
     * @param ResourceConnection $resourceConnection
     * @param File $fileSystem
     * @param DirectoryList $directoryList
     * @param Reader $moduleReader
     */
    public function __construct(
        LoggerInterface $logger,
        CustomAttributeFactory $customAttributeFactory,
        ResourceConnection $resourceConnection,
        File $fileSystem,
        DirectoryList $directoryList,
        Reader $moduleReader
    ) {
        parent::__construct($fileSystem, $directoryList, $moduleReader);

        $this->logger = $logger;
        $this->customAttributeFactory = $customAttributeFactory;
        $this->resourceConnection = $resourceConnection;
    }

    /**
     * @return ConfigureMSIStocks|void
     */
    public function apply()
    {
        $conn = $this->resourceConnection->getConnection();

        $attributes = $this->getAttributes();
        foreach ($attributes as $attribute) {
            $code = $attribute['code'];

            $conn->delete('msi_custom_attribute', "code = '{$code}'");
            $conn->insert(
                'msi_custom_attribute',
                [
                    'code' => $code,
                    'label' => $attribute['label'],
                    'type' => $attribute['type'],
                    'sort_order' => $attribute['sort_order']
                ]
            );
        }
    }

    /**
     * @return array|string[]
     */
    public static function getDependencies(): array
    {
        return [];
    }

    /**
     * @return array|string[]
     */
    public function getAliases(): array
    {
        return [];
    }

    /**
     * @return array[]
     */
    protected function getAttributes(): array
    {
        return [
            [
                'code' => 'cnc_vhs',
                'label' => 'VHS',
                'type' => 'bool',
                'sort_order' => 20
            ]
        ];
    }
}

Spamworldpro Mini