Giter VIP home page Giter VIP logo

syliusimportplugin's Introduction

Asdoria Import Bundle

Simply import resource intro sylius by messenger component

Features

  • import resource intro sylius by messenger componant

Installation


  1. run composer require asdoria/sylius-import-plugin
Asdoria\SyliusImportPlugin\AsdoriaSyliusImportPlugin::class => ['all' => true],
  1. Import config in config/packages/_sylius.yaml
imports:
    - { resource: "@AsdoriaSyliusImportPlugin/Resources/config/config.yaml"}
  1. Import config in config/packages/_sylius.yaml
imports:
    - { resource: "@AsdoriaSyliusImportPlugin/Resources/config/config.yaml"}
  1. Import messenger transport
php bin/console messenger:setup-transports
  1. Create your symfony command for push message into the queues
<?php

namespace App\Command;


use App\Entity\User\ShopUser;
use Asdoria\SyliusImportPlugin\Configurator\Configuration;
use Asdoria\SyliusImportPlugin\Configurator\ConfigurationInterface;
use Asdoria\SyliusImportPlugin\Message\ImportNotification;
use Doctrine\DBAL\Connection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Messenger\MessageBusInterface;
use App\Entity\Customer\Customer;
/**
 * Class ImportCustomerCommand
 * @package App\Command
 *
 * @author  Philippe Vesin <[email protected]>
 */
class ImportCustomerCommand extends Command
{
    const _SQL = "select 
JSON_OBJECT('email', email, 'lastName',lastname, 'firstName', firstname, 'companyName', company, 'professional', is_company, 'siret', siret, 'gender', case 
     WHEN id_gender = 1 THEN 'm'
	 WHEN id_gender = 2 THEN  'f'
else  'u' end, 'createdAt', date_add, 'updatedAt' , date_upd,'acceptPolicy',optin, 'subscribedToNewsletter', newsletter, 'birthday', birthday ) as customer,
1 as enabled,
passwd as password,
secure_key as salt,
email as username
from bdi_customer where id_shop = 1 and active = 1 limit 200 ;";
    protected Connection $connection;
    protected MessageBusInterface $bus;
    /**
     *
     */
    public function __construct(
        MessageBusInterface $bus,
        Connection $connection
    ) {
        parent::__construct();
        $this->connection = $connection;
        $this->bus = $bus;
    }
    /**
     *
     */
    protected function configure()
    {
        $this
            ->setName('app:import:customer')
            ->setDescription(
                'Import Prestashop Customer.'
            );
    }

    /**
     * @param InputInterface  $input
     * @param OutputInterface $output
     */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        try {
            $this->connection->getConfiguration()->setSQLLogger(null);
            $reader = $this->connection->fetchAllAssociative(self::_SQL);
            $config = $this->getConfiguration();
            foreach ($reader as $row) {
                $this->bus->dispatch(new ImportNotification($row, ShopUser::class, $config));
            }
        } catch (\Throwable $e) {
            $output->writeln('<error>Error during import customer , aborting with rollback : done error</error>');
            $output->writeln($e->getMessage());
        }

        return 0;
    }

    protected function getConfiguration(): ConfigurationInterface {
        $configuration = new Configuration();
        $configuration->setIdentifier('username');
        $configuration->setProvider(ConfigurationInterface::_PRESTASHOP_PROVIDER);
        $configuration->setUpdater(true);

        return $configuration;
    }
}
  1. Play the messanger consume worker for unstack the queues
php bin/console messenger:consume asdoria_import -vv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.