From 5fef756af86604ac4fbdfcb25e566ba2811b76af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20B=C3=A9jean?= <nicolas@bejean.eu> Date: Sun, 28 Feb 2021 18:21:39 +0100 Subject: [PATCH] feat: Delete Old Helper --- Helper/SendCustomer.php | 137 ---------------------------------------- 1 file changed, 137 deletions(-) delete mode 100755 Helper/SendCustomer.php diff --git a/Helper/SendCustomer.php b/Helper/SendCustomer.php deleted file mode 100755 index 2fee255..0000000 --- a/Helper/SendCustomer.php +++ /dev/null @@ -1,137 +0,0 @@ -<?php -namespace NicolasBejean\Customer\Helper; - -use Magento\Framework\App\Helper\AbstractHelper; -use Magento\Framework\App\Helper\Context; - -use Magento\Customer\Api\Data\CustomerInterface; -use Magento\Framework\Exception\FileSystemException; -use Magento\Store\Api\StoreRepositoryInterface; - -use Magento\Framework\Filesystem; -use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\File\Csv; - -use Magento\Framework\Exception\NoSuchEntityException; - -/** - * Class SendCustomer - * - * @category PHP - * @package NicolasBejean\Customer\Helper - * @author Nicolas Béjean <nicolas@bejean.eu> - * @license https://lab.frogg.it/bejean-developpement/magento-2/modules/customer/-/blob/master/LICENCE GPL3 Licence - * @link https://www.bejean.eu - */ -class SendCustomer extends AbstractHelper -{ - /** - * @var array - */ - protected array $data; - - /** - * @var StoreRepositoryInterface - */ - protected StoreRepositoryInterface $storeRepository; - - /** - * @var Filesystem - */ - protected Filesystem $filesystem; - - /** - * @var DirectoryList - */ - protected DirectoryList $directoryList; - - /** - * @var Csv - */ - protected Csv $csvProcessor; - - /** - * SendCustomer constructor. - * - * @param Context $context - * @param StoreRepositoryInterface $storeRepository - * @param Filesystem $filesystem - * @param DirectoryList $directoryList - * @param Csv $csvProcessor - */ - public function __construct( - Context $context, - StoreRepositoryInterface $storeRepository, - Filesystem $filesystem, - DirectoryList $directoryList, - Csv $csvProcessor - ) { - $this->storeRepository = $storeRepository; - - $this->filesystem = $filesystem; - $this->directoryList = $directoryList; - $this->csvProcessor = $csvProcessor; - - parent::__construct($context); - } - - /** - * Récupère les données du customer et l'origine - * Mappe les données dans le tableau pour l'écrire dans le CSV - * - * @param string $origin - * @param CustomerInterface $customer - */ - public function execute(string $origin, CustomerInterface $customer) - { - return 'toto'; - /* Mise en place des données du customer dans le tableau de data */ - $this->data[0]['id'] = $customer->getId(); - $this->data[0]['firstname'] = $customer->getFirstname(); - $this->data[0]['lastname'] = $customer->getLastname(); - $this->data[0]['email'] = $customer->getEmail(); - $this->data[0]['created_at'] = $customer->getCreatedAt(); - $this->data[0]['origin'] = $origin; - - try { - /* Récupére le nom du store */ - $store = $this->storeRepository->getById($customer->getStoreId()); - $this->data[0]['storeName'] = $store->getName(); - } catch (NoSuchEntityException $e) { - /* Si le nom du store ne peut pas être récupéré, on force la valeur de storeName */ - $this->data[0]['storeName'] = 'unknown'; - } - - $this->writeToCsv(); - } - - /** - * Ecrit les données dans le fichier CSV - */ - private function writeToCsv () { - try { - /* Récupère le dossier où seront exportées les données */ - $dirPath = $this->directoryList->getPath(DirectoryList::VAR_DIR) . '/exportCustomer'; - } catch (FileSystemException $e) { - die ('Unable to get dirPath !'); - } - - /* Vérifie si le dossier existe */ - if (!is_dir($dirPath)) { - /* Créé le dossier si il n'existe pas */ - mkdir($dirPath, 0750, true); - } - - /* Définit le nom du fichier qui sera créé */ - $filename = 'customer_' . $this->data[0]['id']; - /* Défini le path du fichier */ - $filePath = $dirPath . '/' . $filename . '.csv'; - - try { - /* Enregistre les données dans le fichier */ - $this->csvProcessor->appendData($filePath, $this->data); - } catch (FileSystemException $e) { - die ('Unable to save file !'); - } - } -} -- GitLab