-
Notifications
You must be signed in to change notification settings - Fork 5
Home
- Welcome to the libflexport wiki
This project is offically maintained by FINDOLOGIC. It provides a export library written in PHP which generates a XML or CSV according to the FINDOLOGIC export patterns. Before using this library you should understand how a export file should look like. See https://docs.findologic.com for further information.
The CSV-Export is UNDER CONSTRUCTION and not intended to be used in production!
Term | Meaning |
---|---|
item | An item represents a product in the feed |
elements | Elements in the following context are blocks in the feed which are added to the item such as an attribute or property |
attributes | Attributes are better know as filters which are configurable via the FINDOLOGIC customer account |
properties | Properties are used to display additional information of the product. |
It is recommended to use composer to install the library in the project as most shopsystems come with composer support upfront. If you don't know how to use composer open the following documentation.
$ composer require findologic/libflexport
After installing via composer, you can use the library by including the namespaces of the objects needed. In the examples below we assume that the library is loaded and accessible in the whole project.
<?php
use FINDOLOGIC\Export\Exporter;
<?php
require_once __DIR__ . '/vendor/autoload.php';
use FINDOLOGIC\Export\Exporter;
Calling the method Exporter::create()
with a type is required.
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_CSV);
Please have in mind, that the item has to have at least a price set.
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
The following code is for demonstration only!
For most of the elements there is a easy way to add an element to the item by calling the following schema.
<?php
/**
* Replace the placeholder <Elementtype> with the element you want to add.
* Usergroup is supported by most of the elements. See XML export patterns for
* more information.
*/
$item->addElementtype('value', 'usergroup');
More complex element types are added by providing an object via the parameter.
<?php
// Replace the placeholder <Elementtype> with the element you want to add
$elementtype = new Elementtype();
$elementtype->doStuff();
$item->addElementtype($element);
// Shorter way
$item->addElementtype(new Elementtype('doStuff'));
Adding mutliple elements at once is also possible for most types.
<?php
// Replace the placeholder <Elementtype> with the element you want to add
$arrayOfElements = [];
// First
$arrayOfElements[] = new Elementtype('dostuff');
// Secound
$arrayOfElements[] = new Elementtype('dostuffagain');
$item->setAllElementtypes($arrayOfElements);
NOTE! The examples show the easiest way to add an element to the item.
<?php
use FINDOLOGIC\Export\Exporter;
use FINDOLOGIC\Export\Data\Ordernumber;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addOrdernumber(new Ordernumber('13132452'));
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addName('Productname');
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addSummary('A short description of the product!');
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addDescription('Here should be the detailed description of the product!');
The price may not be empty and must be a numeric value like an integer or float.
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addPrice(44.8);
The added URL must include the http://
or https://
protocol.
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addUrl('https://www.store.com/produkt/detail/link.html');
The URL of the images must include the http://
or https://
protocol.
<?php
use FINDOLOGIC\Export\Exporter;
use FINDOLOGIC\Export\Data\Image;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addImage(new Image('https://www.store.com/link/to/image.jpg'));
// Adding a additonal thumbnail image
$item->addImage(new Image('https://www.store.com/link/to/image/thumbnail.jpg', Image::TYPE_THUMBNAIL));
<?php
use FINDOLOGIC\Export\Exporter;
use FINDOLOGIC\Export\Data\Keyword;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addKeyword(new Keyword('Keyword'));
<?php
use FINDOLOGIC\Export\Exporter;
use FINDOLOGIC\Export\Data\Usergroup;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addUsergroup(new Usergroup('usergroup'));
The bonus value may not be empty and must be a numeric value like an integer or float.
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addBonus(3);
The salesfrequency element may not be empty and must be a non negative integer.
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addSalesFrequency(5);
The value of the date added element must be a \DateTime
-object.
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addDateAdded(new \DateTime());
The sort element may not be empty and must be an integer.
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addSort(5);
The added attribute values must not be empty and have to be collected in an array.
<?php
use FINDOLOGIC\Export\Exporter;
use FINDOLOGIC\Export\Data\Attribute;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$attributeValues = [
'value 1',
'value 2',
'value 3'
];
$item->addAttribute(new Attribute('attributename', $attributeValues));
Properies are the most complex element types. Please have a look at the following examples to get a clue on how to use them.
It is recommended to use the first example (via setter method) if there are no usergroups needed.
<?php
use FINDOLOGIC\Export\Exporter;
use FINDOLOGIC\Export\Data\Property;
$exporter = Exporter::create(Exporter::TYPE_XML);
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
// Adding values via setter method
$propertyElement = new Property('propertyname');
$propertyElement->addValue('propertyvalue1');
$propertyElement->addValue('propertyvalue2', 'partner');
$item->addProperty($propertyElement);
// Alternative usage
// The array key of each entry in the array is the usergroup and the assigne value is the property value
$propertValues = [
'' => 'propertyvalue for general usergroup',
'partner' => 'propertyvalue for usergroup partner'
];
$item->addProperty(new Property('propertyname', $propertValues););
The parameters of the exporters serializeItems
-method should depend on the exported items, the start if implemented, the count of the current export step and the total products available in the shop.
If all items are exported at once, the start
should be 0
, the count
and total
parameter should reflect the number of products exported (count of $itemsCollection
).
<?php
use FINDOLOGIC\Export\Exporter;
$exporter = Exporter::create(Exporter::TYPE_XML);
$itemsCollection = [];
$item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
$item->addPrice(44.8);
$itemsCollection[] = $item;
// Output the generated FINDOLOGIC xml e.g. via echo
echo $exporter->serializeItems($itemsCollection, 0, 1, 1);
// Save the generated FINDOLOGIC xml as a file to the current directory
echo $exporter->serializeItemsToFile('.', $itemsCollection, 0, 1, 1);