5
5
*/
6
6
namespace Magento \Bundle \Helper \Catalog \Product ;
7
7
8
+ use Magento \Catalog \Api \Data \ProductInterface ;
8
9
use Magento \Catalog \Helper \Product \Configuration \ConfigurationInterface ;
9
10
use Magento \Catalog \Model \Product \Configuration \Item \ItemInterface ;
10
11
use Magento \Framework \App \Helper \AbstractHelper ;
@@ -130,7 +131,6 @@ public function getSelectionFinalPrice(ItemInterface $item, \Magento\Catalog\Mod
130
131
*
131
132
* @param ItemInterface $item
132
133
* @return array
133
- * phpcs:disable Generic.Metrics.NestingLevel
134
134
*/
135
135
public function getBundleOptions (ItemInterface $ item )
136
136
{
@@ -166,29 +166,7 @@ public function getBundleOptions(ItemInterface $item)
166
166
$ bundleSelections = $ bundleOption ->getSelections ();
167
167
168
168
foreach ($ bundleSelections as $ bundleSelection ) {
169
- $ qty = $ this ->getSelectionQty ($ product , $ bundleSelection ->getSelectionId ()) * 1 ;
170
- if ($ qty ) {
171
- $ selectionPrice = $ this ->getSelectionFinalPrice ($ item , $ bundleSelection );
172
- $ selectionFinalPrice = $ this ->catalogHelper ->getTaxPrice ($ item , $ selectionPrice );
173
-
174
- $ displayBothPrices = $ this ->taxHelper ->displayBothPrices ();
175
- if ($ displayBothPrices ) {
176
- $ selectionFinalPrice = $ this ->catalogHelper ->getTaxPrice ($ item , $ selectionPrice , true );
177
- $ selectionFinalPriceExclTax = $ this ->catalogHelper ->getTaxPrice ($ item , $ selectionPrice , false );
178
- }
179
- $ option ['value ' ][] = $ qty . ' x '
180
- . $ this ->escaper ->escapeHtml ($ bundleSelection ->getName ())
181
- . ' '
182
- . $ this ->pricingHelper ->currency (
183
- $ selectionFinalPrice
184
- )
185
- . ' '
186
- . ($ displayBothPrices ? __ ('Excl. tax: ' ) . ' '
187
- . $ this ->pricingHelper ->currency (
188
- $ selectionFinalPriceExclTax
189
- ) : '' );
190
- $ option ['has_html ' ] = true ;
191
- }
169
+ $ option = $ this ->getOptionPriceHtml ($ item , $ bundleSelection , $ option );
192
170
}
193
171
194
172
if ($ option ['value ' ]) {
@@ -201,7 +179,47 @@ public function getBundleOptions(ItemInterface $item)
201
179
202
180
return $ options ;
203
181
}
204
- //phpcs:enable Generic.Metrics.NestingLevel
182
+
183
+ /**
184
+ * Get bundle options' prices
185
+ *
186
+ * @param ItemInterface $item
187
+ * @param ProductInterface $bundleSelection
188
+ * @param array $option
189
+ * @return array
190
+ */
191
+ private function getOptionPriceHtml (ItemInterface $ item , ProductInterface $ bundleSelection , array $ option ): array
192
+ {
193
+ $ product = $ item ->getProduct ();
194
+ $ qty = $ this ->getSelectionQty ($ item ->getProduct (), $ bundleSelection ->getSelectionId ()) * 1 ;
195
+ if ($ qty ) {
196
+ $ selectionPrice = $ this ->getSelectionFinalPrice ($ item , $ bundleSelection );
197
+ $ selectionFinalPrice = $ this ->catalogHelper ->getTaxPrice ($ item ->getProduct (), $ selectionPrice );
198
+
199
+ $ displayBothPrices = $ this ->taxHelper ->displayBothPrices ();
200
+ if ($ displayBothPrices ) {
201
+ $ selectionFinalPrice =
202
+ $ this ->catalogHelper
203
+ ->getTaxPrice ($ product , $ selectionPrice , true );
204
+ $ selectionFinalPriceExclTax =
205
+ $ this ->catalogHelper
206
+ ->getTaxPrice ($ product , $ selectionPrice , false );
207
+ }
208
+ $ option ['value ' ][] = $ qty . ' x '
209
+ . $ this ->escaper ->escapeHtml ($ bundleSelection ->getName ())
210
+ . ' '
211
+ . $ this ->pricingHelper ->currency (
212
+ $ selectionFinalPrice
213
+ )
214
+ . ' '
215
+ . ($ displayBothPrices ? __ ('Excl. tax: ' ) . ' '
216
+ . $ this ->pricingHelper ->currency (
217
+ $ selectionFinalPriceExclTax
218
+ ) : '' );
219
+ $ option ['has_html ' ] = true ;
220
+ }
221
+ return $ option ;
222
+ }
205
223
206
224
/**
207
225
* Retrieves product options list
0 commit comments