jorisros / library-product-exporter
There is no license information available for the latest version (v1.2) of this package.
v1.2
2025-04-12 00:45 UTC
Requires
- guzzlehttp/guzzle: ^7.9
- symfony/config: ^7.2
Requires (Dev)
- phpunit/phpunit: ^11.5
- squizlabs/php_codesniffer: ^3.12
- vimeo/psalm: ^6.7
This package is auto-updated.
Last update: 2025-04-12 00:46:17 UTC
README
Requements
- Minumal PHP version 8.2
Usage
Add the library to your project
composer require jorisros/product-exporter
Create a file example.php
<?php use Symfony\Component\Config\Definition\Processor; require_once "vendor/autoload.php"; $configuration = new \JorisRos\LibraryProductExporter\Connector\Configuration(); $reader = new \JorisRos\LibraryProductExporter\Connector\ReaderJson($configuration); $reader->read(file_get_contents("file.json")); $connector = new \JorisRos\LibraryProductExporter\Connector( $reader, new JorisRos\LibraryProductExporter\Processor\DefaultProcessor([ 'name' => 'Generic product connector', 'icon' => '/icon.gif', 'arguments' => [ 'shopClass' => '\\Bla', 'shopId' => 100 ], 'mapping' => [ [ 'destinationField' => 'product.title', 'sourceField' => 'productTitle', 'transformer' => 'JorisRos\\LibraryProductExporter\\Transform\\Capital' ] ], 'transport' => [ 'class' => '\\JorisRos\\LibraryProductExporter\\Transport\\TransportGuzzle', 'options' => [ 'access-token' => '', 'url' => '' ] ] ], [ new \JorisRos\LibraryProductExporter\Transform\Capital(), ] ) ); $data = $connector->process([ 'productTitle' => 'Hello product', 'sku' => '00001', 'price' => 9.95, 'valuta' => 'EUR', 'category' => 'clothing', 'attributes' => [ [ 'size' => 'small', ], [ 'color' => 'white' ] ] ]);
Run that file
php example.php
Where $data
will be transformed as below
array(1) { ["product"]=> array(1) { ["title"]=> string(13) "Hello product" } }
Transformers
The library has the following transformer
Money to float
To convert the prices to a float for example € 12,30
to 12.30
.
Add the class JorisRos\LibraryProductExporter\Transform\MoneyToFloat
to the mapper.
Capital
To convert the string to for example t-shirt
to T-shirt
.
Add the class JorisRos\LibraryProductExporter\Transform\Capital
to the mapper.
Tests
composer install
php vendor/bin/phpunit tests