Skip to content

Commit 0727043

Browse files
authored
Merge pull request #8154 from magento-l3/PR-02142023
Pr 02142023
2 parents 4a66488 + ab58edf commit 0727043

File tree

24 files changed

+701
-97
lines changed

24 files changed

+701
-97
lines changed

app/code/Magento/Bundle/Helper/Catalog/Product/Configuration.php

Lines changed: 85 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,21 @@
55
*/
66
namespace Magento\Bundle\Helper\Catalog\Product;
77

8+
use Magento\Bundle\Model\Product\Price;
9+
use Magento\Bundle\Model\Product\Type;
10+
use Magento\Bundle\Pricing\Price\TaxPrice;
11+
use Magento\Catalog\Api\Data\ProductInterface;
12+
use Magento\Catalog\Helper\Product\Configuration as ProductConfiguration;
813
use Magento\Catalog\Helper\Product\Configuration\ConfigurationInterface;
14+
use Magento\Catalog\Model\Product;
915
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
1016
use Magento\Framework\App\Helper\AbstractHelper;
17+
use Magento\Framework\App\Helper\Context;
18+
use Magento\Framework\App\ObjectManager;
19+
use Magento\Framework\Escaper;
20+
use Magento\Framework\Exception\LocalizedException;
21+
use Magento\Framework\Pricing\Helper\Data;
22+
use Magento\Framework\Serialize\Serializer\Json;
1123

1224
/**
1325
* Helper for fetching properties by product configuration item
@@ -19,61 +31,67 @@ class Configuration extends AbstractHelper implements ConfigurationInterface
1931
/**
2032
* Core data
2133
*
22-
* @var \Magento\Framework\Pricing\Helper\Data
34+
* @var Data
2335
*/
2436
protected $pricingHelper;
2537

2638
/**
2739
* Catalog product configuration
2840
*
29-
* @var \Magento\Catalog\Helper\Product\Configuration
41+
* @var ProductConfiguration
3042
*/
3143
protected $productConfiguration;
3244

3345
/**
34-
* Escaper
35-
*
36-
* @var \Magento\Framework\Escaper
46+
* @var Escaper
3747
*/
3848
protected $escaper;
3949

4050
/**
4151
* Serializer interface instance.
4252
*
43-
* @var \Magento\Framework\Serialize\Serializer\Json
53+
* @var Json
4454
*/
4555
private $serializer;
4656

4757
/**
48-
* @param \Magento\Framework\App\Helper\Context $context
49-
* @param \Magento\Catalog\Helper\Product\Configuration $productConfiguration
50-
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
51-
* @param \Magento\Framework\Escaper $escaper
52-
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
58+
* @var TaxPrice
59+
*/
60+
private $taxHelper;
61+
62+
/**
63+
* @param Context $context
64+
* @param ProductConfiguration $productConfiguration
65+
* @param Data $pricingHelper
66+
* @param Escaper $escaper
67+
* @param Json|null $serializer
68+
* @param TaxPrice|null $taxHelper
5369
*/
5470
public function __construct(
55-
\Magento\Framework\App\Helper\Context $context,
56-
\Magento\Catalog\Helper\Product\Configuration $productConfiguration,
57-
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
58-
\Magento\Framework\Escaper $escaper,
59-
\Magento\Framework\Serialize\Serializer\Json $serializer = null
71+
Context $context,
72+
ProductConfiguration $productConfiguration,
73+
Data $pricingHelper,
74+
Escaper $escaper,
75+
Json $serializer = null,
76+
TaxPrice $taxHelper = null
6077
) {
6178
$this->productConfiguration = $productConfiguration;
6279
$this->pricingHelper = $pricingHelper;
6380
$this->escaper = $escaper;
64-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
65-
->get(\Magento\Framework\Serialize\Serializer\Json::class);
81+
$this->serializer = $serializer ?: ObjectManager::getInstance()
82+
->get(Json::class);
83+
$this->taxHelper = $taxHelper ?? ObjectManager::getInstance()->get(TaxPrice::class);
6684
parent::__construct($context);
6785
}
6886

6987
/**
7088
* Get selection quantity
7189
*
72-
* @param \Magento\Catalog\Model\Product $product
90+
* @param Product $product
7391
* @param int $selectionId
7492
* @return float
7593
*/
76-
public function getSelectionQty(\Magento\Catalog\Model\Product $product, $selectionId)
94+
public function getSelectionQty(Product $product, $selectionId)
7795
{
7896
$selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
7997
if ($selectionQty) {
@@ -86,15 +104,15 @@ public function getSelectionQty(\Magento\Catalog\Model\Product $product, $select
86104
* Obtain final price of selection in a bundle product
87105
*
88106
* @param ItemInterface $item
89-
* @param \Magento\Catalog\Model\Product $selectionProduct
107+
* @param Product $selectionProduct
90108
* @return float
91109
*/
92-
public function getSelectionFinalPrice(ItemInterface $item, \Magento\Catalog\Model\Product $selectionProduct)
110+
public function getSelectionFinalPrice(ItemInterface $item, Product $selectionProduct)
93111
{
94112
$selectionProduct->unsetData('final_price');
95113

96114
$product = $item->getProduct();
97-
/** @var \Magento\Bundle\Model\Product\Price $price */
115+
/** @var Price $price */
98116
$price = $product->getPriceModel();
99117

100118
return $price->getSelectionFinalTotalPrice(
@@ -121,7 +139,7 @@ public function getBundleOptions(ItemInterface $item)
121139
$options = [];
122140
$product = $item->getProduct();
123141

124-
/** @var \Magento\Bundle\Model\Product\Type $typeInstance */
142+
/** @var Type $typeInstance */
125143
$typeInstance = $product->getTypeInstance();
126144

127145
// get bundle options
@@ -150,16 +168,7 @@ public function getBundleOptions(ItemInterface $item)
150168
$bundleSelections = $bundleOption->getSelections();
151169

152170
foreach ($bundleSelections as $bundleSelection) {
153-
$qty = $this->getSelectionQty($product, $bundleSelection->getSelectionId()) * 1;
154-
if ($qty) {
155-
$option['value'][] = $qty . ' x '
156-
. $this->escaper->escapeHtml($bundleSelection->getName())
157-
. ' '
158-
. $this->pricingHelper->currency(
159-
$this->getSelectionFinalPrice($item, $bundleSelection)
160-
);
161-
$option['has_html'] = true;
162-
}
171+
$option = $this->getOptionPriceHtml($item, $bundleSelection, $option);
163172
}
164173

165174
if ($option['value']) {
@@ -173,6 +182,48 @@ public function getBundleOptions(ItemInterface $item)
173182
return $options;
174183
}
175184

185+
/**
186+
* Get bundle options' prices
187+
*
188+
* @param ItemInterface $item
189+
* @param ProductInterface $bundleSelection
190+
* @param array $option
191+
* @return array
192+
* @throws LocalizedException
193+
*/
194+
private function getOptionPriceHtml(ItemInterface $item, ProductInterface $bundleSelection, array $option): array
195+
{
196+
$product = $item->getProduct();
197+
$qty = $this->getSelectionQty($item->getProduct(), $bundleSelection->getSelectionId()) * 1;
198+
if ($qty) {
199+
$selectionPrice = $this->getSelectionFinalPrice($item, $bundleSelection);
200+
201+
$displayCartPricesBoth = $this->taxHelper->displayCartPricesBoth();
202+
if ($displayCartPricesBoth) {
203+
$selectionFinalPrice =
204+
$this->taxHelper
205+
->getTaxPrice($product, $selectionPrice, true);
206+
$selectionFinalPriceExclTax =
207+
$this->taxHelper
208+
->getTaxPrice($product, $selectionPrice, false);
209+
} else {
210+
$selectionFinalPrice = $this->taxHelper->getTaxPrice($item->getProduct(), $selectionPrice);
211+
}
212+
$option['value'][] = $qty . ' x '
213+
. $this->escaper->escapeHtml($bundleSelection->getName())
214+
. ' '
215+
. $this->pricingHelper->currency(
216+
$selectionFinalPrice
217+
)
218+
. ($displayCartPricesBoth ? ' ' . __('Excl. tax:') . ' '
219+
. $this->pricingHelper->currency(
220+
$selectionFinalPriceExclTax
221+
) : '');
222+
$option['has_html'] = true;
223+
}
224+
return $option;
225+
}
226+
176227
/**
177228
* Retrieves product options list
178229
*

0 commit comments

Comments
 (0)