Completed
Push — master ( 6f4209...a56798 )
by Aimeos
03:04
created

Standard::process()   C

Complexity

Conditions 7
Paths 13

Size

Total Lines 36
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 19
nc 13
nop 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017
6
 * @package Controller
7
 * @subpackage Common
8
 */
9
10
11
namespace Aimeos\Controller\Common\Order\Export\Csv\Processor\Product;
12
13
14
/**
15
 * Product processor for order CSV exports
16
 *
17
 * @package Controller
18
 * @subpackage Common
19
 */
20
class Standard
21
	extends \Aimeos\Controller\Common\Order\Export\Csv\Processor\Base
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
Expected 0 spaces between "Base" and comma; 1 found
Loading history...
22
	implements \Aimeos\Controller\Common\Order\Export\Csv\Processor\Iface
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
23
{
24
	/** controller/common/order/export/csv/processor/product/name
25
	 * Name of the product processor implementation
26
	 *
27
	 * Use "Myname" if your class is named "\Aimeos\Controller\Common\Order\Export\Csv\Processor\Product\Myname".
28
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
29
	 *
30
	 * @param string Last part of the processor class name
31
	 * @since 2017.08
32
	 * @category Developer
33
	 */
34
35
36
	/**
37
	 * Returns the order related data
38
	 *
39
	 * @param \Aimeos\MShop\Order\Item\Iface $invoice Invoice item
40
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $order Full order with associated items
41
	 * @return array Two dimensional associative list of order data representing the lines in CSV
42
	 */
43
	public function process( \Aimeos\MShop\Order\Item\Iface $invoice, \Aimeos\MShop\Order\Item\Base\Iface $order )
44
	{
45
		$result = [];
46
47
		foreach( $order->getProducts() as $item )
48
		{
49
			$data = [];
50
			$list = $item->toArray();
51
52
			foreach( $item->getAttributes() as $attrItem )
53
			{
54
				foreach( $attrItem->toArray() as $key => $value )
55
				{
56
					if( isset( $list[$key] ) ) {
57
						$list[$key] .= "\n" . $value;
58
					} else {
59
						$list[$key] = $value;
60
					}
61
				}
62
			}
63
64
			foreach( $this->getMapping() as $pos => $key )
65
			{
66
				if( array_key_exists( $key, $list ) ) {
67
					$data[$pos] = $list[$key];
68
				} else {
69
					$data[$pos] = '';
70
				}
71
			}
72
73
			ksort( $data );
74
			$result[] = $data;
75
		}
76
77
		return $result;
78
	}
79
}
80