6
6
namespace Magento \Bundle \Block \Catalog \Product \View \Type ;
7
7
8
8
use Magento \Bundle \Model \Option ;
9
+ use Magento \Bundle \Model \Product \Price ;
10
+ use Magento \Bundle \Model \Product \PriceFactory ;
11
+ use Magento \Bundle \Model \Product \Type ;
12
+ use Magento \Catalog \Block \Product \Context ;
13
+ use Magento \Catalog \Block \Product \View \AbstractView ;
9
14
use Magento \Catalog \Model \Product ;
15
+ use Magento \Catalog \Pricing \Price \FinalPrice ;
16
+ use Magento \Catalog \Pricing \Price \RegularPrice ;
17
+ use Magento \CatalogRule \Model \ResourceModel \Product \CollectionProcessor ;
18
+ use Magento \Framework \App \ObjectManager ;
10
19
use Magento \Framework \DataObject ;
20
+ use Magento \Framework \Json \EncoderInterface ;
21
+ use Magento \Framework \Locale \FormatInterface ;
22
+ use Magento \Framework \Stdlib \ArrayUtils ;
11
23
12
24
/**
13
25
* Catalog bundle product info block
14
26
*
15
27
* @api
16
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17
- * @api
18
28
* @since 100.0.2
29
+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
19
30
*/
20
- class Bundle extends \ Magento \ Catalog \ Block \ Product \ View \ AbstractView
31
+ class Bundle extends AbstractView
21
32
{
22
-
23
33
/**
24
34
* @var array
25
35
*/
@@ -33,17 +43,17 @@ class Bundle extends \Magento\Catalog\Block\Product\View\AbstractView
33
43
protected $ catalogProduct ;
34
44
35
45
/**
36
- * @var \Magento\Bundle\Model\Product\ PriceFactory
46
+ * @var PriceFactory
37
47
*/
38
48
protected $ productPriceFactory ;
39
49
40
50
/**
41
- * @var \Magento\Framework\Json\ EncoderInterface
51
+ * @var EncoderInterface
42
52
*/
43
53
protected $ jsonEncoder ;
44
54
45
55
/**
46
- * @var \Magento\Framework\Locale\ FormatInterface
56
+ * @var FormatInterface
47
57
*/
48
58
protected $ localeFormat ;
49
59
@@ -63,22 +73,24 @@ class Bundle extends \Magento\Catalog\Block\Product\View\AbstractView
63
73
private $ optionsPosition = [];
64
74
65
75
/**
66
- * @param \Magento\Catalog\Block\Product\ Context $context
67
- * @param \Magento\Framework\Stdlib\ ArrayUtils $arrayUtils
76
+ * @param Context $context
77
+ * @param ArrayUtils $arrayUtils
68
78
* @param \Magento\Catalog\Helper\Product $catalogProduct
69
- * @param \Magento\Bundle\Model\Product\ PriceFactory $productPrice
70
- * @param \Magento\Framework\Json\ EncoderInterface $jsonEncoder
71
- * @param \Magento\Framework\Locale\ FormatInterface $localeFormat
79
+ * @param PriceFactory $productPrice
80
+ * @param EncoderInterface $jsonEncoder
81
+ * @param FormatInterface $localeFormat
72
82
* @param array $data
83
+ * @param CollectionProcessor|null $catalogRuleProcessor
73
84
*/
74
85
public function __construct (
75
- \ Magento \ Catalog \ Block \ Product \ Context $ context ,
76
- \ Magento \ Framework \ Stdlib \ ArrayUtils $ arrayUtils ,
86
+ Context $ context ,
87
+ ArrayUtils $ arrayUtils ,
77
88
\Magento \Catalog \Helper \Product $ catalogProduct ,
78
- \Magento \Bundle \Model \Product \PriceFactory $ productPrice ,
79
- \Magento \Framework \Json \EncoderInterface $ jsonEncoder ,
80
- \Magento \Framework \Locale \FormatInterface $ localeFormat ,
81
- array $ data = []
89
+ PriceFactory $ productPrice ,
90
+ EncoderInterface $ jsonEncoder ,
91
+ FormatInterface $ localeFormat ,
92
+ array $ data = [],
93
+ ?CollectionProcessor $ catalogRuleProcessor = null
82
94
) {
83
95
$ this ->catalogProduct = $ catalogProduct ;
84
96
$ this ->productPriceFactory = $ productPrice ;
@@ -89,22 +101,8 @@ public function __construct(
89
101
$ arrayUtils ,
90
102
$ data
91
103
);
92
- }
93
-
94
- /**
95
- * Return catalog rule processor or creates processor if it does not exist
96
- *
97
- * @deprecated 100.2.0
98
- * @return \Magento\CatalogRule\Model\ResourceModel\Product\CollectionProcessor
99
- */
100
- private function getCatalogRuleProcessor ()
101
- {
102
- if ($ this ->catalogRuleProcessor === null ) {
103
- $ this ->catalogRuleProcessor = \Magento \Framework \App \ObjectManager::getInstance ()
104
- ->get (\Magento \CatalogRule \Model \ResourceModel \Product \CollectionProcessor::class);
105
- }
106
-
107
- return $ this ->catalogRuleProcessor ;
104
+ $ this ->catalogRuleProcessor = $ catalogRuleProcessor ?? ObjectManager::getInstance ()
105
+ ->get (CollectionProcessor::class);
108
106
}
109
107
110
108
/**
@@ -120,7 +118,7 @@ public function getOptions($stripSelection = false)
120
118
{
121
119
if (!$ this ->options ) {
122
120
$ product = $ this ->getProduct ();
123
- /** @var \Magento\Bundle\Model\Product\ Type $typeInstance */
121
+ /** @var Type $typeInstance */
124
122
$ typeInstance = $ product ->getTypeInstance ();
125
123
$ typeInstance ->setStoreFilter ($ product ->getStoreId (), $ product );
126
124
@@ -130,7 +128,7 @@ public function getOptions($stripSelection = false)
130
128
$ typeInstance ->getOptionsIds ($ product ),
131
129
$ product
132
130
);
133
- $ this ->getCatalogRuleProcessor () ->addPriceData ($ selectionCollection );
131
+ $ this ->catalogRuleProcessor ->addPriceData ($ selectionCollection );
134
132
$ selectionCollection ->addTierPriceData ();
135
133
136
134
$ this ->options = $ optionCollection ->appendSelections (
@@ -151,10 +149,7 @@ public function getOptions($stripSelection = false)
151
149
public function hasOptions ()
152
150
{
153
151
$ this ->getOptions ();
154
- if (empty ($ this ->options ) || !$ this ->getProduct ()->isSalable ()) {
155
- return false ;
156
- }
157
- return true ;
152
+ return !(empty ($ this ->options ) || !$ this ->getProduct ()->isSalable ());
158
153
}
159
154
160
155
/**
@@ -255,7 +250,7 @@ private function getSelectionItemData(Product $product, Product $selection)
255
250
->getOptionSelectionAmount ($ selection )
256
251
->getValue ();
257
252
258
- $ selection = [
253
+ return [
259
254
'qty ' => $ qty ,
260
255
'customQty ' => $ selection ->getSelectionCanChangeQty (),
261
256
'optionId ' => $ selection ->getId (),
@@ -275,8 +270,6 @@ private function getSelectionItemData(Product $product, Product $selection)
275
270
'name ' => $ selection ->getName (),
276
271
'canApplyMsrp ' => false ,
277
272
];
278
-
279
- return $ selection ;
280
273
}
281
274
282
275
/**
@@ -371,16 +364,16 @@ private function getOptionItemData(Option $option, Product $product, $position)
371
364
*/
372
365
private function getConfigData (Product $ product , array $ options )
373
366
{
374
- $ isFixedPrice = $ this ->getProduct ()->getPriceType () == \ Magento \ Bundle \ Model \ Product \ Price::PRICE_TYPE_FIXED ;
367
+ $ isFixedPrice = $ this ->getProduct ()->getPriceType () == Price::PRICE_TYPE_FIXED ;
375
368
376
369
$ productAmount = $ product
377
370
->getPriceInfo ()
378
- ->getPrice (\ Magento \ Catalog \ Pricing \ Price \ FinalPrice::PRICE_CODE )
371
+ ->getPrice (FinalPrice::PRICE_CODE )
379
372
->getPriceWithoutOption ();
380
373
381
374
$ baseProductAmount = $ product
382
375
->getPriceInfo ()
383
- ->getPrice (\ Magento \ Catalog \ Pricing \ Price \ RegularPrice::PRICE_CODE )
376
+ ->getPrice (RegularPrice::PRICE_CODE )
384
377
->getAmount ();
385
378
386
379
$ config = [
0 commit comments