@@ -21,6 +21,11 @@ class DefaultSelectionPriceListProvider implements SelectionPriceListProviderInt
21
21
*/
22
22
private $ selectionFactory ;
23
23
24
+ /**
25
+ * @var \Magento\Bundle\Pricing\Price\BundleSelectionPrice[]
26
+ */
27
+ private $ priceList ;
28
+
24
29
/**
25
30
* @param BundleSelectionFactory $bundleSelectionFactory
26
31
*/
@@ -39,7 +44,7 @@ public function getPriceList(Product $bundleProduct, $searchMin, $useRegularPric
39
44
40
45
/** @var \Magento\Bundle\Model\Product\Type $typeInstance */
41
46
$ typeInstance = $ bundleProduct ->getTypeInstance ();
42
- $ priceList = [];
47
+ $ this -> priceList = [];
43
48
44
49
foreach ($ this ->getBundleOptions ($ bundleProduct ) as $ option ) {
45
50
/** @var Option $option */
@@ -54,24 +59,25 @@ public function getPriceList(Product $bundleProduct, $searchMin, $useRegularPric
54
59
$ selectionsCollection ->removeAttributeToSelect ();
55
60
$ selectionsCollection ->addQuantityFilter ();
56
61
62
+ if (!$ useRegularPrice ) {
63
+ $ selectionsCollection ->addAttributeToSelect ('special_price ' );
64
+ $ selectionsCollection ->addAttributeToSelect ('special_price_from ' );
65
+ $ selectionsCollection ->addAttributeToSelect ('special_price_to ' );
66
+ $ selectionsCollection ->addAttributeToSelect ('tax_class_id ' );
67
+ }
68
+
57
69
if (!$ searchMin && $ option ->isMultiSelection ()) {
58
- $ priceList = array_merge (
59
- $ priceList ,
60
- $ this ->getMaximumMultiselectionPriceList ($ bundleProduct , $ selectionsCollection , $ useRegularPrice )
61
- );
70
+ $ this ->addMaximumMultiSelectionPriceList ($ bundleProduct , $ selectionsCollection , $ useRegularPrice );
62
71
} else {
63
- $ priceList = array_merge (
64
- $ priceList ,
65
- $ this ->getMiniMaxPriceList ($ bundleProduct , $ selectionsCollection , $ searchMin , $ useRegularPrice )
66
- );
72
+ $ this ->addMiniMaxPriceList ($ bundleProduct , $ selectionsCollection , $ searchMin , $ useRegularPrice );
67
73
}
68
74
}
69
75
70
76
if ($ shouldFindMinOption ) {
71
- $ priceList = $ this ->getMinPriceForNonRequiredOptions ( $ priceList );
77
+ $ this ->processMinPriceForNonRequiredOptions ( );
72
78
}
73
79
74
- return $ priceList ;
80
+ return $ this -> priceList ;
75
81
}
76
82
77
83
/**
@@ -95,31 +101,23 @@ private function isShouldFindMinOption(Product $bundleProduct, $searchMin)
95
101
}
96
102
97
103
/**
98
- * Get minimum or maximum price for option
104
+ * Add minimum or maximum price for option
99
105
*
100
106
* @param Product $bundleProduct
101
107
* @param \Magento\Bundle\Model\ResourceModel\Selection\Collection $selectionsCollection
102
108
* @param bool $searchMin
103
109
* @param bool $useRegularPrice
104
- * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[]
110
+ * @return void
105
111
*/
106
- private function getMiniMaxPriceList (Product $ bundleProduct , $ selectionsCollection , $ searchMin , $ useRegularPrice )
112
+ private function addMiniMaxPriceList (Product $ bundleProduct , $ selectionsCollection , $ searchMin , $ useRegularPrice )
107
113
{
108
- $ priceList = [];
109
-
110
114
$ selectionsCollection ->addPriceFilter ($ bundleProduct , $ searchMin , $ useRegularPrice );
111
115
$ selectionsCollection ->setPage (0 , 1 );
112
- if (!$ useRegularPrice ) {
113
- $ selectionsCollection ->addAttributeToSelect ('special_price ' );
114
- $ selectionsCollection ->addAttributeToSelect ('special_price_from ' );
115
- $ selectionsCollection ->addAttributeToSelect ('special_price_to ' );
116
- $ selectionsCollection ->addAttributeToSelect ('tax_class_id ' );
117
- }
118
116
119
117
$ selection = $ selectionsCollection ->getFirstItem ();
120
118
121
119
if (!$ selection ->isEmpty ()) {
122
- $ priceList [] = $ this ->selectionFactory ->create (
120
+ $ this -> priceList [] = $ this ->selectionFactory ->create (
123
121
$ bundleProduct ,
124
122
$ selection ,
125
123
$ selection ->getSelectionQty (),
@@ -128,25 +126,22 @@ private function getMiniMaxPriceList(Product $bundleProduct, $selectionsCollecti
128
126
]
129
127
);
130
128
}
131
-
132
- return $ priceList ;
133
129
}
134
130
135
131
/**
136
- * Get maximum price for multiselection option
132
+ * Add maximum price for multi selection option
137
133
*
138
134
* @param Product $bundleProduct
139
135
* @param \Magento\Bundle\Model\ResourceModel\Selection\Collection $selectionsCollection
140
136
* @param bool $useRegularPrice
141
- * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[]
137
+ * @return void
142
138
*/
143
- private function getMaximumMultiselectionPriceList (Product $ bundleProduct , $ selectionsCollection , $ useRegularPrice )
139
+ private function addMaximumMultiSelectionPriceList (Product $ bundleProduct , $ selectionsCollection , $ useRegularPrice )
144
140
{
145
- $ priceList = [];
146
-
147
141
$ selectionsCollection ->addPriceData ();
142
+
148
143
foreach ($ selectionsCollection as $ selection ) {
149
- $ priceList [] = $ this ->selectionFactory ->create (
144
+ $ this -> priceList [] = $ this ->selectionFactory ->create (
150
145
$ bundleProduct ,
151
146
$ selection ,
152
147
$ selection ->getSelectionQty (),
@@ -155,28 +150,23 @@ private function getMaximumMultiselectionPriceList(Product $bundleProduct, $sele
155
150
]
156
151
);
157
152
}
158
-
159
- return $ priceList ;
160
153
}
161
154
162
155
/**
163
- * @param \Magento\Bundle\Pricing\Price\BundleSelectionPrice[] $priceList
164
- * @return \Magento\Bundle\Pricing\Price\BundleSelectionPrice[]
156
+ * @return void
165
157
*/
166
- private function getMinPriceForNonRequiredOptions ( $ priceList )
158
+ private function processMinPriceForNonRequiredOptions ( )
167
159
{
168
160
$ minPrice = null ;
169
161
$ priceSelection = null ;
170
- foreach ($ priceList as $ price ) {
162
+ foreach ($ this -> priceList as $ price ) {
171
163
$ minPriceTmp = $ price ->getAmount ()->getValue () * $ price ->getQuantity ();
172
164
if (!$ minPrice || $ minPriceTmp < $ minPrice ) {
173
165
$ minPrice = $ minPriceTmp ;
174
166
$ priceSelection = $ price ;
175
167
}
176
168
}
177
- $ priceList = $ priceSelection ? [$ priceSelection ] : [];
178
-
179
- return $ priceList ;
169
+ $ this ->priceList = $ priceSelection ? [$ priceSelection ] : [];
180
170
}
181
171
182
172
/**
0 commit comments