5
5
*/
6
6
namespace Magento \Tax \Observer ;
7
7
8
- use Magento \Framework \Event \ObserverInterface ;
9
8
use Magento \Catalog \Pricing \Price \BasePrice ;
10
9
use Magento \Catalog \Pricing \Price \RegularPrice ;
10
+ use Magento \Framework \Event \ObserverInterface ;
11
11
12
+ /**
13
+ * Modifies the bundle config for the front end to resemble the tax included price when tax included prices.
14
+ */
12
15
class GetPriceConfigurationObserver implements ObserverInterface
13
16
{
14
17
/**
@@ -84,12 +87,11 @@ private function recurConfigAndUpdatePrice($input, $searchKey)
84
87
if (is_array ($ el )) {
85
88
$ holder [$ key ] =
86
89
$ this ->recurConfigAndUpdatePrice ($ el , $ searchKey );
87
- if ($ key === $ searchKey ) {
88
- if ((array_key_exists ('basePrice ' , $ holder [$ key ]))) {
89
- if (array_key_exists ('optionId ' , $ input )) {
90
- $ holder = $ this ->updatePriceForBundle ($ holder , $ key );
91
- }
92
- }
90
+ if ($ key === $ searchKey
91
+ && array_key_exists ('optionId ' , $ input )
92
+ && array_key_exists ('basePrice ' , $ holder [$ key ])
93
+ ) {
94
+ $ holder = $ this ->updatePriceForBundle ($ holder , $ key );
93
95
}
94
96
} else {
95
97
$ holder [$ key ] = $ el ;
@@ -108,36 +110,35 @@ private function recurConfigAndUpdatePrice($input, $searchKey)
108
110
*/
109
111
private function updatePriceForBundle ($ holder , $ key )
110
112
{
111
- if (array_key_exists ($ key , $ holder )) {
112
- if ( array_key_exists ('basePrice ' , $ holder [$ key ])) {
113
- /** @var \Magento\Catalog\Model\Product $product */
114
- $ product = $ this ->registry ->registry ('current_product ' );
115
- if ($ product ->getTypeId () == \Magento \Catalog \Model \Product \Type::TYPE_BUNDLE ) {
116
- if (!isset ($ this ->selectionCache [$ product ->getId ()])) {
117
- $ typeInstance = $ product ->getTypeInstance ();
118
- $ typeInstance ->setStoreFilter ($ product ->getStoreId (), $ product );
113
+ if (array_key_exists ($ key , $ holder )
114
+ && array_key_exists ('basePrice ' , $ holder [$ key ])) {
115
+ /** @var \Magento\Catalog\Model\Product $product */
116
+ $ product = $ this ->registry ->registry ('current_product ' );
117
+ if ($ product ->getTypeId () == \Magento \Catalog \Model \Product \Type::TYPE_BUNDLE ) {
118
+ if (!isset ($ this ->selectionCache [$ product ->getId ()])) {
119
+ $ typeInstance = $ product ->getTypeInstance ();
120
+ $ typeInstance ->setStoreFilter ($ product ->getStoreId (), $ product );
119
121
120
- $ selectionCollection = $ typeInstance ->getSelectionsCollection (
121
- $ typeInstance ->getOptionsIds ($ product ),
122
- $ product
123
- );
124
- $ this ->selectionCache [$ product ->getId ()] = $ selectionCollection ->getItems ();
125
- }
126
- $ arrSelections = $ this ->selectionCache [$ product ->getId ()];
122
+ $ selectionCollection = $ typeInstance ->getSelectionsCollection (
123
+ $ typeInstance ->getOptionsIds ($ product ),
124
+ $ product
125
+ );
126
+ $ this ->selectionCache [$ product ->getId ()] = $ selectionCollection ->getItems ();
127
+ }
128
+ $ arrSelections = $ this ->selectionCache [$ product ->getId ()];
127
129
128
- foreach ($ arrSelections as $ selectionItem ) {
129
- if ($ holder ['optionId ' ] == $ selectionItem ->getId ()) {
130
- /** @var \Magento\Framework\Pricing\Amount\Base $baseAmount */
131
- $ baseAmount = $ selectionItem ->getPriceInfo ()->getPrice (BasePrice::PRICE_CODE )->getAmount ();
132
- /** @var \Magento\Framework\Pricing\Amount\Base $oldAmount */
133
- $ oldAmount =
130
+ foreach ($ arrSelections as $ selectionItem ) {
131
+ if ($ holder ['optionId ' ] == $ selectionItem ->getId ()) {
132
+ /** @var \Magento\Framework\Pricing\Amount\Base $baseAmount */
133
+ $ baseAmount = $ selectionItem ->getPriceInfo ()->getPrice (BasePrice::PRICE_CODE )->getAmount ();
134
+ /** @var \Magento\Framework\Pricing\Amount\Base $oldAmount */
135
+ $ oldAmount =
134
136
$ selectionItem ->getPriceInfo ()->getPrice (RegularPrice::PRICE_CODE )->getAmount ();
135
- if ($ baseAmount ->hasAdjustment ('tax ' )) {
136
- $ holder [$ key ]['basePrice ' ]['amount ' ] =
137
+ if ($ baseAmount ->hasAdjustment ('tax ' )) {
138
+ $ holder [$ key ]['basePrice ' ]['amount ' ] =
137
139
$ baseAmount ->getBaseAmount () + $ baseAmount ->getAdjustmentAmount ('tax ' );
138
- $ holder [$ key ]['oldPrice ' ]['amount ' ] =
140
+ $ holder [$ key ]['oldPrice ' ]['amount ' ] =
139
141
$ oldAmount ->getBaseAmount () + $ oldAmount ->getAdjustmentAmount ('tax ' );
140
- }
141
142
}
142
143
}
143
144
}
0 commit comments