1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, https://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Metaways Infosystems GmbH, 2012 |
6
|
|
|
* @copyright Aimeos (aimeos.org), 2015-2022 |
7
|
|
|
* @package MShop |
8
|
|
|
* @subpackage Price |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
namespace Aimeos\MShop\Price\Manager; |
13
|
|
|
|
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Abstract class for all price managers with basic methods. |
17
|
|
|
* |
18
|
|
|
* @package MShop |
19
|
|
|
* @subpackage Price |
20
|
|
|
*/ |
21
|
|
|
abstract class Base |
22
|
|
|
extends \Aimeos\MShop\Common\Manager\Base |
23
|
|
|
{ |
24
|
|
|
use \Aimeos\MShop\Common\Manager\ListsRef\Traits; |
25
|
|
|
use \Aimeos\MShop\Common\Manager\PropertyRef\Traits; |
26
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Returns the price item with the lowest price for the given quantity. |
30
|
|
|
* |
31
|
|
|
* @param \Aimeos\Map $priceItems List of price items implementing \Aimeos\MShop\Price\Item\Iface |
32
|
|
|
* @param float $quantity Number of products |
33
|
|
|
* @param string|null $currencyId Three letter ISO currency code or null for all |
34
|
|
|
* @return \Aimeos\MShop\Price\Item\Iface Price item with the lowest price |
35
|
|
|
* @throws \Aimeos\MShop\Price\Exception if no price item is available |
36
|
|
|
*/ |
37
|
|
|
public function getLowestPrice( \Aimeos\Map $priceItems, float $quantity, string $currencyId = null ) : \Aimeos\MShop\Price\Item\Iface |
38
|
|
|
{ |
39
|
|
|
$priceList = $this->getPriceList( $priceItems, $currencyId ); |
40
|
|
|
|
41
|
|
|
if( ( $price = $priceList->first() ) === null ) |
42
|
|
|
{ |
43
|
|
|
$msg = $this->context()->translate( 'mshop', 'Price item not available' ); |
44
|
|
|
throw new \Aimeos\MShop\Price\Exception( $msg ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
if( $price->getQuantity() > $quantity ) |
48
|
|
|
{ |
49
|
|
|
$msg = $this->context()->translate( 'mshop', 'Price for the given quantity "%1$s" not available' ); |
50
|
|
|
throw new \Aimeos\MShop\Price\Exception( sprintf( $msg, $quantity ) ); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
return $this->call( 'calcLowestPrice', $priceList, $quantity ); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Returns the lowest price for the given quantity |
59
|
|
|
* |
60
|
|
|
* @param \Aimeos\Map Associative list of quantity as keys and price item as value |
|
|
|
|
61
|
|
|
* @param float $quantity Number of products |
62
|
|
|
* @return \Aimeos\MShop\Price\Item\Iface Price item with the lowest price |
63
|
|
|
*/ |
64
|
|
|
protected function calcLowestPrice( \Aimeos\Map $priceList, float $quantity ) : \Aimeos\MShop\Price\Item\Iface |
65
|
|
|
{ |
66
|
|
|
$price = $priceList->first(); |
67
|
|
|
|
68
|
|
|
foreach( $priceList as $qty => $priceItem ) |
69
|
|
|
{ |
70
|
|
|
// add $priceItem->getValue() < $price->getValue() to use lowest price regardless of quantity |
71
|
|
|
if( $quantity >= $qty && $price->getQuantity() < $qty ) { |
72
|
|
|
$price = $priceItem; |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
return $price; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Returns the price items sorted by quantity |
82
|
|
|
* |
83
|
|
|
* @param \Aimeos\Map $priceItems List of price items implementing \Aimeos\MShop\Price\Item\Iface |
84
|
|
|
* @param string|null $currencyId Three letter ISO currency code or null for all |
85
|
|
|
* @return \Aimeos\Map Associative list of quantity as keys and price item as value |
86
|
|
|
* @throws \Aimeos\MShop\Price\Exception If an object is no price item |
87
|
|
|
*/ |
88
|
|
|
protected function getPriceList( \Aimeos\Map $priceItems, ?string $currencyId ) : \Aimeos\Map |
89
|
|
|
{ |
90
|
|
|
$list = map(); |
91
|
|
|
$priceItems->implements( \Aimeos\MShop\Price\Item\Iface::class, true ); |
92
|
|
|
|
93
|
|
|
foreach( $priceItems as $priceItem ) |
94
|
|
|
{ |
95
|
|
|
if( $currencyId !== null && $currencyId !== $priceItem->getCurrencyId() ) { |
96
|
|
|
continue; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
$qty = (string) $priceItem->getQuantity(); |
100
|
|
|
|
101
|
|
|
if( !isset( $list[$qty] ) || $list[$qty]->getValue() > $priceItem->getValue() ) { |
|
|
|
|
102
|
|
|
$list[$qty] = $priceItem; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $list->ksort(); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths