PHP code example of sndsabin / import-bundle

1. Go to this page and download the library: Download sndsabin/import-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

sndsabin / import-bundle example snippets


bin/console pimcore:bundle:enable ImportBundle



namespace App\Mapper;

use Pimcore\Model\DataObject\Customer;
use SNDSABIN\ImportBundle\Helper\IdentifierType;
use SNDSABIN\ImportBundle\Contract\MapperInterface;

class CustomerMapper implements MapperInterface
{
    /** @var string */
    const FOLDER = 'customer'; // the folder inside which all customer data objects would be created

    /**
     * @param array $data
     * @return array
     */
    public function map(array $data): array
    {
        return [
            'folder' => self::FOLDER, // mandatory
            'class' => Customer::class, // mandatory
            'identifier' => [ // analogous to primary key: used for update operation (mandatory) 
                'attribute' => 'code',
                'value' => $data['Code'],
                'type' => IdentifierType::NON_CONDITIONAL
            ],
            'attributes' => [
                'code' => $data['Code'],
                'firstname' => $data['First Name'],
                'lastname' => $data['Last Name'],
                'email' => $data['Email'],
                'company' => $data['Company'],
                'address' => $data['Address'],
                'country' => $data['Country'],
                'phone' => $data['Phone'],
                'acceptsMarketing' => (bool) $data['Accepts Marketing'],
                'key' => "{$data['Code']}-{$data['First Name']}", // o_key (mandatory)
                'localisedField' => [
                    [
                        'attribute' => 'note',
                        'value' => $data['Note English'],
                        'language' => 'en'
                    ],
                    [
                        'attribute' => 'note',
                        'value' => $data['Note Nepali'],
                        'language' => 'ne'
                    ]
                ]
            ]
        ];

    }
}

bin/console data:import [options]

Options:
  -c, --class=CLASS                     DataObject whose data is to be imported
  -f, --file[=FILE]                     path of the data file
      --book-keeping|--no-book-keeping  maintain the records (or do not maintain --no-book-keeping) of imported file

bin/console data:import -c customer