Passed
Push — master ( 22ec29...d89274 )
by Aimeos
05:05
created

Nocosts   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A calcPrice() 0 10 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2020
6
 * @package MShop
7
 * @subpackage Service
8
 */
9
10
11
namespace Aimeos\MShop\Service\Provider\Decorator;
12
13
14
/**
15
 * Decorator for service providers setting costs to zero.
16
 *
17
 * @package MShop
18
 * @subpackage Service
19
 */
20
class Nocosts
21
	extends \Aimeos\MShop\Service\Provider\Decorator\Base
22
	implements \Aimeos\MShop\Service\Provider\Decorator\Iface
23
{
24
	/**
25
	 * Returns the costs per item as negative value to get no costs at all.
26
	 *
27
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
28
	 * @return \Aimeos\MShop\Price\Item\Iface Price item containing the price, shipping, rebate
29
	 */
30
	public function calcPrice( \Aimeos\MShop\Order\Item\Base\Iface $basket ) : \Aimeos\MShop\Price\Item\Iface
31
	{
32
		$costs = 0;
33
		$price = $this->getProvider()->calcPrice( $basket );
34
35
		foreach( $basket->getProducts() as $product ) {
36
			$costs += $product->getPrice()->getCosts() * $product->getQuantity();
37
		}
38
39
		return $price->setCosts( -$costs );
40
	}
41
}
42