1<?php
2
3require_once __DIR__ . '/../vendor/autoload.php';
4
5use FINDOLOGIC\Export\Data\Item;
6use FINDOLOGIC\Export\Exporter;
7use FINDOLOGIC\Export\Data\Ordernumber;
8use FINDOLOGIC\Export\Data\Image;
9use FINDOLOGIC\Export\Data\Attribute;
10use FINDOLOGIC\Export\Data\Keyword;
11use FINDOLOGIC\Export\Data\Usergroup;
12use FINDOLOGIC\Export\Data\Property;
13
14/**
15 * This example class builds a xml export based on the example of the FINDOLOGIC documentation, which can be found
16 * under the following link https://docs.findologic.com/doku.php?id=export_patterns:xml#example_xml
17 */
18class XmlExample
19{
20    public function createExport()
21    {
22        $exporter = Exporter::create(Exporter::TYPE_XML);
23
24        $itemsToExport = [];
25
26        // Here you could have an array with the item data to iterate threw
27        $itemsData = ['item1'];
28
29        foreach ($itemsData as $itemData) {
30            $item = $exporter->createItem('01120c948ad41a2284ad9f0402fbc7d');
31
32            $this->addOrdernumbers($item, $itemData);
33            $this->addNames($item, $itemData);
34            $this->addSummaries($item, $itemData);
35            $this->addDescriptions($item, $itemData);
36            $this->addPrices($item, $itemData);
37            $this->addUrls($item, $itemData);
38            $this->addKeywords($item, $itemData);
39            $this->addBonuses($item, $itemData);
40            $this->addSalesFrequencies($item, $itemData);
41            $this->addDateAddeds($item, $itemData);
42            $this->addSorts($item, $itemData);
43            $this->addUsergroups($item, $itemData);
44            $this->addImages($item, $itemData);
45            $this->addAttributes($item, $itemData);
46            $this->addProperties($item, $itemData);
47
48            $itemsToExport[] = $item;
49        }
50
51        return $exporter->serializeItems($itemsToExport, 0, 1, 1);
52    }
53
54    private function addAttributes(Item $item, $itemData)
55    {
56        $attributesData = [
57            'cat' => [
58                'Sneakers_Men',
59                'Specials_Sale'
60            ],
61            'cat_url' => [
62                '/sneakers',
63                '/sneakers/men',
64                '/specials',
65                '/specials/sale'
66            ],
67            'brand' => [
68                'Adidas'
69            ],
70            'color' => [
71                'green',
72                'blue'
73            ]
74        ];
75
76        foreach ($attributesData as $attributeName => $attributeValues) {
77            $item->addAttribute(new Attribute($attributeName, $attributeValues));
78        }
79    }
80
81    private function addBonuses(Item $item, $itemData)
82    {
83        $item->addBonus(3);
84        $item->addBonus(5, 'LNrLF7BRVJ0toQ==');
85    }
86
87    private function addDateAddeds(Item $item, $itemData)
88    {
89        $item->addDateAdded(new \DateTime());
90        $item->addDateAdded(new \DateTime(), 'LNrLF7BRVJ0toQ==');
91    }
92
93    private function addDescriptions(Item $item, $itemData)
94    {
95        $item->addDescription('With this sneaker you will walk in style. It\'s available in green and blue.');
96        $item->addDescription(
97            'With this men\'s sneaker you will walk in style. It\'s comes in various sizes and colors.',
98            'LNrLF7BRVJ0toQ=='
99        );
100    }
101
102    private function addOrdernumbers(Item $item, $itemData)
103    {
104        $ordernumbersData = [
105            '' => [
106                '277KTL',
107                '4987123846879'
108            ],
109            'LNrLF7BRVJ0toQ==' => [
110                '377KTL'
111            ]
112        ];
113
114        foreach ($ordernumbersData as $usergroup => $ordernumbers) {
115            foreach ($ordernumbers as $ordernumber) {
116                $item->addOrdernumber(new Ordernumber($ordernumber, $usergroup));
117            }
118        }
119    }
120
121    private function addImages(Item $item, $itemData)
122    {
123        $imagesData = [
124            '' => [
125                'https://www.store.com/images/277KTL.png' => Image::TYPE_DEFAULT,
126                'https://www.store.com/images/thumbnails/277KTL.png' => Image::TYPE_THUMBNAIL
127            ],
128            'LNrLF7BRVJ0toQ==' => [
129                'https://www.store.com/images/277KTLmen.png' => Image::TYPE_DEFAULT,
130                'https://www.store.com/images/thumbnails/277KTLmen.png' => Image::TYPE_THUMBNAIL
131            ]
132        ];
133
134        foreach ($imagesData as $usergroup => $images) {
135            foreach ($images as $image => $type) {
136                $item->addImage(new Image($image, $type, $usergroup));
137            }
138        }
139    }
140
141    private function addKeywords(Item $item, $itemData)
142    {
143        $keywordsData = [
144            '' => [
145                '277KTL',
146                '4987123846879'
147            ],
148            'LNrLF7BRVJ0toQ==' => [
149                '377KTL'
150            ]
151        ];
152
153        foreach ($keywordsData as $usergroup => $keywords) {
154            foreach ($keywords as $keyword) {
155                $item->addKeyword(new Keyword($keyword, $usergroup));
156            }
157        }
158    }
159
160    private function addNames(Item $item, $itemData)
161    {
162        $item->addName('Adidas Sneaker');
163        $item->addName('Adidas Men\'s Sneaker', 'LNrLF7BRVJ0toQ==');
164    }
165
166    private function addPrices(Item $item, $itemData)
167    {
168        $item->addPrice(44.8);
169        $item->addPrice(45.9, 'LNrLF7BRVJ0toQ==');
170    }
171
172    private function addProperties(Item $item, $itemData)
173    {
174        $propertiesData = [
175            'sale' => [
176                '' => 1,
177                'LNrLF7BRVJ0toQ==' => 0
178            ],
179            'novelty' => [
180                '' => 0,
181                'LNrLF7BRVJ0toQ==' => 0
182            ],
183            'logo' => [
184                '' => 'http://www.shop.de/brand.png',
185                'LNrLF7BRVJ0toQ==' => 'http://www.shop.de/brand.png'
186            ],
187            'availability' => [
188                '' => '<span style="color: green;">4 days</span>',
189                'LNrLF7BRVJ0toQ==' => '<span style="color: green;">3 days</span>'
190            ],
191            'old_price' => [
192                '' => 99.9,
193                'LNrLF7BRVJ0toQ==' => 99.9
194            ],
195            'Basic_rate_price' => [
196                '' => 99.9,
197                'LNrLF7BRVJ0toQ==' => 89.9
198            ]
199        ];
200
201        foreach ($propertiesData as $propertyName => $values) {
202            $propertyElement = new Property($propertyName, $values);
203            $item->addProperty($propertyElement);
204        }
205    }
206
207    private function addSalesFrequencies(Item $item, $itemData)
208    {
209        $item->addSalesFrequency(5);
210        $item->addSalesFrequency(10, 'LNrLF7BRVJ0toQ==');
211    }
212
213    private function addSorts(Item $item, $itemData)
214    {
215        $item->addSort(5);
216        $item->addSort(7, 'LNrLF7BRVJ0toQ==');
217    }
218
219    private function addSummaries(Item $item, $itemData)
220    {
221        $item->addSummary('A cool and fashionable sneaker');
222        $item->addSummary('A cool and fashionable sneaker for men', 'LNrLF7BRVJ0toQ==');
223    }
224
225    private function addUrls(Item $item, $itemData)
226    {
227        $item->addUrl('https://www.store.com/sneakers/adidas.html');
228        $item->addUrl('https://www.store.com/sneakers/mens/adidas.html', 'LNrLF7BRVJ0toQ==');
229    }
230
231    private function addUsergroups(Item $item, $itemData)
232    {
233        $usergroups = [
234            'LNrLF7BRVJ0toQ==',
235            'cHBw'
236        ];
237
238        foreach ($usergroups as $usergroup) {
239            $item->addUsergroup(new Usergroup($usergroup));
240        }
241    }
242}
243
244$example = new XmlExample();
245
246// Echo the xml content
247echo $example->createExport();
248