1<?php
2
3namespace FINDOLOGIC\Export\CSV;
4
5use FINDOLOGIC\Export\Exporter;
6
7class CSVExporter extends Exporter
8{
9    const HEADING = "id\tordernumber\tname\tsummary\tdescription\tprice\tinstead\tmaxprice\ttaxrate\turl\timage\t" .
10        "attributes\tkeywords\tgroups\tbonus\tsales_frequency\tdate_added\tsort\n";
11
12    /**
13     * @inheritdoc
14     */
15    public function serializeItems($items, $start = 0, $count = 0, $total = 0)
16    {
17        $export = self::HEADING;
18
19        /** @var CSVItem $item */
20        foreach ($items as $item) {
21            $export .= $item->getCsvFragment();
22        }
23
24        return $export;
25    }
26
27    /**
28     * @inheritdoc
29     */
30    public function serializeItemsToFile($targetDirectory, $items, $start = 0, $count = 0, $total = 0)
31    {
32        $csvString = $this->serializeItems($items, $start, $count, $total);
33        $targetPath = sprintf('%s/findologic.csv', $targetDirectory);
34
35        file_put_contents($targetPath, $csvString);
36
37        return $targetPath;
38    }
39
40    /**
41     * @inheritdoc
42     */
43    public function createItem($id)
44    {
45        return new CSVItem($id);
46    }
47}
48