getTSVData()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 33
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 22
nc 5
nop 0
dl 0
loc 33
rs 9.568
c 0
b 0
f 0
1
<?php
2
3
namespace Sunnysideup\EcommerceGoogleShoppingFeed\Api;
4
5
use SilverStripe\ORM\ArrayList;
6
use SilverStripe\View\ArrayData;
7
use Sunnysideup\Ecommerce\Api\ProductCollection;
8
9
class ProductCollectionForGoogleShoppingFeed extends ProductCollection
10
{
11
    public function getArrayList(): ArrayList
12
    {
13
        $arrayList = new ArrayList();
14
15
        $products = parent::getArrayBasic();
16
17
        foreach ($products as $id => $className) {
18
            $productArray = [];
19
20
            if (method_exists($className, 'get_data_for_google_shopping_feed')) {
21
                $productArray = $className::get_data_for_google_shopping_feed($id);
22
            }
23
24
            if (! empty($productArray)) {
25
                $arrayList->push(
26
                    ArrayData::create(
27
                        $productArray
28
                    )
29
                );
30
            }
31
        }
32
33
        return $arrayList;
34
    }
35
36
    public function getTSVData(): array
37
    {
38
        $array = [];
39
        $array[] = [
40
            'id', //1
41
            'title', //2
42
            'description', //3
43
            'google product category', //4
44
            'link', //6
45
            'image link', //7
46
            'condition', //8
47
            'availability', //9
48
            'price', //10
49
            'brand', //11
50
            'mpn', //12
51
            'custom label 1', //13
52
        ];
53
54
        $products = parent::getArrayBasic();
55
56
        foreach ($products as $id => $className) {
57
            $productArray = [];
58
59
            if (method_exists($className, 'get_data_for_google_shopping_feed')) {
60
                $productArray = $className::get_data_for_google_shopping_feed($id);
61
            }
62
63
            if (! empty($productArray)) {
64
                $array[] = $productArray;
65
            }
66
        }
67
68
        return $array;
69
    }
70
71
    public function getArrayFull(): array
72
    {
73
        return [];
74
    }
75
76
}
77