Passed
Push — master ( 042e6c...085f99 )
by Aimeos
07:08
created

Base::processBatch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
/**
5
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
6
 * @copyright Metaways Infosystems GmbH, 2011
7
 * @copyright Aimeos (aimeos.org), 2015-2022
8
 * @package MShop
9
 * @subpackage Service
10
 */
11
12
13
namespace Aimeos\MShop\Service\Provider\Delivery;
14
15
16
/**
17
 * Abstract class for all delivery provider implementations.
18
 *
19
 * @package MShop
20
 * @subpackage Service
21
 */
22
abstract class Base extends \Aimeos\MShop\Service\Provider\Base implements Iface
23
{
24
	/**
25
	 * Feature constant if querying for status updates for an order is supported.
26
	 */
27
	const FEAT_QUERY = 1;
28
29
30
	/**
31
	 * Returns the price when using the provider.
32
	 *
33
	 * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object
34
	 * @return \Aimeos\MShop\Price\Item\Iface Price item containing the price, shipping, rebate
35
	 */
36
	public function calcPrice( \Aimeos\MShop\Order\Item\Base\Iface $basket ) : \Aimeos\MShop\Price\Item\Iface
37
	{
38
		$costs = 0;
39
		$manager = \Aimeos\MShop::create( $this->context(), 'price' );
40
41
		$prices = $this->getServiceItem()->getRefItems( 'price', 'default', 'default' );
42
		$price = $prices->isEmpty() ? $manager->create() : $manager->getLowestPrice( $prices, 1 );
43
44
		foreach( $basket->getProducts() as $product ) {
45
			$costs = $product->getPrice()->getCosts() * $product->getQuantity();
46
		}
47
48
		return $price->setCosts( $price->getCosts() + $costs );
49
	}
50
51
52
	/**
53
	 * Sends the details of all orders to the ERP system for further processing
54
	 *
55
	 * @param \Aimeos\MShop\Order\Item\Iface[] $orders List of order invoice objects
56
	 * @return \Aimeos\Map Updated order items
57
	 */
58
	public function processBatch( iterable $orders ) : \Aimeos\Map
59
	{
60
		foreach( $orders as $key => $order ) {
61
			$orders[$key] = $this->object()->process( $order );
62
		}
63
64
		return map( $orders );
65
	}
66
67
68
	/**
69
	 * Sets the delivery attributes in the given service.
70
	 *
71
	 * @param \Aimeos\MShop\Order\Item\Base\Service\Iface $orderServiceItem Order service item that will be added to the basket
72
	 * @param array $attributes Attribute key/value pairs entered by the customer during the checkout process
73
	 * @return \Aimeos\MShop\Order\Item\Base\Service\Iface Order service item with attributes added
74
	 */
75
	public function setConfigFE( \Aimeos\MShop\Order\Item\Base\Service\Iface $orderServiceItem,
76
		array $attributes ) : \Aimeos\MShop\Order\Item\Base\Service\Iface
77
	{
78
		return $this->setAttributes( $orderServiceItem, $attributes, 'delivery' );
79
	}
80
}
81