Skip to content

Commit 5d71a16

Browse files
committed
ACP2E-1456: display bundle options taking into account cart tax configurations
1 parent 7fdb0e0 commit 5d71a16

File tree

3 files changed

+322
-51
lines changed

3 files changed

+322
-51
lines changed

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

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,20 @@
55
*/
66
namespace Magento\Bundle\Helper\Catalog\Product;
77

8+
use Magento\Bundle\Model\Product\Price;
9+
use Magento\Bundle\Model\Product\Type;
810
use Magento\Catalog\Api\Data\ProductInterface;
911
use Magento\Catalog\Helper\Product\Configuration\ConfigurationInterface;
12+
use Magento\Catalog\Helper\Product\Configuration as ProductConfiguration;
13+
use Magento\Catalog\Model\Product;
1014
use Magento\Catalog\Model\Product\Configuration\Item\ItemInterface;
1115
use Magento\Framework\App\Helper\AbstractHelper;
16+
use Magento\Framework\App\Helper\Context;
1217
use Magento\Framework\App\ObjectManager;
18+
use Magento\Framework\Escaper;
19+
use Magento\Framework\Exception\LocalizedException;
20+
use Magento\Framework\Pricing\Helper\Data;
21+
use Magento\Framework\Serialize\Serializer\Json;
1322

1423
/**
1524
* Helper for fetching properties by product configuration item
@@ -21,75 +30,67 @@ class Configuration extends AbstractHelper implements ConfigurationInterface
2130
/**
2231
* Core data
2332
*
24-
* @var \Magento\Framework\Pricing\Helper\Data
33+
* @var Data
2534
*/
2635
protected $pricingHelper;
2736

2837
/**
2938
* Catalog product configuration
3039
*
31-
* @var \Magento\Catalog\Helper\Product\Configuration
40+
* @var ProductConfiguration
3241
*/
3342
protected $productConfiguration;
3443

3544
/**
36-
* @var \Magento\Framework\Escaper
45+
* @var Escaper
3746
*/
3847
protected $escaper;
3948

4049
/**
4150
* Serializer interface instance.
4251
*
43-
* @var \Magento\Framework\Serialize\Serializer\Json
52+
* @var Json
4453
*/
4554
private $serializer;
4655

4756
/**
48-
* @var \Magento\Catalog\Helper\Data
49-
*/
50-
private $catalogHelper;
51-
52-
/**
53-
* @var \Magento\Tax\Helper\Data|mixed
57+
* @var Tax
5458
*/
5559
private $taxHelper;
5660

5761
/**
58-
* @param \Magento\Framework\App\Helper\Context $context
59-
* @param \Magento\Catalog\Helper\Product\Configuration $productConfiguration
60-
* @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
61-
* @param \Magento\Framework\Escaper $escaper
62-
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
63-
* @param \Magento\Catalog\Helper\Data|null $catalogHelper
64-
* @param \Magento\Tax\Helper\Data|null $taxHelper
62+
* @param Context $context
63+
* @param ProductConfiguration $productConfiguration
64+
* @param Data $pricingHelper
65+
* @param Escaper $escaper
66+
* @param Json|null $serializer
67+
* @param Tax|null $taxHelper
6568
*/
6669
public function __construct(
67-
\Magento\Framework\App\Helper\Context $context,
68-
\Magento\Catalog\Helper\Product\Configuration $productConfiguration,
69-
\Magento\Framework\Pricing\Helper\Data $pricingHelper,
70-
\Magento\Framework\Escaper $escaper,
71-
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
72-
\Magento\Catalog\Helper\Data $catalogHelper = null,
73-
\Magento\Tax\Helper\Data $taxHelper = null
70+
Context $context,
71+
ProductConfiguration $productConfiguration,
72+
Data $pricingHelper,
73+
Escaper $escaper,
74+
Json $serializer = null,
75+
Tax $taxHelper = null
7476
) {
7577
$this->productConfiguration = $productConfiguration;
7678
$this->pricingHelper = $pricingHelper;
7779
$this->escaper = $escaper;
78-
$this->serializer = $serializer ?: \Magento\Framework\App\ObjectManager::getInstance()
79-
->get(\Magento\Framework\Serialize\Serializer\Json::class);
80-
$this->catalogHelper = $catalogHelper ?? ObjectManager::getInstance()->get(\Magento\Catalog\Helper\Data::class);
81-
$this->taxHelper = $taxHelper ?? ObjectManager::getInstance()->get(\Magento\Tax\Helper\Data::class);
80+
$this->serializer = $serializer ?: ObjectManager::getInstance()
81+
->get(Json::class);
82+
$this->taxHelper = $taxHelper ?? ObjectManager::getInstance()->get(Tax::class);
8283
parent::__construct($context);
8384
}
8485

8586
/**
8687
* Get selection quantity
8788
*
88-
* @param \Magento\Catalog\Model\Product $product
89+
* @param Product $product
8990
* @param int $selectionId
9091
* @return float
9192
*/
92-
public function getSelectionQty(\Magento\Catalog\Model\Product $product, $selectionId)
93+
public function getSelectionQty(Product $product, $selectionId)
9394
{
9495
$selectionQty = $product->getCustomOption('selection_qty_' . $selectionId);
9596
if ($selectionQty) {
@@ -102,15 +103,15 @@ public function getSelectionQty(\Magento\Catalog\Model\Product $product, $select
102103
* Obtain final price of selection in a bundle product
103104
*
104105
* @param ItemInterface $item
105-
* @param \Magento\Catalog\Model\Product $selectionProduct
106+
* @param Product $selectionProduct
106107
* @return float
107108
*/
108-
public function getSelectionFinalPrice(ItemInterface $item, \Magento\Catalog\Model\Product $selectionProduct)
109+
public function getSelectionFinalPrice(ItemInterface $item, Product $selectionProduct)
109110
{
110111
$selectionProduct->unsetData('final_price');
111112

112113
$product = $item->getProduct();
113-
/** @var \Magento\Bundle\Model\Product\Price $price */
114+
/** @var Price $price */
114115
$price = $product->getPriceModel();
115116

116117
return $price->getSelectionFinalTotalPrice(
@@ -137,7 +138,7 @@ public function getBundleOptions(ItemInterface $item)
137138
$options = [];
138139
$product = $item->getProduct();
139140

140-
/** @var \Magento\Bundle\Model\Product\Type $typeInstance */
141+
/** @var Type $typeInstance */
141142
$typeInstance = $product->getTypeInstance();
142143

143144
// get bundle options
@@ -187,22 +188,23 @@ public function getBundleOptions(ItemInterface $item)
187188
* @param ProductInterface $bundleSelection
188189
* @param array $option
189190
* @return array
191+
* @throws LocalizedException
190192
*/
191193
private function getOptionPriceHtml(ItemInterface $item, ProductInterface $bundleSelection, array $option): array
192194
{
193195
$product = $item->getProduct();
194196
$qty = $this->getSelectionQty($item->getProduct(), $bundleSelection->getSelectionId()) * 1;
195197
if ($qty) {
196198
$selectionPrice = $this->getSelectionFinalPrice($item, $bundleSelection);
197-
$selectionFinalPrice = $this->catalogHelper->getTaxPrice($item->getProduct(), $selectionPrice);
199+
$selectionFinalPrice = $this->taxHelper->getTaxPrice($item->getProduct(), $selectionPrice);
198200

199-
$displayBothPrices = $this->taxHelper->displayBothPrices();
200-
if ($displayBothPrices) {
201+
$displayCartPricesBoth = $this->taxHelper->displayCartPricesBoth();
202+
if ($displayCartPricesBoth) {
201203
$selectionFinalPrice =
202-
$this->catalogHelper
204+
$this->taxHelper
203205
->getTaxPrice($product, $selectionPrice, true);
204206
$selectionFinalPriceExclTax =
205-
$this->catalogHelper
207+
$this->taxHelper
206208
->getTaxPrice($product, $selectionPrice, false);
207209
}
208210
$option['value'][] = $qty . ' x '
@@ -212,7 +214,7 @@ private function getOptionPriceHtml(ItemInterface $item, ProductInterface $bundl
212214
$selectionFinalPrice
213215
)
214216
. ' '
215-
. ($displayBothPrices ? __('Excl. tax:') . ' '
217+
. ($displayCartPricesBoth ? __('Excl. tax:') . ' '
216218
. $this->pricingHelper->currency(
217219
$selectionFinalPriceExclTax
218220
) : '');

0 commit comments

Comments
 (0)