jorisros/library-product-exporter
最新稳定版本:v1.2
Composer 安装命令:
composer require jorisros/library-product-exporter
包简介
README 文档
README
Requirements
- 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
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-04-11