GoogleExtendedConverter::setNormalizer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of gpupo/pipe2
5
 *
6
 * (c) Gilmar Pupo <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * For more information, see
12
 * <https://opensource.gpupo.com/pipe2/>.
13
 */
14
15
namespace Gpupo\Pipe2\Converter;
16
17
use Gpupo\CommonSchema\Sphinx\GoogleExtendedSchema;
18
use Gpupo\Pipe2\Normalizer\GoogleExtendedNormalizer;
19
20
class GoogleExtendedConverter extends GoogleConverter
21
{
22
    public function setSchema()
23
    {
24
        $this->schema = new GoogleExtendedSchema();
25
    }
26
27
    public function setNormalizer()
28
    {
29
        $this->normalizer = new GoogleExtendedNormalizer();
30
    }
31
32
    protected function extended($item)
33
    {
34
        if (array_key_exists('sale_price', $item) && !empty($item['sale_price'])) {
35
            $item['sale_price_discount'] = $item['price'] - $item['sale_price'];
36
            $item['sale_price_percentage'] = ($item['price'] - $item['sale_price']) / $item['price'] * 100;
37
        }
38
39
        $parts = [];
40
41
        foreach (['title', 'color', 'size', 'id', 'brand', 'channel', 'category', 'sku'] as $key) {
42
            if (array_key_exists($key, $item)) {
43
                $parts[] = $item[$key];
44
            }
45
        }
46
47
        $item['document_slug'] = $this->getNormalizer()->slugify(implode('-', $parts));
48
49
        return $item;
50
    }
51
}
52